public void TestListEntries_OutOfRangeStartIndex_ShouldThrow()
        {
            int startIndex = 3;
            int endIndex = 0;
            IPhonebookRepository phonebookRepo = new PhonebookRepository();

            phonebookRepo.ListEntries(startIndex, endIndex);
        }
        public void TestListEntries_NegativeIndeces_ShouldThrow()
        {
            int startIndex = -1;
            int endIndex = -1;
            IPhonebookRepository phonebookRepo = new PhonebookRepository();

            phonebookRepo.ListEntries(startIndex, endIndex);
        }
Example #3
0
        public void AddPhone_WithValidNewInput_ShouldAddANewEntryToTheDatabase()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };

            database.AddPhone(name, phones);

            Assert.AreEqual(1, database.ListEntries(0, 1).Length);
        }
Example #4
0
        public void AddPhone_WithNewUser_ShouldReturnTrue()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };

            var isNew = database.AddPhone(name, phones);

            Assert.AreEqual(true, isNew);
        }
Example #5
0
        public void AddPhone_WithAlreadyExistingUser_ShouldReturnFalse()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };
            var phones2 = new string[] { "0111111222", "+359222333444", "0888 444 444" };

            database.AddPhone(name, phones);
            var isNew = database.AddPhone(name, phones2);

            Assert.AreEqual(false, isNew);
        }
Example #6
0
        public void AddPhone_WithValidNewInput_ShouldAddANewEntryWithValidData()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };

            database.AddPhone(name, phones);

            var expectedEntry = "[Pesho: + 333 12 24 55, 0009990 24-55-66, 0999 (222) 333]";

            Assert.AreEqual(name, database.ListEntries(0, 1)[0].Name);
            Assert.AreEqual(expectedEntry, database.ListEntries(0, 1)[0].ToString());
        }
Example #7
0
        public void AddPhone_WithRepeatingEntries_ShouldKeepOnlyUniqueEntries()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones1 = new[] { "0888 444 444" };
            var phones2 = new string[] { "0111333222", "0888 444 444" };
            var phones3 = new[] { "0111 222 333", "0444 555 666", "0888 444 444" };

            database.AddPhone(name, phones1);
            database.AddPhone(name, phones2);
            database.AddPhone(name, phones3);
            database.ChangePhone("0888 444 444", "0888 555 555");

            var expectedResult = "[Pesho: 0111 222 333, 0111333222, 0444 555 666, 0888 555 555]";

            Assert.AreEqual(expectedResult, database.ListEntries(0, 1)[0].ToString());
        }
        public void TestListEntries_RangeCoversAllEntries_CollectionsShouldMatch()
        {
            int startIndex = 0;
            int endIndex = 2;
            IPhonebookRepository phonebookRepo = new PhonebookRepository();
            Entry[] entries =
                            {
                                new Entry()
                                    {
                                        Name = "Maina",
                                        PhoneNumbers = new SortedSet<string>() { "+359123"}
                                    },
                                new Entry()
                                    {
                                        Name = "Maina2",
                                        PhoneNumbers = new SortedSet<string>() { "+359123"}
                                    },
                            };

            phonebookRepo.AddPhone(entries[0].Name, entries[0].PhoneNumbers);
            phonebookRepo.AddPhone(entries[1].Name, entries[1].PhoneNumbers);

            var returnedEntries = phonebookRepo.ListEntries(startIndex, endIndex);

            Assert.AreEqual(entries[1].Name, returnedEntries[1].Name, "Entries names should be equal.");
            Assert.AreEqual(entries[1].PhoneNumbers.ElementAt(0),
                returnedEntries[1].PhoneNumbers.ElementAt(0), "Entries numbers should be equal.");
        }
Example #9
0
        public void List_WithDatabaseData_ShouldReturnCorrectResults()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };

            database.AddPhone(name, phones);

            var expectedEntry = "[Pesho: + 333 12 24 55, 0009990 24-55-66, 0999 (222) 333]";
            var resultName = database.ListEntries(0, 1)[0].Name;
            var result = database.ListEntries(0, 1)[0].ToString();

            Assert.AreEqual(name, resultName);
            Assert.AreEqual(expectedEntry, result);
        }
Example #10
0
        public void ChangePhone_WithSamePhoneInMultipleEntries_ShouldChangePhoneInAllEntries()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var name2 = "Gosho";
            var phones1 = new[] { "0888 444 444" };
            var phones2 = new string[] { "0111333222", "0888 444 444" };

            database.AddPhone(name, phones1);
            database.AddPhone(name2, phones2);
            database.ChangePhone("0888 444 444", "0888 555 555");

            var expectedResult = "[Gosho: 0111333222, 0888 555 555]\n[Pesho: 0888 555 555]";

            Assert.AreEqual(expectedResult, string.Join<PhoneEntry>("\n", database.ListEntries(0, 2)));
        }
Example #11
0
        public void ChangePhone_WithValidInput_ShouldChangePhone()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones2 = new string[] { "0111333222", "+359222333444", "0888 444 444" };

            database.AddPhone(name, phones2);
            database.ChangePhone("0111333222", "+359 111 222 333");

            var expectedResult = "[Pesho: +359 111 222 333, +359222333444, 0888 444 444]";

            Assert.AreEqual(expectedResult, database.ListEntries(0, 1)[0].ToString());
        }     
Example #12
0
        public void List_WithMultipleDatabaseEntries_ShouldReturnCorrectlySortedData()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var name2 = "Ivan";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };
            var phones2 = new string[] { "0111333222", "+359222333444", "0888 444 444" };

            database.AddPhone(name, phones);
            database.AddPhone(name2, phones2);

            var expectedResult = string.Format("[Ivan: +359222333444, 0111333222, 0888 444 444]{0}[Pesho: + 333 12 24 55, 0009990 24-55-66, 0999 (222) 333]", Environment.NewLine);

            Assert.AreEqual(expectedResult, string.Join<PhoneEntry>(Environment.NewLine, database.ListEntries(0, 2)));
        }
Example #13
0
        public void List_WithIncorrectParameters_ShouldThrowArgumentException()
        {
            var database = new PhonebookRepository();
            var name = "Pesho";
            var phones = new string[] { "0999 (222) 333", "+ 333 12 24 55", "0009990 24-55-66" };

            database.AddPhone(name, phones);

            var expectedEntry = "[Pesho: + 333 12 24 55, 0009990 24-55-66, 0999 (222) 333]";

            Assert.AreEqual(name, database.ListEntries(-1, 10)[0].Name);
            Assert.AreEqual(expectedEntry, database.ListEntries(0, 1)[0].ToString());
        }