public void TestAddPhoneWithSeveralEntriesAndMultiplePhoneNumbers()
        {
            var testRepository = new PhonebookRepository();
            testRepository.AddPhone("Pesho", new[] { "+359885222222" });
            testRepository.AddPhone("Gosho", new[] { "+359885652482", "0888888888", "029574457" });

            Assert.AreEqual(2, testRepository.NamesCount);
            Assert.AreEqual(4, testRepository.PhonesCount);
        }
        public void TestAddPhoneWithExistingEntryAndMultiplePhoneNumbers()
        {
            var testRepository = new PhonebookRepository();
            testRepository.AddPhone("Pesho", new[] { "+359885222222" });
            bool isNew = testRepository.AddPhone("Pesho", new[] { "+359885652482", "0888888888", "029574457" });

            Assert.IsFalse(isNew);
            Assert.AreEqual(1, testRepository.NamesCount);
            Assert.AreEqual(4, testRepository.PhonesCount);
        }
        public void AddingExistingPhoneEntryShouldReturnFalse()
        {
            var repository = new PhonebookRepository();
            var firstContactName = "Pesho";
            var secondContactName = "PeShO";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };

            repository.AddPhone(firstContactName, phoneNumbers);
            var actual = repository.AddPhone(secondContactName, phoneNumbers);

            Assert.AreEqual(false, actual);
        }
        public void AddingNewPhoneNumberShouldMergePhoneNumbers()
        {
            var repository = new PhonebookRepository();
            var firstContactName = "Pesho";
            var secondContactName = "PeShO";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11", "112" };

            repository.AddPhone(firstContactName, phoneNumbers);
            var actual = repository.AddPhone(secondContactName, new List<string> { "112", "911" });

            Assert.AreEqual(4, repository.ListEntries(0, 1).First().PhoneNumbers.Count);
        }
 public void TestNumberAdditionContainingShortCountryCodeWithPlusSymbolWhiteSpacesAndNotAllowedSymbolsAsSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "+359 (888) 41-80-12" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +359888418012]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingShortCountryCodeWithPlusSymbolAndNoSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "+359527734522" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +359527734522]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingLeadingZeroAsCityCodeInFrontWhiteSpacesAndNotAlowedSymbolsAsSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "(02) 981 22 33" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +35929812233]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingSingleZeroInFrontWhiteSpacesAndNotAllowedSymbolsAsSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "0883 / 456-789" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +359883456789]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingNoAnyPrefixesAndNoSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "123" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +359123]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingDashesAsSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "888-88-99-00" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +359888889900]", phoneEntry.ToString());
 }
        public void TestAddPhoneWithNonExistingEntry()
        {
            var testRepository = new PhonebookRepository();
            bool isNew = testRepository.AddPhone("Pesho", new[] { "+359885222222" });

            Assert.IsTrue(isNew);
            Assert.AreEqual(1, testRepository.NamesCount);
            Assert.AreEqual(1, testRepository.PhonesCount);
        }
        public void ListingWithInvalidRangeParametersShouldReturnNull()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ListEntries(10, 10);

            Assert.AreEqual(null, actual);
        }
        public void ListingWithNegativeStartingCountShouldReturnNull()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ListEntries(-1, 10);

            Assert.AreEqual(null, actual);
        }
        public void ListingWithParametersSumGreatherThanPhoneNumbersCountShouldReturnNull()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ListEntries(1, 2);

            Assert.AreEqual(null, actual);
        }
Esempio n. 15
0
        public void AddSinglePhoneTest()
        {
            PhonebookRepository target = new PhonebookRepository();

            var name    = "Kalina";
            var numbers = new List <string>();

            numbers.Add("+359899777235");

            target.AddPhone(name, numbers);
            Assert.AreEqual(1, target.Count);
        }
        public void TestListSingleEntrySinglePhone()
        {
            PhonebookRepository phonebook = new PhonebookRepository();

            phonebook.AddPhone("Nakov", new string[] { "+359887333555" });
            string expectedResult = "[Nakov: +359887333555]";

            PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 1);
            string           actualResult  = string.Join("; ", (object[])listedEntries);

            Assert.AreEqual(expectedResult, actualResult);
        }
        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 TestAddUniquePhonebookEntryWithSingleNumber()
        {
            var test = new PhonebookRepository();

            bool isNewNumber  = test.AddPhone("Pesho", new[] { "08895624" });
            int  entriesCount = test.PhoneEntrySortedCount;
            int  numbersCount = test.KeyNumberValueEntryCount;


            Assert.AreEqual(true, isNewNumber);
            Assert.AreEqual(1, entriesCount);
        }
        public void ChangingNonExistingPhoneNumberWithAnotherPhoneNumberShouldReturnZeroChanges()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };
            var numberToChange = "911";

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ChangePhone("02/1000", numberToChange);

            Assert.AreEqual(0, actual);
        }
        public void ChangingPhoneNumberWithItselfShouldReturnOneChange()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };
            var numberToChange = "0899 777 235";

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ChangePhone(numberToChange, numberToChange);

            Assert.AreEqual(1, actual);
        }
        public void ListingOneEntryShouldReturnFirstAddedContact()
        {
            var repository = new PhonebookRepository();
            var contactName = "Pesho";
            string[] phoneNumbers = { "0899 777 235", "02 / 981 11 11" };

            repository.AddPhone(contactName, phoneNumbers);
            var actual = repository.ListEntries(0, 1).First().ToString();
            var expected = "[Pesho: 02 / 981 11 11, 0899 777 235]";

            Assert.AreEqual(expected, actual);
        }
