public async Task WHEN_Passing_RegisteredCustomer_Valid_Parameters_SHOULD_Update_ShippingAddress() { //Arrange var cart = CreateBasicCart(); cart.Shipments.First().Address = new Address() { City = GetRandom.String(10), PostalCode = GetRandom.String(6), Id = Guid.NewGuid() }; var service = CreateCheckoutService(cart); var updatedAddress = new RegisteredShippingAddressViewModel { ShippingAddressId = Guid.NewGuid() }; var address = await _container.Get <IAddressRepository>().GetAddressByIdAsync(updatedAddress.ShippingAddressId); // Act var param = new UpdateCheckoutCartParam { GetCartParam = CreateGetCartParam(), UpdateValues = CreateUpdateOperation("ShippingAddressRegistered", updatedAddress), CurrentStep = GetRandom.Int(), IsGuest = GetRandom.Boolean() }; var processedCart = await service.UpdateCheckoutCartAsync(param); //Assert processedCart.Cart.Should().NotBeNull(); processedCart.Cart.ShippingAddress.AddressBookId.ShouldBeEquivalentTo(updatedAddress.ShippingAddressId); processedCart.Cart.ShippingAddress.AddressName.ShouldBeEquivalentTo(address.AddressName); processedCart.Cart.ShippingAddress.City.ShouldBeEquivalentTo(address.City); processedCart.Cart.ShippingAddress.CountryCode.ShouldBeEquivalentTo(address.CountryCode); processedCart.Cart.ShippingAddress.FirstName.ShouldBeEquivalentTo(address.FirstName); processedCart.Cart.ShippingAddress.LastName.ShouldBeEquivalentTo(address.LastName); processedCart.Cart.ShippingAddress.Line1.ShouldBeEquivalentTo(address.Line1); processedCart.Cart.ShippingAddress.Line2.ShouldBeEquivalentTo(address.Line2); processedCart.Cart.ShippingAddress.PhoneNumber.ShouldBeEquivalentTo(address.PhoneNumber); processedCart.Cart.ShippingAddress.PostalCode.ShouldBeEquivalentTo(address.PostalCode); processedCart.Cart.ShippingAddress.RegionCode.ShouldBeEquivalentTo(address.RegionCode); }
protected virtual async Task UpdateRegisteredShippingAddress(Overture.ServiceModel.Orders.Cart cart, RegisteredShippingAddressViewModel registeredShippingAddressViewModel) { if (registeredShippingAddressViewModel == null) { return; } if (registeredShippingAddressViewModel.ShippingAddressId == Guid.Empty) { return; } var shipment = cart.Shipments.FirstOrDefault(); if (shipment == null) { return; } var newAddress = await AddressRepository.GetAddressByIdAsync(registeredShippingAddressViewModel.ShippingAddressId).ConfigureAwait(false); var isShippingChanged = shipment.Address == null || !IsEqual(shipment.Address, newAddress); if (isShippingChanged) { shipment.Address = newAddress; shipment.Address.PropertyBag[AddressBookIdPropertyBagKey] = newAddress.Id; shipment.Address.Id = Guid.Empty; } //In the case the user didn't do estimate shipping before await ShippingMethodViewService.EstimateShippingAsync(new EstimateShippingParam { Cart = cart, CultureInfo = CultureInfo.GetCultureInfo(cart.CultureName), //TODO: Fix me ForceUpdate = isShippingChanged }).ConfigureAwait(false); }