本文整理汇总了C#中Contact.AddPerson方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.AddPerson方法的具体用法?C# Contact.AddPerson怎么用?C# Contact.AddPerson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contact
的用法示例。
在下文中一共展示了Contact.AddPerson方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateFirstNameTest
public void GenerateFirstNameTest()
{
Contact contact = new Contact { Name = "Todd", FirstNames = "Test business", };
contact.AddPerson(new Person { FirstName="John", IncludeInDisplayName=true});
contact.AddPerson(new Person { FirstName="Anne", IncludeInDisplayName=true});
contact.AddPerson(new Person { FirstName="David", IncludeInDisplayName=true});
//Test - 3 people included
string expected = "John, Anne & David";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.FirstNames);
//Test - 2 people included
contact.People[2].IncludeInDisplayName = false;
expected = "John & Anne";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.FirstNames);
//Test - just one person included
contact.People[1].IncludeInDisplayName = false;
expected = "John";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.FirstNames);
//Test - error if no people included
contact.People[0].IncludeInDisplayName = false;
//ExceptionAssert.Throws<ArgumentException>(() => contact.UpdateFirstNames());
//Test - if business, return Display name directly
contact.IsBusiness = true;
expected = "";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.FirstNames);
}
示例2: ContactMainTest
public void ContactMainTest()
{
string address = "1 road name\npostcode\ntown";
string email = "[email protected]";
bool isbusiness = false;
string lastname = "Lastname";
string notes = "some notes here";
string phonenumber = "021 9551 684 6";
string contact1firstname = "Horrace";
string worknumber = "032 568 79 85";
string contact2email = "[email protected]";
Contact target = new Contact()
{
Address = address,
Email = email,
IsBusiness = isbusiness,
Name = lastname,
Notes = notes,
PhoneNumber = phonenumber,
};
target.AddPerson(new Person { DateOfBirth = new DateTime(1968, 5, 3), FirstName = contact1firstname, LastName = "Lastname", MobileNumber= "079 813 83 53", WorkNumber = worknumber, Email = "[email protected]", IncludeInDisplayName = true });
target.AddPerson(new Person { DateOfBirth = new DateTime(1984, 7, 13), FirstName = "Contact1", LastName = "Lastname", MobileNumber = "079 887 35 00", Email = contact2email, IncludeInDisplayName = false });
Assert.Equal(target.Address, address);
Assert.Equal(target.Email, email);
Assert.Equal(target.IsBusiness, isbusiness);
Assert.Equal(target.Name, lastname);
Assert.Equal(target.Notes, notes);
Assert.Equal(target.PhoneNumber, phonenumber);
Assert.Equal(target.People[0].WorkNumber, worknumber);
Assert.Equal(target.People.Count, 2);
Assert.Equal(target.People[0].FirstName, contact1firstname);
Assert.Equal(target.People[1].Email, contact2email);
}
示例3: GetAddressBookFromLookup
/// <summary>
/// Gets the address book from CSV dictionary.
/// </summary>
//(This would be private, but test generation wouldn't work...)
internal static AddressBook GetAddressBookFromLookup(IEnumerable<Dictionary<string, string>> csv)
{
AddressBook book = new AddressBook();
foreach(var row in csv)
{
bool isbusiness = (row[Keys.HomePhone] == "" && row[Keys.WorkPhone] != ""); //is business if no home phone AND has business phone
bool multiperson = row[Keys.FirstName].Contains('&');
var contact = new Contact
{
Name = row[Keys.LastName],
Email = ContactMailLogic(row, multiperson),
IsBusiness = isbusiness,
PhoneNumber = isbusiness ? row[Keys.WorkPhone] : row[Keys.HomePhone],
Address = GetAddress(row),
Notes = row[Keys.Notes]
};
//Add one or two people, based on first name containing &
if(multiperson)
{
contact.AddPerson(FirstPerson(row, false));
contact.AddPerson(SecondPerson(row));
}
else
{
contact.AddPerson(FirstPerson(row, true));
}
//Update first names with new people
contact.UpdateFirstNames();
book.AddContact(contact);
}
return book;
}
示例4: MergeContactsTest
public void MergeContactsTest()
{
var contact1 = new Contact
{
Address = "Address",
Email = "[email protected]",
IsBusiness = false,
Name = "Name",
PhoneNumber = "012 3209 2 93",
Notes = "Notes 1"
};
contact1.AddPerson(new Person { FirstName = "Duplicate", Email="", LastName="person1name", MobileNumber = "mobile1a", WorkNumber="work1a", DateOfBirth=new DateTime(1964, 12, 1) });
contact1.AddPerson(new Person { FirstName = "Marjory", Email="person2mail", LastName="person2name", MobileNumber = "mobile2", WorkNumber="work2", DateOfBirth=new DateTime(1968, 12, 1) });
var contact2 = new Contact
{
Address = "Address2",
Email = "[email protected]",
IsBusiness = false,
Name = "Name",
PhoneNumber = "012 3209 2 93",
Notes = "Notes 2"
};
contact2.AddPerson(new Person { FirstName = "Duplicate", Email = "person1email", LastName = "", MobileNumber = "mobile1b", WorkNumber = "work1b" });
var contact3 = new Contact
{
Address = "Address3",
Email = "[email protected]",
IsBusiness = false,
Name = "Name",
PhoneNumber = "012 3209 2 93",
Notes = "Notes 3"
};
contact3.AddPerson(new Person { FirstName = "Herny", Email = "person3mail", LastName = "person3name", MobileNumber = "mobile3", WorkNumber = "work3", DateOfBirth = new DateTime(1966, 12, 1) });
var contacts = new List<Contact> { contact1, contact2, contact3 };
var actual = Contact.MergeContacts(contacts);
Assert.Equal(contact1.Address, actual.Address);
Assert.Equal(contact1.Name, actual.Name);
Assert.Equal("Notes 1\r\nNotes 2\r\nNotes 3", actual.Notes);
Assert.Equal(3, actual.People.Count);
Assert.Equal(contact1.People[1].FirstName, actual.People[1].FirstName);
Assert.Equal(contact3.People[0].FirstName, actual.People[2].FirstName);
Assert.Equal(contact2.People[0].Email, actual.People[0].Email);
Assert.Equal(contact1.People[0].LastName, actual.People[0].LastName);
Assert.Equal("mobile1a/mobile1b", actual.People[0].MobileNumber);
Assert.Equal(new DateTime(1964, 12, 1), actual.People[0].DateOfBirth);
}
示例5: OrderByNameDisplayNameTest
public void OrderByNameDisplayNameTest()
{
Contact contact = new Contact { Name = "Todd", FirstNames = "Test business", };
contact.AddPerson(new Person { FirstName = "John", IncludeInDisplayName = true });
contact.AddPerson(new Person { FirstName = "Anne", IncludeInDisplayName = true });
contact.AddPerson(new Person { FirstName = "David", IncludeInDisplayName = true });
//Test - 3 people included
string expected = "John, Anne & David Todd";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.DisplayName);
expected = "Todd, John, Anne & David";
Assert.Equal(expected, contact.OrderByName);
//Test - 2 people included
contact.People[2].IncludeInDisplayName = false;
expected = "John & Anne Todd";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.DisplayName);
expected = "Todd, John & Anne";
Assert.Equal(expected, contact.OrderByName);
//Test - just one person included
contact.People[1].IncludeInDisplayName = false;
expected = "John Todd";
contact.UpdateFirstNames();
Assert.Equal(expected, contact.DisplayName);
expected = "Todd, John";
Assert.Equal(expected, contact.OrderByName);
//Test - if business, return Display name directly
contact.IsBusiness = true;
expected = contact.Name;
contact.UpdateFirstNames();
Assert.Equal(expected, contact.DisplayName);
Assert.Equal(expected, contact.OrderByName);
}