Esempio n. 22
0
        public void ShouldAddPhoneWhenCalled()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            List <String> numbers  = new List <string>();

            numbers.Add("0898 123 456");
            numbers.Add("((02) 9811111");
            repo.AddPhone(userName, numbers);
            Assert.AreNotEqual(null, repo);
        }
        public void TestChangeSinglePhoneMustReturnNumberOfChangedPhones()
        {
            var test = new PhonebookRepository();

            test.AddPhone("Pesho", new[] { "08895624", "08895625", "08895626" });

            int changedPhones = test.ChangePhone("08895624", "08895628");

            Assert.AreEqual(1, changedPhones);

            // Number of phones should stay unchanged
            Assert.AreEqual(3, test.KeyNumberValueEntryCount);
        }
Esempio n. 24
0
        public void ShouldAddEmptyUsernameWithPhonesWhenCalled()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "";
            List <String> numbers  = new List <string>();

            numbers.Add("088 322 33 44");
            numbers.Add("((+359) 899 777236");
            numbers.Add("+359899777235");
            repo.AddPhone(userName, numbers);
            Assert.AreNotEqual(null, repo);
        }
Esempio n. 25
0
        public void TestChangePhoneOnece()
        {
            string name = "Kalina";

            string[]            item = new string[] { "+359899777235", "+359899777235" };
            PhonebookRepository phoneBookRepository = new PhonebookRepository();

            phoneBookRepository.AddPhone(name, item);
            int result = phoneBookRepository.ChangePhone("+359899777235", "+359899777444");


            Assert.AreEqual(result, 1);
        }
Esempio n. 26
0
        public void ShouldMergeUserPhonesWhenCalled()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            string        phone    = "088 322 33 44";
            List <String> numbers  = new List <string>();

            numbers.Add(phone);
            repo.AddPhone(userName, numbers);
            numbers.Clear();
            string phoneNew = "((+359) 899 777236";

            numbers.Add(phoneNew);
            repo.AddPhone(userName, numbers);

            var    testObj = GetInstanceField(typeof(PhonebookRepository), repo, "_sortedEntries");
            string result  = testObj.ToString();

            Assert.IsTrue(result.Contains(phone));
            Assert.IsTrue(result.Contains(phoneNew));
        }
        public void TestChangeSingleExistingPhone()
        {
            PhonebookRepository phonebook = new PhonebookRepository();

            phonebook.AddPhone("Nakov", new string[] { "+359887333555" });
            int changedPhonesCount = phonebook.ChangePhone("+359887333555", "+359888888888");

            Assert.AreEqual(1, changedPhonesCount);
            string expectedResult = "[Nakov: +359888888888]";

            PhonebookEntry[] listedEntries = phonebook.ListEntries(0, 1);
            string           actualResult  = string.Join("; ", (object[])listedEntries);

            Assert.AreEqual(expectedResult, actualResult);
        }
Esempio n. 28
0
        public void ShouldNotChangeUserPhonesWhenDuplicate()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            string        phone    = "088 322 33 44";
            List <String> numbers  = new List <string>();

            numbers.Add(phone);
            repo.AddPhone(userName, numbers);
            repo.ChangePhone(phone, phone);
            var    testObj = GetInstanceField(typeof(PhonebookRepository), repo, "_sortedEntries");
            string result  = testObj.ToString();

            Assert.IsTrue(result.Contains(phone));
        }
Esempio n. 29
0
        public void ShouldNotListWhenBiggerCount()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            string        phone    = "088 322 33 44";
            string        phoneNew = "((+359) 899 777236";
            List <String> numbers  = new List <string>();

            numbers.Add(phone);
            numbers.Add(phoneNew);
            repo.AddPhone(userName, numbers);

            var list = repo.ListEntries(5, 10);

            Assert.AreEqual(null, list[0]);
        }
Esempio n. 30
0
        public void ShouldListUserPhonesWhenCalled()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            string        phone    = "088 322 33 44";
            string        phoneNew = "((+359) 899 777236";
            List <String> numbers  = new List <string>();

            numbers.Add(phone);
            numbers.Add(phoneNew);
            repo.AddPhone(userName, numbers);

            var list = repo.ListEntries(0, 1);

            Assert.AreEqual(userName, list[0].FirstName);
            Assert.AreEqual(2, list[0].PhoneNumbers.Count);
        }
        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);
        }
