public void CanSave_WhenAddressWithSameNameExists_ShouldReturnFalse() { var model = new Address { AddressId = Guid.NewGuid(), Name = _address1.Name }; Assert.IsFalse(_subject.CanSave(model)); }
public void CanSave_WhenAddressWithSameNameDoesNotExist_ShouldReturnTrue() { var guid = Guid.NewGuid(); var model = new Address { AddressId = guid, Name = guid.ToString() }; Assert.IsTrue(_subject.CanSave(model)); }
public void Save_WhenSavingExistingAddress_ShouldUpdateAddressInCurrentContact() { var model = new Address { AddressId = _address1.AddressId, Name = _address1.AddressId.ToString() }; _subject.Save(model); Assert.IsNotNull(_currentContact.ContactAddresses.SingleOrDefault(x => x.Name == model.AddressId.ToString())); }
public void Save_WhenSavingNewAddress_ShouldAddAddressToCurrentContact() { var guid = Guid.NewGuid(); var model = new Address { Name = guid.ToString() }; _subject.Save(model); Assert.IsNotNull(_currentContact.ContactAddresses.SingleOrDefault(x => x.AddressId == model.AddressId)); }
public void Save_WhenSavingNewAddress_ShouldUpdatePreferredBillingAddress() { var guid = Guid.NewGuid(); var model = new Address { AddressId = guid, Name = guid.ToString(), BillingDefault = true, }; _subject.Save(model); Assert.AreEqual<Guid?>(model.AddressId, _currentContact.PreferredBillingAddress.AddressId); }
public void MapModelToOrderAddress(Address address, OrderAddress orderAddress) { orderAddress.City = address.City; orderAddress.CountryCode = address.CountryCode; orderAddress.CountryName = GetAllCountries().Where(x => x.Code == address.CountryCode).Select(x => x.Name).FirstOrDefault(); orderAddress.FirstName = address.FirstName; orderAddress.LastName = address.LastName; orderAddress.Line1 = address.Line1; orderAddress.Line2 = address.Line2; orderAddress.DaytimePhoneNumber = address.DaytimePhoneNumber; orderAddress.PostalCode = address.PostalCode; orderAddress.RegionName = address.Region; // Commerce Manager expects State to be set for addresses in order management. Set it to be same as // RegionName to avoid issues. orderAddress.State = address.Region; orderAddress.Email = address.Email; }
public void MapOrderAddressToModel(Address address, OrderAddress orderAddress) { address.Line1 = orderAddress.Line1; address.Line2 = orderAddress.Line2; address.City = orderAddress.City; address.CountryName = orderAddress.CountryName; address.CountryCode = orderAddress.CountryCode; address.Email = orderAddress.Email; address.FirstName = orderAddress.FirstName; address.LastName = orderAddress.LastName; address.PostalCode = orderAddress.PostalCode; address.SaveAddress = false; address.Region = orderAddress.RegionName ?? orderAddress.State; address.Modified = orderAddress.Modified; address.Name = orderAddress.Name; address.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; }
public void MapCustomerAddressToModel(Address address, CustomerAddress customerAddress) { address.Line1 = customerAddress.Line1; address.Line2 = customerAddress.Line2; address.City = customerAddress.City; address.CountryName = customerAddress.CountryName; address.CountryCode = customerAddress.CountryCode; address.Email = customerAddress.Email; address.FirstName = customerAddress.FirstName; address.LastName = customerAddress.LastName; address.PostalCode = customerAddress.PostalCode; address.SaveAddress = HttpContext.Current.User.Identity.IsAuthenticated; address.Region = customerAddress.RegionName ?? customerAddress.State; address.ShippingDefault = customerAddress.Equals(_customercontext.CurrentContact.PreferredShippingAddress); address.BillingDefault = customerAddress.Equals(_customercontext.CurrentContact.PreferredBillingAddress); address.AddressId = customerAddress.AddressId; address.Modified = customerAddress.Modified; address.Name = customerAddress.Name; address.DaytimePhoneNumber = customerAddress.DaytimePhoneNumber; }
private CustomerAddress CreateOrUpdateCustomerAddress(CurrentContactFacade contact, Address address) { var customerAddress = GetAddress(contact, address.AddressId); var isNew = customerAddress == null; IEnumerable<PrimaryKeyId> existingId = contact.ContactAddresses.Select(a => a.AddressId).ToList(); if (isNew) { customerAddress = CustomerAddress.CreateInstance(); } MapModelToCustomerAddress(address, customerAddress); if (isNew) { contact.AddContactAddress(customerAddress); } else { contact.UpdateContactAddress(customerAddress); } contact.SaveChanges(); if (isNew) { customerAddress.AddressId = contact.ContactAddresses .Where(a => !existingId.Contains(a.AddressId)) .Select(a => a.AddressId) .Single(); address.AddressId = customerAddress.AddressId; } return customerAddress; }
private CountryDto.CountryRow GetCountryByName(Address address) { var selectedCountry = address.CountryOptions.FirstOrDefault(x => x.Name == address.CountryName); if (selectedCountry != null) { address.CountryCode = selectedCountry.Code; } return selectedCountry; }
public void GetCountriesAndRegionsForAddress(Address address) { address.CountryOptions = GetAllCountries(); //try get country first by code, then by name, then the first in list as final fallback var selectedCountry = (GetCountryByCode(address) ?? GetCountryByName(address)) ?? address.CountryOptions.FirstOrDefault(); address.RegionOptions = GetRegionOptionsFromCountry(selectedCountry); }
public void LoadAddress(Address address) { var currentContact = _customercontext.CurrentContact; address.CountryOptions = GetAllCountries(); if (address.CountryCode == null && address.CountryOptions.Any()) { address.CountryCode = address.CountryOptions.First().Code; } if (address.AddressId.HasValue) { var existingCustomerAddress = GetAddress(currentContact, address.AddressId); if (existingCustomerAddress == null) { throw new ArgumentException(string.Format("The address id {0} could not be found.", address.AddressId.Value)); } MapCustomerAddressToModel(address, existingCustomerAddress); } if (!string.IsNullOrEmpty(address.CountryCode)) { address.RegionOptions = GetRegionOptionsByCountryCode(address.CountryCode); } }
public void LoadAddress_WhenAddressIdDoesNotExist_ShouldThrowException() { _currentContact = new FakeCurrentContact(Enumerable.Empty<CustomerAddress>()); var customerContext = new FakeCustomerContext(_currentContact); var countryManager = new FakeCountryManager(); _subject = new AddressBookService(customerContext, countryManager); var model = new Address(); model.AddressId = Guid.NewGuid(); _subject.LoadAddress(model); }
public void LoadAddress_WhenModelHasNoAddressId_ShouldReturnEmptyModel() { var model = new Address(); _subject.LoadAddress(model); Assert.IsNull(model.AddressId); }
private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage) { Address address = null; if (customerAddress != null) { address = new Address(); MapCustomerAddressToModel(address, customerAddress); } return address; }
public bool CanSave(Address address) { return !_customercontext.CurrentContact.ContactAddresses.Any(x => x.Name.Equals(address.Name, StringComparison.InvariantCultureIgnoreCase) && x.AddressId != address.AddressId); }
public void Save(Address address) { var currentContact = _customercontext.CurrentContact; var customerAddress = CreateOrUpdateCustomerAddress(currentContact, address); if (address.BillingDefault) { currentContact.PreferredBillingAddress = customerAddress; } else if (currentContact.PreferredBillingAddressId == address.AddressId) { currentContact.PreferredBillingAddressId = null; } if (address.ShippingDefault) { currentContact.PreferredShippingAddress = customerAddress; } else if (currentContact.PreferredShippingAddressId == address.AddressId) { currentContact.PreferredShippingAddressId = null; } currentContact.SaveChanges(); }
public void MapModelToCustomerAddress(Address address, CustomerAddress customerAddress) { customerAddress.Name = address.Name; customerAddress.City = address.City; customerAddress.CountryCode = address.CountryCode; customerAddress.CountryName = GetAllCountries().Where(x => x.Code == address.CountryCode).Select(x => x.Name).FirstOrDefault(); customerAddress.FirstName = address.FirstName; customerAddress.LastName = address.LastName; customerAddress.Line1 = address.Line1; customerAddress.Line2 = address.Line2; customerAddress.DaytimePhoneNumber = address.DaytimePhoneNumber; customerAddress.PostalCode = address.PostalCode; customerAddress.RegionName = address.Region; // Commerce Manager expects State to be set for addresses in order management. Set it to be same as // RegionName to avoid issues. customerAddress.State = address.Region; customerAddress.Email = address.Email; customerAddress.AddressType = CustomerAddressTypeEnum.Public | (address.ShippingDefault ? CustomerAddressTypeEnum.Shipping : 0) | (address.BillingDefault ? CustomerAddressTypeEnum.Billing : 0); }
public void Save_WhenSavingExistingAddress_ShouldUpdatePreferredShippingAddress() { var model = new Address { AddressId = _address1.AddressId, Name = _address1.AddressId.ToString(), ShippingDefault = true }; _subject.Save(model); Assert.AreEqual<Guid?>(model.AddressId, _currentContact.PreferredShippingAddress.AddressId); }