public void TestAddSinglePhonebookEntry() { PhonebookRepository phonebook = new PhonebookRepository(); bool isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444" }); Assert.AreEqual(true, isNew); Assert.AreEqual(1, phonebook.EntriesCount); Assert.AreEqual(1, phonebook.PhonesCount); // Notes: we have intentionally added the properties EntriesCount // and PhonesCount in the PhonebookRepository class to simplify testing }
public void TestAddWithMerge() { PhonebookRepository phonebook = new PhonebookRepository(); bool isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444", "+359887333555" }); Assert.AreEqual(true, isNew); isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333555", "+359887333777" }); Assert.AreEqual(false, isNew); isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); Assert.AreEqual(false, isNew); Assert.AreEqual(1, phonebook.EntriesCount); Assert.AreEqual(3, phonebook.PhonesCount); }
public void TestAddEntryDifferentCasing() { PhonebookRepository phonebook = new PhonebookRepository(); bool isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444" }); Assert.AreEqual(true, isNew); isNew = phonebook.AddPhone("NAKOV", new string[] { "+359887333555" }); Assert.AreEqual(false, isNew); isNew = phonebook.AddPhone("nakov", new string[] { "+359887333777" }); Assert.AreEqual(false, isNew); Assert.AreEqual(1, phonebook.EntriesCount); Assert.AreEqual(3, phonebook.PhonesCount); }
public void TestAddDuplicatedEntry() { PhonebookRepository phonebook = new PhonebookRepository(); bool isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444" }); Assert.AreEqual(true, isNew); isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444" }); Assert.AreEqual(false, isNew); isNew = phonebook.AddPhone("Nakov", new string[] { "+359887333444" }); Assert.AreEqual(false, isNew); Assert.AreEqual(1, phonebook.EntriesCount); Assert.AreEqual(1, phonebook.PhonesCount); }
public void TestChangePhoneWithMerge() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555", "+359887333999" }); phonebook.AddPhone("Ina", new string[] { "+359887333999" }); phonebook.AddPhone("Ani", new string[] { "+359887333555", "359887333444" }); int changedPhonesCount = phonebook.ChangePhone("+359887333999", "+359887333555"); Assert.AreEqual(2, changedPhonesCount); string expectedResult = "[Ani: +359887333555, 359887333444]; [Ina: +359887333555]; [Nakov: +359887333555]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 3); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }
public void TestMethodAddPhoneManyForms() { // Conversion to cannonical form is not responsibility of the PhonebookRepository // class and thus the below phones are considered different PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.AddPhone("Nakov", new string[] { "0887 333 555" }); phonebook.AddPhone("Nakov", new string[] { "0887 33 35 55" }); phonebook.AddPhone("Nakov", new string[] { "+359 887 33 35 55" }); phonebook.AddPhone("Nakov", new string[] { "(+359) 887 33 35 55" }); phonebook.AddPhone("Nakov", new string[] { "(+359) 887 333-555" }); phonebook.AddPhone("Nakov", new string[] { "0887 / 33 35 55" }); Assert.AreEqual(1, phonebook.EntriesCount); Assert.AreEqual(7, phonebook.PhonesCount); }
public void TestListSingleEntryMultiplePhones() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.AddPhone("Nakov", new string[] { "+3592555444" }); string expectedResult = "[Nakov: +3592555444, +359887333555]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 1); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }
public void TestChangeSharedPhone() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555", "+3592981981" }); phonebook.AddPhone("Ina", new string[] { "+3592981981" }); phonebook.AddPhone("Aneliya", new string[] { "+3592981981" }); phonebook.AddPhone("Niki", new string[] { "+3592981981", "+359999888777" }); int changedPhonesCount = phonebook.ChangePhone("+3592981981", "+3592982982"); Assert.AreEqual(4, changedPhonesCount); string expectedResult = "[Aneliya: +3592982982]; [Ina: +3592982982]; [Nakov: +3592982982, +359887333555]; " + "[Niki: +3592982982, +359999888777]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 4); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }
public void TestChangeSingleNonExistingPhone() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.AddPhone("Niki", new string[] { "+359887333666" }); int changedPhonesCount = phonebook.ChangePhone("+359887333777", "+359888888888"); Assert.AreEqual(0, changedPhonesCount); string expectedResult = "[Nakov: +359887333555]; [Niki: +359887333666]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 2); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }
public void TestListMultipleEntriesInvalidCount() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.AddPhone("Jorro", new string[] { "+359888444777" }); phonebook.ListEntries(1, 2); }
public void TestListMultipleEntriesInvalidStart() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.ListEntries(1, 1); }
public void TestListMultipleEntriesSubPageWithSorting() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Nakov", new string[] { "+359887333555" }); phonebook.AddPhone("Niki", new string[] { "+35989911222" }); phonebook.AddPhone("Ani", new string[] { "+359886344544" }); phonebook.AddPhone("Yana", new string[] { "+3599874456" }); phonebook.AddPhone("Tanya", new string[] { "+359884222333" }); string expectedResult = "[Nakov: +359887333555]; [Niki: +35989911222]; [Tanya: +359884222333]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(1, 3); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }
public void TestListMultipleEntriesWithMergeAndSorting() { PhonebookRepository phonebook = new PhonebookRepository(); phonebook.AddPhone("Svetlin Nakov", new string[] { "+359887333555", "+35962445566" }); phonebook.AddPhone("SVETLIN NAKOV", new string[] { "+3592555444", "+359887333555" }); phonebook.AddPhone("Niki Kostov", new string[] { "+35989911222", "+35929887744" }); phonebook.AddPhone("niki kostov", new string[] { "+35929887744", "+35989911222" }); string expectedResult = "[Niki Kostov: +35929887744, +35989911222]; [Svetlin Nakov: +3592555444, +35962445566, +359887333555]"; PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 2); string actualResult = string.Join("; ", (object[])listedEntries); Assert.AreEqual(expectedResult, actualResult); }