Esempio n. 32
0
        public void TestListEntries()
        {
            StringBuilder output = new StringBuilder();
            string        name   = "Kalina";

            string[]            item = new string[] { "+359899777135", "+359899777235" };
            PhonebookRepository phoneBookRepository = new PhonebookRepository();

            phoneBookRepository.AddPhone(name, item);
            IEnumerable <PhoneBookContactOutput> entries = phoneBookRepository.ListEntries(0, 1);

            foreach (var entry in entries)
            {
                output.AppendLine(entry.ToString());
            }

            string result   = output.ToString().Trim();
            string expected = "[Kalina: +359899777135, +359899777235]";

            Assert.AreEqual(result, expected);
        }
Esempio n. 33
0
        public override void Execute(string[] inputData)
        {
            string name         = inputData[0];
            var    phoneNumbers = inputData.Skip(1).ToList();

            for (int i = 0; i < phoneNumbers.Count; i++)
            {
                phoneNumbers[i] = this.Converter.ConvertPhoneNumber(phoneNumbers[i]);
            }

            bool isInPhonebook = PhonebookRepository.AddPhone(name, phoneNumbers);

            if (isInPhonebook)
            {
                Printer.Print("Phone entry merged");
            }
            else
            {
                Printer.Print("Phone entry created");
            }
        }
Esempio n. 34
0
        public void ListSingleEntriesTest()
        {
            PhonebookRepository target = new PhonebookRepository();

            var name    = "Kalina";
            var numbers = new List <string>();

            numbers.Add("+359899777235");
            target.AddPhone(name, numbers);

            Content[] expected = new Content[1];
            expected[0] = new Content()
            {
                Name    = "Kalina",
                Numbers = new SortedSet <string>()
                {
                    { "+359899777235" }
                }
            };

            Content[] actual = target.ListEntries(0, 1);

            var sbExpected = new StringBuilder();

            foreach (var content in expected)
            {
                sbExpected.AppendLine(content.ToString());
            }

            var sbActual = new StringBuilder();

            foreach (var content in actual)
            {
                sbActual.AppendLine(content.ToString());
            }

            Assert.AreEqual(sbExpected.ToString(), sbActual.ToString());
        }
Esempio n. 35
0
        public void ShouldNotListWhenNegativeCount()
        {
            PhonebookRepository repo = new PhonebookRepository();

            string        userName = "******";
            string        phone    = "088 322 33 44";
            string        phoneNew = "((+359) 899 777236";
            List <String> numbers  = new List <string>();

            numbers.Add(phone);
            numbers.Add(phoneNew);
            repo.AddPhone(userName, numbers);

            PhonebookEntry[] list = null;
            try
            {
                list = repo.ListEntries(-5, -10);
            }
            catch (OverflowException ofe)
            {
                Assert.AreEqual(null, list);
            }
        }
Esempio n. 36
0
        public void ListMultipleMiddleEntriesTest()
        {
            PhonebookRepository target = new PhonebookRepository();

            var name    = "Kalina";
            var numbers = new List <string>();

            numbers.Add("+35989943242235");
            target.AddPhone(name, numbers);

            name    = "Kalina";
            numbers = new List <string>();
            numbers.Add("+359899777235");
            target.AddPhone(name, numbers);

            name    = "Pesho";
            numbers = new List <string>();
            numbers.Add("+35945346433");
            target.AddPhone(name, numbers);

            name    = "Peshev";
            numbers = new List <string>();
            numbers.Add("+3594545454545");
            target.AddPhone(name, numbers);

            Content[] expected = new Content[2];
            expected[0] = new Content()
            {
                Name    = "Peshev",
                Numbers = new SortedSet <string>()
                {
                    { "+3594545454545" }
                }
            };
            expected[1] = new Content()
            {
                Name    = "Pesho",
                Numbers = new SortedSet <string>()
                {
                    { "+35945346433" }
                }
            };

            Content[] actual = target.ListEntries(1, 2);

            var sbExpected = new StringBuilder();

            foreach (var content in expected)
            {
                sbExpected.AppendLine(content.ToString());
            }

            var sbActual = new StringBuilder();

            foreach (var content in actual)
            {
                sbActual.AppendLine(content.ToString());
            }

            Assert.AreEqual(sbExpected.ToString(), sbActual.ToString());
        }
 public void TestNumberAdditionContainingOtherCountryShortCountryCodeNoSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "+1123456789" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +1123456789]", phoneEntry.ToString());
 }
 public void TestAddingSinglePhonebookEntryWithTwoPhoneNumbers()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "+1123456789" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +1123456789]", phoneEntry.ToString());
 }
 public void TestNumberAdditionContainingOtherCountryShortCountryCodeWithPlusSymbolWhiteSpacesAndNotAllowedSymbolsAsSeparators()
 {
     var phonebook = new PhonebookRepository();
     phonebook.AddPhone("Mike", new[] { "(+1) 123-456-789" });
     var actualPhone = phonebook.ListEntries(0, 1);
     PhonebookEntry phoneEntry = phonebook.ListEntries(0, 1).FirstOrDefault();
     Assert.AreEqual("[Mike: +1123456789]", phoneEntry.ToString());
 }