public void CanSave_WhenAddressWithSameNameExists_ShouldReturnFalse() { var model = new AddressModel { AddressId = Guid.NewGuid().ToString(), Name = _address1.Name }; Assert.False(_subject.CanSave(model)); }
public void CanSave_WhenAddressWithSameNameDoesNotExist_ShouldReturnTrue() { var guid = Guid.NewGuid(); var model = new AddressModel { AddressId = guid.ToString(), Name = guid.ToString() }; Assert.True(_subject.CanSave(model)); }
public void Save_WhenSavingNewAddress_ShouldAddAddressToCurrentContact() { var guid = Guid.NewGuid(); var model = new AddressModel { Name = guid.ToString() }; _subject.Save(model); Assert.NotNull(_currentContact.ContactAddresses.SingleOrDefault(x => x.AddressId == Guid.Parse(model.AddressId))); }
public void Save_WhenSavingExistingAddress_ShouldUpdateAddressInCurrentContact() { var model = new AddressModel { AddressId = ((Guid)_address1.AddressId).ToString(), Name = _address1.AddressId.ToString() }; _subject.Save(model); Assert.NotNull(_currentContact.ContactAddresses.SingleOrDefault(x => x.Name == model.AddressId.ToString())); }
public ShipmentViewModelFactoryTests() { _cart = new FakeCart(new MarketImpl(new MarketId(Currency.USD)), Currency.USD) { Name = "Default" }; _cart.Forms.Single().Shipments.Single().LineItems.Add(new InMemoryLineItem { Code = "code"}); _cart.Forms.Single().CouponCodes.Add("couponcode"); var shippingManagerFacadeMock = new Mock<ShippingManagerFacade>(); shippingManagerFacadeMock.Setup(x => x.GetShippingMethodsByMarket(It.IsAny<string>(), It.IsAny<bool>())).Returns(() => new List<ShippingMethodInfoModel> { new ShippingMethodInfoModel { LanguageId = CultureInfo.InvariantCulture.TwoLetterISOLanguageName, Currency = Currency.USD } }); _shippingRate = new ShippingRate(Guid.NewGuid(), "name", new Money(10, Currency.USD)); shippingManagerFacadeMock.Setup(x => x.GetRate(It.IsAny<IShipment>(), It.IsAny<ShippingMethodInfoModel>(), It.IsAny<IMarket>())) .Returns(_shippingRate); var languageServiceMock = new Mock<LanguageService>(null, null, null, null); languageServiceMock.Setup(x => x.GetCurrentLanguage()).Returns(CultureInfo.InvariantCulture); var referenceConverterMock = new Mock<ReferenceConverter>(null,null); var addressBookServiceMock = new Mock<IAddressBookService>(); _addressModel = new AddressModel(); addressBookServiceMock.Setup(x => x.ConvertToModel(It.IsAny<IOrderAddress>())).Returns(_addressModel); _cartItem = new CartItemViewModel (); var cartItemViewModelFactoryMock = new Mock<CartItemViewModelFactory>(null,null,null,null,null,null,null,null,null,null, null); cartItemViewModelFactoryMock.Setup(x => x.CreateCartItemViewModel(It.IsAny<ICart>(), It.IsAny<ILineItem>(), It.IsAny<VariationContent>())).Returns(_cartItem); var contentLoaderMock = new Mock<IContentLoader>(); contentLoaderMock.Setup(x => x.GetItems(It.IsAny<IEnumerable<ContentReference>>(), It.IsAny<CultureInfo>())) .Returns(() => new List<VariationContent> {new VariationContent {Code = "code"} }); var relationRepositoryMock = new Mock<IRelationRepository>(); relationRepositoryMock.Setup(x => x.GetRelationsByTarget<ProductVariation>(It.IsAny<ContentReference>())) .Returns(() => new[] {new ProductVariation {Source = new ContentReference(1)}}); _subject = new ShipmentViewModelFactory( contentLoaderMock.Object, shippingManagerFacadeMock.Object, languageServiceMock.Object, referenceConverterMock.Object, addressBookServiceMock.Object, cartItemViewModelFactoryMock.Object, () => CultureInfo.GetCultureInfo("en"), relationRepositoryMock.Object); }
public void Save_WhenSavingNewAddress_ShouldUpdatePreferredBillingAddress() { var guid = Guid.NewGuid().ToString(); var model = new AddressModel { AddressId = guid, Name = guid.ToString(), BillingDefault = true, }; _subject.Save(model); Assert.Equal<Guid?>(Guid.Parse(model.AddressId), _currentContact.PreferredBillingAddress.AddressId); }
private void UpdateShippingAddressesForAnonymous(MultiShipmentViewModel viewModel) { foreach (var item in viewModel.CartItems) { var anonymousShippingAddress = new AddressModel { AddressId = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString(), CountryCode = "USA" }; item.AddressId = anonymousShippingAddress.AddressId; _addressBookService.LoadCountriesAndRegionsForAddress(anonymousShippingAddress); viewModel.AvailableAddresses.Add(anonymousShippingAddress); } }
public void MapToAddress(AddressModel addressModel, IOrderAddress orderAddress) { orderAddress.Id = addressModel.Name; orderAddress.City = addressModel.City; orderAddress.CountryCode = addressModel.CountryCode; orderAddress.CountryName = _countryManager.GetCountries().Country.Where(x => x.Code == addressModel.CountryCode).Select(x => x.Name).FirstOrDefault(); orderAddress.FirstName = addressModel.FirstName; orderAddress.LastName = addressModel.LastName; orderAddress.Line1 = addressModel.Line1; orderAddress.Line2 = addressModel.Line2; orderAddress.DaytimePhoneNumber = addressModel.DaytimePhoneNumber; orderAddress.PostalCode = addressModel.PostalCode; orderAddress.RegionName = addressModel.CountryRegion.Region; orderAddress.RegionCode = addressModel.CountryRegion.Region; orderAddress.Email = addressModel.Email; orderAddress.Organization = addressModel.Organization; }
public void MapToModel(IOrderAddress orderAddress, AddressModel addressModel) { addressModel.Name = orderAddress.Id; addressModel.Line1 = orderAddress.Line1; addressModel.Line2 = orderAddress.Line2; addressModel.City = orderAddress.City; addressModel.CountryName = orderAddress.CountryName; addressModel.CountryCode = orderAddress.CountryCode; addressModel.Email = orderAddress.Email; addressModel.FirstName = orderAddress.FirstName; addressModel.LastName = orderAddress.LastName; addressModel.PostalCode = orderAddress.PostalCode; addressModel.CountryRegion = new CountryRegionViewModel { Region = orderAddress.RegionName ?? orderAddress.RegionCode }; addressModel.DaytimePhoneNumber = orderAddress.DaytimePhoneNumber; }
public void MapToModel(CustomerAddress customerAddress, AddressModel addressModel) { addressModel.Line1 = customerAddress.Line1; addressModel.Line2 = customerAddress.Line2; addressModel.City = customerAddress.City; addressModel.CountryName = customerAddress.CountryName; addressModel.CountryCode = customerAddress.CountryCode; addressModel.Email = customerAddress.Email; addressModel.FirstName = customerAddress.FirstName; addressModel.LastName = customerAddress.LastName; addressModel.PostalCode = customerAddress.PostalCode; addressModel.CountryRegion = new CountryRegionViewModel { Region = customerAddress.RegionName ?? customerAddress.RegionCode ?? customerAddress.State }; addressModel.ShippingDefault = _customerContext.CurrentContact.PreferredShippingAddress != null && customerAddress.Name == _customerContext.CurrentContact.PreferredShippingAddress.Name; addressModel.BillingDefault = _customerContext.CurrentContact.PreferredBillingAddress != null && customerAddress.Name == _customerContext.CurrentContact.PreferredBillingAddress.Name; addressModel.AddressId = customerAddress.Name; addressModel.Name = customerAddress.Name; addressModel.DaytimePhoneNumber = customerAddress.DaytimePhoneNumber; }
public AddressModel ConvertToModel(IOrderAddress orderAddress) { var address = new AddressModel { AddressId = Guid.NewGuid().ToString() }; if (orderAddress != null) { MapToModel(orderAddress, address); } return address; }
public bool CanSave(AddressModel addressModel) { return !_customerContext.CurrentContact.ContactAddresses.Any(x => x.Name.Equals(addressModel.Name, StringComparison.InvariantCultureIgnoreCase) && x.Name != addressModel.AddressId); }
public void Save(AddressModel addressModel) { var currentContact = _customerContext.CurrentContact; var customerAddress = CreateOrUpdateCustomerAddress(currentContact, addressModel); if (addressModel.BillingDefault) { currentContact.PreferredBillingAddress = customerAddress; } else if (currentContact.PreferredBillingAddress != null && currentContact.PreferredBillingAddress.Name.Equals(addressModel.AddressId)) { currentContact.PreferredBillingAddressId = null; } if (addressModel.ShippingDefault) { currentContact.PreferredShippingAddress = customerAddress; } else if (currentContact.PreferredShippingAddress != null && currentContact.PreferredShippingAddress.Name.Equals(addressModel.AddressId)) { currentContact.PreferredShippingAddressId = null; } currentContact.SaveChanges(); }
public void LoadAddress_WhenModelHasNoAddressId_ShouldReturnEmptyModel() { var model = new AddressModel(); _subject.LoadAddress(model); Assert.Null(model.AddressId); }
public void LoadAddress(AddressModel addressModel) { var currentContact = _customerContext.CurrentContact; addressModel.CountryOptions = GetAllCountries(); if (addressModel.CountryCode == null && addressModel.CountryOptions.Any()) { addressModel.CountryCode = addressModel.CountryOptions.First().Code; } if (!string.IsNullOrEmpty(addressModel.AddressId)) { var existingCustomerAddress = GetAddress(currentContact, addressModel.AddressId); if (existingCustomerAddress != null) { MapToModel(existingCustomerAddress, addressModel); } } if (!string.IsNullOrEmpty(addressModel.CountryCode)) { if (addressModel.CountryRegion == null) { addressModel.CountryRegion = new CountryRegionViewModel(); } addressModel.CountryRegion.RegionOptions = GetRegionsByCountryCode(addressModel.CountryCode); } }
public void Save_WhenSavingExistingAddress_ShouldUpdatePreferredShippingAddress() { var model = new AddressModel { AddressId = _address1.AddressId.ToString(), Name = _address1.AddressId.ToString(), ShippingDefault = true }; _subject.Save(model); Assert.Equal<Guid?>(Guid.Parse(model.AddressId), _currentContact.PreferredShippingAddress.AddressId); }
public void LoadCountriesAndRegionsForAddress(AddressModel addressModel) { addressModel.CountryOptions = GetAllCountries(); // Try get the address country first by country code, then by name, else use the first in list as final fallback. var selectedCountry = (GetCountryByCode(addressModel) ?? GetCountryByName(addressModel)) ?? addressModel.CountryOptions.FirstOrDefault(); addressModel.CountryRegion.RegionOptions = selectedCountry != null ? GetRegionsByCountryCode(selectedCountry.Code) : Enumerable.Empty<string>(); }
public void MapToAddress(AddressModel addressModel, CustomerAddress customerAddress) { customerAddress.Name = addressModel.Name; customerAddress.City = addressModel.City; customerAddress.CountryCode = addressModel.CountryCode; customerAddress.CountryName = _countryManager.GetCountries().Country.Where(x => x.Code == addressModel.CountryCode).Select(x => x.Name).FirstOrDefault(); customerAddress.FirstName = addressModel.FirstName; customerAddress.LastName = addressModel.LastName; customerAddress.Line1 = addressModel.Line1; customerAddress.Line2 = addressModel.Line2; customerAddress.DaytimePhoneNumber = addressModel.DaytimePhoneNumber; customerAddress.PostalCode = addressModel.PostalCode; customerAddress.RegionName = addressModel.CountryRegion.Region; customerAddress.RegionCode = addressModel.CountryRegion.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 = addressModel.CountryRegion.Region; customerAddress.Email = addressModel.Email; customerAddress.AddressType = CustomerAddressTypeEnum.Public | (addressModel.ShippingDefault ? CustomerAddressTypeEnum.Shipping : 0) | (addressModel.BillingDefault ? CustomerAddressTypeEnum.Billing : 0); }
public IOrderAddress ConvertToAddress(AddressModel model) { var address = _orderFactory.CreateOrderAddress(); address.Id = model.Name; MapToAddress(model, address); return address; }
private AddressModel ConvertAddress(CustomerAddress customerAddress) { AddressModel addressModel = null; if (customerAddress != null) { addressModel = new AddressModel(); MapToModel(customerAddress, addressModel); } return addressModel; }
private CustomerAddress CreateOrUpdateCustomerAddress(CurrentContactFacade contact, AddressModel addressModel) { var customerAddress = GetAddress(contact, addressModel.AddressId); var isNew = customerAddress == null; IEnumerable<PrimaryKeyId> existingId = contact.ContactAddresses.Select(a => a.AddressId).ToList(); if (isNew) { customerAddress = CustomerAddress.CreateInstance(); } MapToAddress(addressModel, 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(); addressModel.AddressId = customerAddress.Name; } return customerAddress; }
private CountryViewModel GetCountryByName(AddressModel addressModel) { var selectedCountry = addressModel.CountryOptions.FirstOrDefault(x => x.Name == addressModel.CountryName); if (selectedCountry != null) { addressModel.CountryCode = selectedCountry.Code; } return selectedCountry; }