public async Task ProcessFormAsync_SavesAddressIfNoMatchingFound()
        {
            var saveAddressCalled = false;
            var newAddress = new Address
            {
                FirstName = "testfirst",
                StreetAddress = "teststreetaddress"
            };

            var existingAddresses = new List<Address>();
            var checkoutDataRepository = new MockCheckoutDataRepository();
            checkoutDataRepository.GetAllBillingAddressesAsyncDelegate =
                () => Task.FromResult<ICollection<Address>>(new Collection<Address>(existingAddresses));

            checkoutDataRepository.SaveBillingAddressAsyncDelegate = address =>
            {
                saveAddressCalled = true;
                Assert.AreEqual("teststreetaddress",
                                address.StreetAddress);
                return Task.Delay(0);
            };
            var target = new BillingAddressUserControlViewModel(checkoutDataRepository, null, null, null);
            target.Address = newAddress;

            await target.ProcessFormAsync();

            Assert.IsTrue(saveAddressCalled);
        }
        public async Task ProcessFormAsync_UsesExistingAddressIfMatchingFound()
        {
            var newAddress = new Address
            {
                FirstName = "testfirst",
                StreetAddress = "teststreetaddress"
            };

            var existingAddresses = new List<Address>
                                        {
                                            new Address
                                                {
                                                    Id = "testId",
                                                    FirstName = "testfirst",
                                                    StreetAddress = "teststreetaddress"
                                                }
                                        };

            var checkoutDataRepository = new MockCheckoutDataRepository();
            checkoutDataRepository.GetAllBillingAddressesAsyncDelegate =
                () => Task.FromResult<ICollection<Address>>(new ReadOnlyCollection<Address>(existingAddresses));

            var target = new BillingAddressUserControlViewModel(checkoutDataRepository, null, null, null);
            target.Address = newAddress;

            await target.ProcessFormAsync();

            Assert.AreEqual("testId", target.Address.Id);
        }
 public ShippingAddressUserControlViewModel(ICheckoutDataRepository checkoutDataRepository, ILocationService locationService, IResourceLoader resourceLoader, IAlertMessageService alertMessageService)
 {
     _address = new Address();
     _checkoutDataRepository = checkoutDataRepository;
     _locationService = locationService;
     _resourceLoader = resourceLoader;
     _alertMessageService = alertMessageService;
 }
 public Task SaveAddressAsync(Address address)
 {
     var matchingAddress = Addresses.FirstOrDefault(a => a.Id == address.Id && a.AddressType == address.AddressType);
     if (matchingAddress != null)
     {
         Addresses.Remove(matchingAddress);
     }
     Addresses.Add(address);
     return Task.Delay(0);
 }
        public async Task SaveAddressAsync(Address address)
        {
            using (var client = new HttpClient())
            {
                var serializedAddress = JsonConvert.SerializeObject(address);

                var response = await client.PostAsync(new Uri(_clientBaseUrl), new HttpStringContent(serializedAddress, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));
                await response.EnsureSuccessWithValidationSupportAsync();
            }
        }
        public async Task<Order> CreateOrderAsync(string userId, ShoppingCart shoppingCart, Address shippingAddress, Address billingAddress, PaymentMethod paymentMethod, ShippingMethod shippingMethod)
        {
            Order order = new Order
                {
                    UserId = userId,
                    ShoppingCart = shoppingCart,
                    ShippingAddress = shippingAddress,
                    BillingAddress = billingAddress,
                    PaymentMethod = paymentMethod,
                    ShippingMethod = shippingMethod
                };

            order.Id = await _orderService.CreateOrderAsync(order);

            return order;
        }
        public void OnNavigateTo_LoadsDefault_IfTryLoadDefaultTrue()
        {
            var defaultAddress = new Address
            {
                FirstName = "FirstName",
                State = "WA"
            };
            var checkoutDataRepository = new MockCheckoutDataRepository();
            checkoutDataRepository.GetDefaultBillingAddressAsyncDelegate = () => Task.FromResult(defaultAddress);
            var locationService = new MockLocationService();
            var resourceLoader = new MockResourceLoader();
            var target = new BillingAddressUserControlViewModel(checkoutDataRepository, locationService, resourceLoader, null);

            target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, new Dictionary<string, object>());
            Assert.IsNull(target.Address.FirstName);

            target.SetLoadDefault(true);
            target.OnNavigatedTo(new NavigatedToEventArgs { Parameter = null, NavigationMode = NavigationMode.New }, new Dictionary<string, object>());
            Assert.AreEqual("FirstName", target.Address.FirstName);
        }
 public Task SaveBillingAddressAsync(Address address)
 {
     return SaveBillingAddressAsyncDelegate(address);
 }
 public async Task CreateBasicOrderAsync(string userId, ShoppingCart shoppingCart, Address shippingAddress, Address billingAddress, PaymentMethod paymentMethod)
 {
     var basicShippingMethod = await _shippingMethodService.GetBasicShippingMethodAsync();
     _currentOrder = await CreateOrderAsync(userId, shoppingCart, shippingAddress, billingAddress, paymentMethod, basicShippingMethod);
     _sessionStateService.SessionState[OrderKey] = _currentOrder;
 }
 public Task<Order> CreateOrderAsync(string userId, ShoppingCart shoppingCart, Address shippingAddress, Address billingAddress, PaymentMethod paymentMethod, ShippingMethod shippingMethod)
 {
     return CreateOrderAsyncDelegate(userId, shoppingCart, shippingAddress, billingAddress, paymentMethod, shippingMethod);
 }
 public void SaveEntity(Address address)
 {
     Addresses.Add(address);
 }
 private CheckoutDataViewModel CreateCheckoutData(Address address, string dataType)
 {
     return new CheckoutDataViewModel()
     {
         EntityId = address.Id,
         DataType = dataType,
         Title = dataType == Constants.ShippingAddress ? _resourceLoader.GetString("ShippingAddress") : _resourceLoader.GetString("BillingAddress"),
         FirstLine = address.StreetAddress,
         SecondLine = string.Format(CultureInfo.CurrentCulture, "{0}, {1} {2}", address.City, address.State, address.ZipCode),
         BottomLine = string.Format(CultureInfo.CurrentCulture, "{0} {1}", address.FirstName, address.LastName),
         LogoUri = dataType == Constants.ShippingAddress ? new Uri(Constants.ShippingAddressLogo, UriKind.Absolute) : new Uri(Constants.BillingAddressLogo, UriKind.Absolute)
     };
 }
