public void AddExistingPhonebookEntryShouldReturnFalse() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var isEntryAdded = phonebookRepository.AddPhone("John", new List<string>() { "333" }); Assert.AreEqual(false, isEntryAdded); }
public void AddExistingPhonebookEntryWithDifferentNameCasesShouldReturnFalse() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var isEntryAdded = phonebookRepository.AddPhone("joHN", new List<string>() { "333" }); var mergedEntry = phonebookRepository.ListEntries(0, 1).First(); Assert.AreEqual(false, isEntryAdded); Assert.AreEqual(3, mergedEntry.PhoneNumbers.Count); }
public void AddPhonesShouldMergeAndKeepOnlyUniquePhoneNumbers() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var isEntryAdded = phonebookRepository.AddPhone("John", new List<string>() { "111", "222", "333" }); var mergedEntry = phonebookRepository.ListEntries(0, 1).First(); Assert.AreEqual(false, isEntryAdded); Assert.AreEqual(3, mergedEntry.PhoneNumbers.Count); Assert.AreEqual("333", mergedEntry.PhoneNumbers.Skip(2).First()); }
public void ListMultipleEntry() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.AddPhone("John1", new List<string>() { "333", "444", "4444" }); phonebookRepository.AddPhone("John2", new List<string>() { "555", "666" }); var result = phonebookRepository.ListEntries(0, 3); Assert.AreEqual(3, result.Count()); Assert.AreEqual("John", result.First().Name); Assert.AreEqual(2, result.First().PhoneNumbers.Count); CollectionAssert.AreEqual(new List<string>() { "333", "444", "4444" }, result.Skip(1).First().PhoneNumbers.ToList()); }
public void ChangePhoneWithMergeAndDuplicates() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.AddPhone("John1", new List<string>() { "333", "444" }); phonebookRepository.AddPhone("John2", new List<string>() { "555", "666" }); phonebookRepository.ChangePhone("111", "333"); Assert.AreEqual(2, phonebookRepository.ListEntries(0, 3).Where(a => a.PhoneNumbers.Contains("333")).Count()); Assert.AreEqual(0, phonebookRepository.ListEntries(0, 3).Where(a => a.PhoneNumbers.Contains("111")).Count()); Assert.AreEqual(1, phonebookRepository.ListEntries(0, 3).Where(a => a.Name == "John").Count()); Assert.AreEqual(1, phonebookRepository.ListEntries(0, 3).Where(a => a.Name == "John1").Count()); }
public void ChangedSharedPhoneNumber() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.AddPhone("Smith", new List<string>() { "222", "333" }); var matchedPhoneEntries = phonebookRepository.ChangePhone("222", "444"); Assert.AreEqual(2, matchedPhoneEntries); Assert.AreEqual(2, phonebookRepository.ListEntries(0, 2).First().PhoneNumbers.Count); Assert.AreEqual(2, phonebookRepository.ListEntries(0, 2).Skip(1).First().PhoneNumbers.Count); Assert.IsTrue(phonebookRepository.ListEntries(0, 2).First().PhoneNumbers.Contains("444")); Assert.IsFalse(phonebookRepository.ListEntries(0, 2).First().PhoneNumbers.Contains("222")); Assert.IsTrue(phonebookRepository.ListEntries(0, 2).Skip(1).First().PhoneNumbers.Contains("444")); Assert.IsFalse(phonebookRepository.ListEntries(0, 2).Skip(1).First().PhoneNumbers.Contains("222")); }
public void ListSingleEntry() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var result = phonebookRepository.ListEntries(0, 1); Assert.AreEqual(1, result.Count()); Assert.AreEqual("John", result.First().Name); Assert.AreEqual(2, result.First().PhoneNumbers.Count); CollectionAssert.AreEqual(new List<string>() { "111", "222" }, result.First().PhoneNumbers.ToList()); }
public void ChangeNonExistingPhoneNumberShouldNotAffectToTheRepository() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var matchedPhoneEntries = phonebookRepository.ChangePhone("333", "444"); Assert.AreEqual(0, matchedPhoneEntries); Assert.AreEqual(2, phonebookRepository.ListEntries(0, 1).First().PhoneNumbers.Count); CollectionAssert.AreEqual(new List<string>() { "111", "222" }, phonebookRepository.ListEntries(0, 1).First().PhoneNumbers.ToList()); }
public void ChangeExistingPhoneNumberShouldRemoveOldAndAddNewPhoneNumber() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); var matchedPhoneEntries = phonebookRepository.ChangePhone("111", "333"); Assert.AreEqual(1, matchedPhoneEntries); Assert.AreEqual(2, phonebookRepository.ListEntries(0, 1).First().PhoneNumbers.Count); Assert.IsTrue(phonebookRepository.ListEntries(0, 1).First().PhoneNumbers.Contains("333")); Assert.IsFalse(phonebookRepository.ListEntries(0, 1).First().PhoneNumbers.Contains("111")); }
public void ListEntriesWithCountBiggetThanMaxCountShouldThrowException() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.ListEntries(0, int.MaxValue); }
public void ListEntriesWithNegativeCountShouldThrowException() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.ListEntries(0, -1); }
public void ListEntriesWithInvalidIndexShouldThrowException() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); phonebookRepository.ListEntries(-1, 1); }
public void AddPhoneToValidEntryNameButNullPhoneNumbersCollectionShouldThrowException() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone("John", null); }
public void AddPhoneToNullNameShouldThrowException() { var phonebookRepository = new PhonebookRepositoryFast(); phonebookRepository.AddPhone(null, new List<string>() { "111", "222" }); }
public void AddNonExistingPhoneEntryShouldReturnTrue() { var phonebookRepository = new PhonebookRepositoryFast(); var isEntryAdded = phonebookRepository.AddPhone("John", new List<string>() { "111", "222" }); Assert.AreEqual(true, isEntryAdded); }