Пример #1
0
 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);
 }
Пример #2
0
 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);
 }
Пример #3
0
 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());
 }
Пример #4
0
        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());
        }
Пример #5
0
 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());
 }
Пример #6
0
        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"));
        }
Пример #7
0
 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());
 }
Пример #8
0
        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());
        }
Пример #9
0
        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"));
        }
Пример #10
0
 public void ListEntriesWithNegativeCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(0, -1);
 }
Пример #11
0
 public void ListEntriesWithInvalidIndexShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(-1, 1);
 }
Пример #12
0
 public void ChangePhoneOnEmptyNewPhoneNumberShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ChangePhone("", null);
 }
Пример #13
0
 public void ChangePhoneOnEmptyOldPhoneNumberShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ChangePhone(null, "111");
 }
Пример #14
0
 public void AddPhoneToValidEntryNameButNullPhoneNumbersCollectionShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", null);
 }
Пример #15
0
 public void AddPhoneToNullNameShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone(null, new List<string>() { "111", "222" });
 }
Пример #16
0
 public void ListEntriesWithCountBiggetThanMaxCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(0, int.MaxValue);
 }
Пример #17
0
 public void ListEntriesWithInvalidIndexAndCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ListEntries(1, 1);
 }
Пример #18
0
 public void AddNonExistingPhoneEntryShouldReturnTrue()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     var isEntryAdded = phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     Assert.AreEqual(true, isEntryAdded);
 }