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); }
/// <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; }
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); }