public void UpdateUser( string emailAddress, UpdateUserModel updateUserModel) { var unitOfWork = this.unitOfWorkFactory.CreateUnitOfWork(); var repository = unitOfWork.CreateUserRepository(); var user = repository.FindByEmailAddress(emailAddress); if (updateUserModel.BillingAddress != null && IsNewAddress(updateUserModel.BillingAddress)) { user.SetBillingAddress(updateUserModel.BillingAddress); } if (updateUserModel.ContactAddress != null && IsNewAddress(updateUserModel.ContactAddress)) { user.SetContactAddress(updateUserModel.ContactAddress); } if (!string.IsNullOrEmpty(updateUserModel.FirstName)) { user.SetFirstName(updateUserModel.FirstName); } if (!string.IsNullOrEmpty(updateUserModel.LastName)) { user.SetLastName(updateUserModel.LastName); } repository.Save(); }
public void UpdateUser_AddressesUpdatedCorrectly() { var email = "*****@*****.**"; var billingAddress = TestModelFactory.CreateAddress(); var contactAddress = TestModelFactory.CreateAddress(); var sampleUser = TestModelFactory.CreateUser(emailAddress: email, contactAddress: contactAddress, billingAddress: billingAddress); var service = CreateUserService(new List<UserModel>() { sampleUser }); var returnedUser = service.GetUserByEmail(email); returnedUser.BillingAddress.ShouldBeEquivalentTo(billingAddress); returnedUser.ContactAddress.ShouldBeEquivalentTo(contactAddress); var newBillingAddress = TestModelFactory.CreateAddress(); var newContactAddress = TestModelFactory.CreateAddress(); var updateUserModel = new UpdateUserModel { BillingAddress = newBillingAddress, ContactAddress = newContactAddress }; service.UpdateUser(email, updateUserModel); returnedUser = service.GetUserByEmail(email); returnedUser.BillingAddress.ShouldBeEquivalentTo(newBillingAddress); returnedUser.ContactAddress.ShouldBeEquivalentTo(newContactAddress); }