Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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());
 }
Exemplo n.º 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());
        }
Exemplo n.º 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());
 }
Exemplo n.º 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"));
        }
Exemplo n.º 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());
 }
Exemplo n.º 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());
        }
Exemplo n.º 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"));
        }
Exemplo n.º 10
0
 public void ListEntriesWithNegativeCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(0, -1);
 }
Exemplo n.º 11
0
 public void ListEntriesWithInvalidIndexShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(-1, 1);
 }
Exemplo n.º 12
0
 public void ChangePhoneOnEmptyNewPhoneNumberShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ChangePhone("", null);
 }
Exemplo n.º 13
0
 public void ChangePhoneOnEmptyOldPhoneNumberShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ChangePhone(null, "111");
 }
Exemplo n.º 14
0
 public void AddPhoneToValidEntryNameButNullPhoneNumbersCollectionShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", null);
 }
Exemplo n.º 15
0
 public void AddPhoneToNullNameShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone(null, new List<string>() { "111", "222" });
 }
Exemplo n.º 16
0
 public void ListEntriesWithCountBiggetThanMaxCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     phonebookRepository.ListEntries(0, int.MaxValue);
 }
Exemplo n.º 17
0
 public void ListEntriesWithInvalidIndexAndCountShouldThrowException()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     phonebookRepository.ListEntries(1, 1);
 }
Exemplo n.º 18
0
 public void AddNonExistingPhoneEntryShouldReturnTrue()
 {
     var phonebookRepository = new PhonebookRepositoryFast();
     var isEntryAdded = phonebookRepository.AddPhone("John", new List<string>() { "111", "222" });
     Assert.AreEqual(true, isEntryAdded);
 }