예제 #13
0
 public static Address FindMatchingAddress(Address searchAddress, IEnumerable<Address> addresses)
 {
     return addresses.FirstOrDefault(address =>
         searchAddress.FirstName == address.FirstName &&
         searchAddress.MiddleInitial == address.MiddleInitial &&
         searchAddress.LastName == address.LastName &&
         searchAddress.StreetAddress == address.StreetAddress &&
         searchAddress.OptionalAddress == address.OptionalAddress &&
         searchAddress.City == address.City &&
         searchAddress.State == address.State &&
         searchAddress.ZipCode == address.ZipCode);
 }
        public async Task SaveBillingAddressAsync(Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            address.Id = address.Id ?? Guid.NewGuid().ToString();
            address.AddressType = AddressType.Billing;

            // If there's no default value stored, use this one
            if (await GetDefaultBillingAddressAsync() == null)
            {
                address.IsDefault = true;
            }

            // Save the address in the service
            await _addressService.SaveAddressAsync(address);

            ExpireCachedAddresses();
        }
        public async Task SettingUseShippingAddressToTrue_CopiesValuesFromShippingAddressToBilling()
        {
            var mockAddress = new Address()
                {
                    FirstName = "TestFirstName",
                    MiddleInitial = "TestMiddleInitial",
                    LastName = "TestLastName",
                    StreetAddress = "TestStreetAddress",
                    OptionalAddress = "TestOptionalAddress",
                    City = "TestCity",
                    State = "TestState",
                    ZipCode = "123456",
                    Phone = "123456"
                };
            var compareAddressesFunc = new Func<Address, Address, bool>((Address a1, Address a2) =>
                {
                    return a1.FirstName == a2.FirstName && a1.MiddleInitial == a2.MiddleInitial && a1.LastName == a2.LastName
                           && a1.StreetAddress == a2.StreetAddress && a1.OptionalAddress == a2.OptionalAddress && a1.City == a2.City
                           && a1.State == a2.State && a1.ZipCode == a2.ZipCode && a1.Phone == a2.Phone;
                });

            var shippingAddressPageViewModel = new MockShippingAddressPageViewModel()
                {
                    ValidateFormDelegate = () => true,
                    ProcessFormAsyncDelegate = () => Task.Delay(0),
                    Address = mockAddress
                };
            var billingAddressPageViewModel = new MockBillingAddressPageViewModel()
                {
                    ValidateFormDelegate = () => true
                };
            billingAddressPageViewModel.ProcessFormAsyncDelegate = () =>
                {
                    // The Address have to be updated before the form is processed
                    Assert.IsTrue(compareAddressesFunc(shippingAddressPageViewModel.Address, billingAddressPageViewModel.Address));
                    return Task.Delay(0);
                };
            var paymentMethodPageViewModel = new MockPaymentMethodPageViewModel()
                {
                    ValidateFormDelegate = () => true,
                    ProcessFormAsyncDelegate = async () => await Task.Delay(0),
                };
            var accountService = new MockAccountService()
                {
                    VerifyUserAuthenticationAsyncDelegate = () => Task.FromResult(new UserInfo()),
                    SignedInUser = new UserInfo()
                };
            var orderRepository = new MockOrderRepository()
                {
                    CreateBasicOrderAsyncDelegate = (userId, shoppingCart, shippingAddress, billingAddress, paymentMethod) =>
                        {
                            // The Address information stored in the order must be the same
                            Assert.IsTrue(compareAddressesFunc(shippingAddress, billingAddress));
                            return Task.FromResult<Order>(new Order());
                        }
                };
            var shoppingCartRepository = new MockShoppingCartRepository()
                {
                    GetShoppingCartAsyncDelegate = () => Task.FromResult(new ShoppingCart(null))
                };
            var navigationService = new MockNavigationService()
                {
                    NavigateDelegate = (a, b) => true
                };

            var target = new CheckoutHubPageViewModel(navigationService, accountService, orderRepository, shoppingCartRepository,
                                            shippingAddressPageViewModel, billingAddressPageViewModel, paymentMethodPageViewModel, null, null);
            target.UseSameAddressAsShipping = true;

            await target.GoNextCommand.Execute();
        }