Exemplo n.º 1
0
        public void ConstructorTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBook        = addressBookBuilder.Build();

            Helper.AssertAreEqual(addressBookBuilder, addressBook);
        }
Exemplo n.º 2
0
        internal static void AssertAreEqual(AddressBookBuilder expected, AddressBook actual, string message)
        {
            var expectedBuilders = expected.GetAddressBuilders();
            var actualAddresses  = actual.GetAll();

            Assert.AreEqual(expectedBuilders.Count, actualAddresses.Count, $"Count {message}");

            // Test that each of the addresses we expect exist inside the addresses that we actually have
            foreach (var builder in expectedBuilders)
            {
                bool found = false;
                foreach (var address in actualAddresses)
                {
                    if (builder.Key == address.Key)
                    {
                        AssertAreEqual(builder.Value, address.Value);

                        found = true;
                        break;
                    }
                }

                Assert.IsTrue(found, $"{builder.Key} Address is not found {message}");
            }
        }
Exemplo n.º 3
0
        public void RemoveDoesNotExistTest()
        {
            var builder     = new AddressBookBuilder();
            var addressBook = builder.Build();

            Helper.AssertAreEqual(builder, addressBook, "Before");

            addressBook.Remove("Does not exist");

            Helper.AssertAreEqual(builder, addressBook, "After");
        }
Exemplo n.º 4
0
        public void AddNullAddressTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBook        = addressBookBuilder.Build();

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "Before");

            var addressBuilders = addressBookBuilder.GetAddressBuilders();

            var addressBuilder = new AddressBuilder();
            var name           = "New address name";

            addressBuilders.Add(name, addressBuilder);
            addressBook.Add(null);

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "After");
        }
Exemplo n.º 5
0
        public void RemoveTest()
        {
            var builder         = new AddressBookBuilder();
            var addressBuilders = builder.GetAddressBuilders();
            var name            = "Address we will remove";
            var addressBuilder  = new AddressBuilder();

            addressBuilders.Add(name, addressBuilder);
            var addressBook = builder.Build();

            Helper.AssertAreEqual(builder, addressBook, "Before");

            addressBuilders.Remove(name);
            addressBook.Remove(name);

            Helper.AssertAreEqual(builder, addressBook, "After");
        }
Exemplo n.º 6
0
        public void UpdateKeyDoesNotExistTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBook        = addressBookBuilder.Build();

            var addressBuilders = addressBookBuilder.GetAddressBuilders();

            var addressBuilder = new AddressBuilder();
            var name           = "Sally";

            addressBuilders.Add(name, addressBuilder);
            addressBook.Add(addressBuilder.Build());

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "Before");

            addressBook.Update(name, "foo", "bar");
        }
Exemplo n.º 7
0
        public void UpdateNameDoesNotExistTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBook        = addressBookBuilder.Build();

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "Before");

            var addressBuilders = addressBookBuilder.GetAddressBuilders();

            var addressBuilder = new AddressBuilder();
            var name           = "New address name";

            addressBuilders.Add(name, addressBuilder);

            addressBook.Update(name, "name", name);

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "After");
        }
Exemplo n.º 8
0
        public void UpdateTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBuilders    = addressBookBuilder.GetAddressBuilders();
            var addressBuilder     = new AddressBuilder();
            var name = "Jake";

            addressBuilders.Add(name, addressBuilder);
            var addressBook = addressBookBuilder.Build();

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "Before");

            var street     = "One Haight Street";
            var newAddress = new AddressBuilder().SetStreet(street);

            addressBuilders.Remove(name);
            addressBuilders.Add(name, newAddress);

            addressBook.Update(name, "street", street);

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "After");
        }
Exemplo n.º 9
0
        public void UpdateNameTest()
        {
            var addressBookBuilder = new AddressBookBuilder();
            var addressBuilders    = addressBookBuilder.GetAddressBuilders();
            var addressBuilder     = new AddressBuilder().SetCountry("Ireland");
            var oldName            = "Paul Hewson";

            addressBuilders.Add(oldName, addressBuilder);
            var addressBook = addressBookBuilder.Build();

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "Before");

            var newName = "Bono";

            addressBuilders.Remove(oldName);
            addressBuilders.Add(newName, addressBuilder);
            addressBookBuilder.SetAddressBuilders(addressBuilders);

            addressBook.Update(oldName, "name", newName);

            Helper.AssertAreEqual(addressBookBuilder, addressBook, "After");
        }
Exemplo n.º 10
0
 internal static void AssertAreEqual(AddressBookBuilder expected, AddressBook actual)
 {
     AssertAreEqual(expected, actual, "");
 }