internal static void AssertEqual(this Contact contact, IContactSummaryReturn contactReturn)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }
            if (contactReturn == null)
            {
                throw new ArgumentNullException("contactReturn");
            }

            Assert.AreEqual(new ContactKey(contact).KeyValue, contactReturn.ContactKey);
            Assert.AreEqual(new CompanyKey(contact).KeyValue, contactReturn.CompanyKey);
            Assert.AreEqual(contact.Name, contactReturn.Name);
            Assert.AreEqual(contact.PhoneNumber, contactReturn.PhoneNumber);
            Assert.AreEqual(contact.EMailAddress, contactReturn.EMailAddress);
            if (contact.Addresses == null)
            {
                if (contactReturn.Addresses != null)
                {
                    Assert.IsEmpty(contactReturn.Addresses);
                }
            }
            else
            {
                contact.Addresses.ForEach(a =>
                {
                    var contactAddressKey = new ContactAddressKey(a);
                    a.Address.AssertEqual(contactReturn.Addresses.Single(r => contactAddressKey.KeyValue == r.ContactAddressKey).Address);
                });
            }
        }
Esempio n. 2
0
        internal static IResult <SetContactAddressParameters> ToParsedParameters(this IContactAddressReturn contactAddress)
        {
            if (contactAddress == null)
            {
                throw new ArgumentNullException("contactAddress");
            }

            ContactAddressKey contactAddressKey = null;

            if (contactAddress.ContactAddressKey != null)
            {
                var contactAddressKeyResult = KeyParserHelper.ParseResult <IContactAddressKey>(contactAddress.ContactAddressKey);
                if (!contactAddressKeyResult.Success)
                {
                    return(contactAddressKeyResult.ConvertTo <SetContactAddressParameters>());
                }
                contactAddressKey = contactAddressKeyResult.ResultingObject.ToContactAddressKey();
            }

            return(new SuccessResult <SetContactAddressParameters>(new SetContactAddressParameters
            {
                ContactAddress = contactAddress,
                ContactAddressKey = contactAddressKey
            }));
        }
            public void Removes_Contact_and_associated_records_from_database_on_success()
            {
                //Arrange
                var contactKey  = new ContactKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>(c => c.Addresses = null));
                var addressKey0 = new ContactAddressKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ContactAddress>(c => c.SetContact(contactKey)));
                var addressKey1 = new ContactAddressKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ContactAddress>(c => c.SetContact(contactKey)));
                var addressKey2 = new ContactAddressKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ContactAddress>(c => c.SetContact(contactKey)));



                //Act
                var result = Service.DeleteContact(contactKey.KeyValue);

                //Assert
                result.AssertSuccess();

                Assert.IsNull(RVCUnitOfWork.ContactAddressRepository.FindByKey(addressKey0));
                Assert.IsNull(RVCUnitOfWork.ContactAddressRepository.FindByKey(addressKey1));
                Assert.IsNull(RVCUnitOfWork.ContactAddressRepository.FindByKey(addressKey2));
                Assert.IsNull(RVCUnitOfWork.ContactRepository.FindByKey(contactKey));
            }
            public void Updates_Contact_as_expected_on_success()
            {
                //Arrange
                const int    expectedAddresses          = 2;
                const string expectedAddressDescription = "Desc";
                const string expectedName        = "Jimmy Corrigan";
                const string expectedPhoneNumber = "lonelyNumber";
                const string expectedEmail       = "probably none";

                var updatedAddress = new Address
                {
                    AddressLine1 = "updated"
                };

                var newAddress = new Address
                {
                    AddressLine1 = "new"
                };

                var contactKey         = new ContactKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Contact>(c => c.Addresses = null));
                var addressToUpdateKey = new ContactAddressKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ContactAddress>(a => a.SetContact(contactKey)));
                var addressToRemoveKey = new ContactAddressKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ContactAddress>(a => a.SetContact(contactKey)));

                //Act
                var result = Service.UpdateContact(new UpdateContactParameters
                {
                    ContactKey   = contactKey,
                    Name         = expectedName,
                    PhoneNumber  = expectedPhoneNumber,
                    EmailAddress = expectedEmail,
                    Addresses    = new List <IContactAddressReturn>
                    {
                        new ContactAddressParameters
                        {
                            ContactAddressKey  = addressToUpdateKey.KeyValue,
                            AddressDescription = expectedAddressDescription,
                            Address            = updatedAddress
                        },
                        new ContactAddressParameters
                        {
                            Address = newAddress
                        }
                    }
                });

                //Assert
                result.AssertSuccess();

                var contact = RVCUnitOfWork.ContactRepository.FindByKey(contactKey, c => c.Addresses);

                Assert.AreEqual(expectedName, contact.Name);
                Assert.AreEqual(expectedPhoneNumber, contact.PhoneNumber);
                Assert.AreEqual(expectedEmail, contact.EMailAddress);

                var addresses = contact.Addresses.ToList();

                Assert.AreEqual(expectedAddresses, addresses.Count);

                var contactAddress = addresses.Single(a => addressToUpdateKey.Equals(a));

                Assert.AreEqual(contactAddress.AddressDescription, expectedAddressDescription);
                contactAddress.Address.AssertEqual(updatedAddress);
                Assert.IsNull(addresses.SingleOrDefault(a => addressToRemoveKey.Equals(a)));
                addresses.Single(a => a.Address.AddressLine1 == newAddress.AddressLine1).Address.AssertEqual(newAddress);
            }