public void Rendering_When_Basket_Is_Not_Empty_Should_Return_View_With_Non_Empty_Model()
        {
            //Arrange
            _transactionLibraryInternal.HasBasket().Returns(true);
            _transactionLibraryInternal.GetBasket().Returns(new PurchaseOrder
            {
                BillingCurrency = new Currency()
                {
                    ISOCode = "EUR"
                }
            });

            //Act
            var result = _controller.Rendering();

            //Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as MiniBasketRenderingViewModel : null;

            Assert.NotNull(viewResult);
            Assert.NotNull(model);
            Assert.True(model.IsEmpty);
            Assert.Equal(0, model.NumberOfItems);
            Assert.Equal(0, model.Total.Value);
            Assert.NotEmpty(model.RefreshUrl);
        }
        public void Rendering_When_BasketModel_IsNotNull_Should_Return_View_With_Non_Empty_Model()
        {
            // Arrange
            _transactionLibraryInternal.GetBasket().Returns(new PurchaseOrder
            {
                BillingCurrency = new Currency
                {
                    ISOCode = "USD"
                }
            });
            _transactionLibraryInternal.HasBasket().Returns(true);


            // Act
            var result = _controller.Rendering();

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as BasketRenderingViewModel : null;

            Assert.NotNull(viewResult);
            Assert.NotNull(model);
            Assert.NotEmpty(model.RefreshUrl);
            Assert.NotEmpty(model.RemoveOrderlineUrl);

            Assert.NotNull(model.OrderTotal);
            Assert.NotNull(model.DiscountTotal);
            Assert.NotNull(model.TaxTotal);
            Assert.NotNull(model.SubTotal);
        }
        public ActionResult Rendering()
        {
            var purchaseOrder          = _transactionLibrary.GetBasket();
            var basketPreviewViewModel = new BasketPreviewViewModel();

            basketPreviewViewModel = MapPurchaseOrderToViewModel(purchaseOrder, basketPreviewViewModel);

            return(View(basketPreviewViewModel));
        }
        public ActionResult Rendering()
        {
            var paymentPickerViewModel = new PaymentPickerViewModel();

            var basket          = _transactionLibrary.GetBasket();
            var shippingCountry = basket.GetShippingAddress(Constants.DefaultShipmentAddressName).Country;

            paymentPickerViewModel.ShippingCountry = shippingCountry.Name;

            var availablePaymentMethods = _transactionLibrary.GetPaymentMethods(shippingCountry);

            var existingPayment = basket.Payments.FirstOrDefault();

            paymentPickerViewModel.SelectedPaymentMethodId = existingPayment != null
                                ? existingPayment.PaymentMethod.PaymentMethodId
                                : -1;

            foreach (var availablePaymentMethod in availablePaymentMethods)
            {
                var     option       = new SelectListItem();
                decimal feePercent   = availablePaymentMethod.FeePercent;
                var     fee          = availablePaymentMethod.GetFeeForCurrency(basket.BillingCurrency);
                var     formattedFee = new Money((fee == null ? 0 : fee.Fee), basket.BillingCurrency.ISOCode);

                option.Text = String.Format(" {0} ({1} + {2}%)", availablePaymentMethod.Name, formattedFee,
                                            feePercent.ToString("0.00"));
                option.Value    = availablePaymentMethod.PaymentMethodId.ToString();
                option.Selected = availablePaymentMethod.PaymentMethodId == paymentPickerViewModel.SelectedPaymentMethodId;

                paymentPickerViewModel.AvailablePaymentMethods.Add(option);
            }

            return(View(paymentPickerViewModel));
        }
        public MiniBasketRefreshViewModel Refresh()
        {
            var viewModel = new MiniBasketRefreshViewModel
            {
                IsEmpty = true
            };

            if (!_transactionLibrary.HasBasket())
            {
                return(viewModel);
            }

            var purchaseOrder = _transactionLibrary.GetBasket();

            var quantity = purchaseOrder.OrderLines.Sum(x => x.Quantity);

            var total = purchaseOrder.OrderTotal.HasValue
                                ? new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency.ISOCode)
                                : new Money(0, purchaseOrder.BillingCurrency.ISOCode);

            viewModel.NumberOfItems = quantity.ToString();
            viewModel.IsEmpty       = quantity == 0;
            viewModel.Total         = total.ToString();

            return(viewModel);
        }
        public ActionResult Rendering()
        {
            var shipmentPickerViewModel = new ShippingPickerViewModel();

            var basket          = _transactionLibrary.GetBasket();
            var shippingCountry = basket.GetAddress(Constants.DefaultShipmentAddressName).Country;

            shipmentPickerViewModel.ShippingCountry = shippingCountry.Name;
            var availableShippingMethods = _transactionLibrary.GetShippingMethods(shippingCountry);

            shipmentPickerViewModel.SelectedShippingMethodId = basket.Shipments.FirstOrDefault() != null
                                ? basket.Shipments.FirstOrDefault().ShippingMethod.ShippingMethodId : -1;

            foreach (var availableShippingMethod in availableShippingMethods)
            {
                var price          = availableShippingMethod.GetPriceForCurrency(basket.BillingCurrency);
                var formattedprice = new Money((price == null ? 0 : price.Price), basket.BillingCurrency.ISOCode);

                shipmentPickerViewModel.AvailableShippingMethods.Add(new SelectListItem()
                {
                    Selected = shipmentPickerViewModel.SelectedShippingMethodId == availableShippingMethod.ShippingMethodId,
                    Text     = String.Format(" {0} ({1})", availableShippingMethod.Name, formattedprice),
                    Value    = availableShippingMethod.ShippingMethodId.ToString()
                });
            }

            return(View(shipmentPickerViewModel));
        }
        public ActionResult Rendering()
        {
            var viewModel = new AddressRenderingViewModel();

            var shippingInformation = _transactionLibrary.GetBasket().GetShippingAddress(Constants.DefaultShipmentAddressName) ?? new OrderAddress();
            var billingInformation  = _transactionLibrary.GetBasket().BillingAddress ?? new OrderAddress();

            viewModel.BillingAddress.FirstName         = billingInformation.FirstName;
            viewModel.BillingAddress.LastName          = billingInformation.LastName;
            viewModel.BillingAddress.EmailAddress      = billingInformation.EmailAddress;
            viewModel.BillingAddress.PhoneNumber       = billingInformation.PhoneNumber;
            viewModel.BillingAddress.MobilePhoneNumber = billingInformation.MobilePhoneNumber;
            viewModel.BillingAddress.Line1             = billingInformation.Line1;
            viewModel.BillingAddress.Line2             = billingInformation.Line2;
            viewModel.BillingAddress.PostalCode        = billingInformation.PostalCode;
            viewModel.BillingAddress.City        = billingInformation.City;
            viewModel.BillingAddress.State       = billingInformation.State;
            viewModel.BillingAddress.Attention   = billingInformation.Attention;
            viewModel.BillingAddress.CompanyName = billingInformation.CompanyName;
            viewModel.BillingAddress.CountryId   = billingInformation.Country != null ? billingInformation.Country.CountryId : -1;

            viewModel.ShippingAddress.FirstName         = shippingInformation.FirstName;
            viewModel.ShippingAddress.LastName          = shippingInformation.LastName;
            viewModel.ShippingAddress.EmailAddress      = shippingInformation.EmailAddress;
            viewModel.ShippingAddress.PhoneNumber       = shippingInformation.PhoneNumber;
            viewModel.ShippingAddress.MobilePhoneNumber = shippingInformation.MobilePhoneNumber;
            viewModel.ShippingAddress.Line1             = shippingInformation.Line1;
            viewModel.ShippingAddress.Line2             = shippingInformation.Line2;
            viewModel.ShippingAddress.PostalCode        = shippingInformation.PostalCode;
            viewModel.ShippingAddress.City        = shippingInformation.City;
            viewModel.ShippingAddress.State       = shippingInformation.State;
            viewModel.ShippingAddress.Attention   = shippingInformation.Attention;
            viewModel.ShippingAddress.CompanyName = shippingInformation.CompanyName;
            viewModel.ShippingAddress.CountryId   = shippingInformation.Country != null ? shippingInformation.Country.CountryId : -1;

            viewModel.AvailableCountries = _countries.ToList().Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.CountryId.ToString()
            }).ToList();

            viewModel.SaveAddressUrl = Url.Action("Save");

            return(View(viewModel));
        }
        public ActionResult Rendering()
        {
            var basketModel = new BasketRenderingViewModel();

            if (!_transactionLibrary.HasBasket())
            {
                return(View(basketModel));
            }

            PurchaseOrder basket = _transactionLibrary.GetBasket();

            foreach (var orderLine in basket.OrderLines)
            {
                var orderLineViewModel = new BasketRenderingViewModel.OrderlineViewModel();

                orderLineViewModel.Quantity    = orderLine.Quantity;
                orderLineViewModel.ProductName = orderLine.ProductName;
                orderLineViewModel.Sku         = orderLine.Sku;
                orderLineViewModel.VariantSku  = orderLine.VariantSku;
                orderLineViewModel.Total       = new Money(orderLine.Total.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.Discount    = orderLine.Discount;
                orderLineViewModel.Tax         = new Money(orderLine.VAT, basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.Price       = new Money(orderLine.Price, basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.ProductUrl  = _urlService.GetUrl(_catalogContext.CurrentCatalog,
                                                                    _catalogLibrary.GetProduct(orderLine.Sku));
                orderLineViewModel.PriceWithDiscount = new Money(orderLine.Price - orderLine.UnitDiscount.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
                orderLineViewModel.OrderLineId       = orderLine.OrderLineId;

                basketModel.OrderLines.Add(orderLineViewModel);
            }

            basketModel.OrderTotal    = new Money(basket.OrderTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.DiscountTotal = new Money(basket.DiscountTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.TaxTotal      = new Money(basket.TaxTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();
            basketModel.SubTotal      = new Money(basket.SubTotal.GetValueOrDefault(), basket.BillingCurrency.ISOCode).ToString();

            basketModel.RefreshUrl         = Url.Action("UpdateBasket");
            basketModel.RemoveOrderlineUrl = Url.Action("RemoveOrderline");

            return(View(basketModel));
        }
        public ActionResult Rendering()
        {
            var basketPreviewViewModel = new BasketPreviewViewModel();

            //used to grap addresses
            var purchaseOrder = _transactionLibrary.GetBasket();

            var cart = GetCart();

            basketPreviewViewModel = MapPurchaseOrderToViewModel(purchaseOrder, cart, basketPreviewViewModel);

            return(View(basketPreviewViewModel));
        }
Exemplo n.º 10
0
        public void Rendering_When_Basket_Has_Shipping_And_Billing_Information_Should_Return_View_With_Non_Empty_Model()
        {
            //Arrange
            _countries.Add(new Country());
            _transactionLibraryInternal.GetBasket().Returns(new PurchaseOrder());

            //Act
            var result = _controller.Rendering();

            //Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as AddressRenderingViewModel : null;

            Assert.NotNull(viewResult);
            Assert.NotNull(model);
            Assert.NotNull(model.BillingAddress);
            Assert.NotNull(model.ShippingAddress);
            Assert.NotEmpty(model.AvailableCountries);
        }
Exemplo n.º 11
0
        public void Rendering_Returns_View_With_Valid_Model()
        {
            // Arrange
            var purchaseOrder = Substitute.For <PurchaseOrder>();

            purchaseOrder.GetShippingAddress(Constants.DefaultShipmentAddressName).Returns(new OrderAddress()
            {
                Country = new Country()
                {
                    Name = "Denmark"
                }
            });

            var paymentMethods = new List <PaymentMethod>();

            paymentMethods.Add(new PaymentMethod()
            {
                Name = "PayPal"
            });

            _transactionLibraryInternal.GetPaymentMethods(
                purchaseOrder.GetShippingAddress(Constants.DefaultShipmentAddressName).Country)
            .ReturnsForAnyArgs(paymentMethods);


            var basket = Substitute.For <PurchaseOrder>();

            basket.BillingCurrency.ISOCode = "EUR";
            _transactionLibraryInternal.GetBasket().Returns(basket);

            // Act
            var result = _controller.Rendering();

            // Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as PaymentPickerViewModel : null;

            Assert.NotNull(model);
            Assert.NotNull(viewResult);
            Assert.NotNull(model.SelectedPaymentMethodId);
            Assert.True(model.AvailablePaymentMethods.Count == 1);
        }
        public ActionResult Rendering()
        {
            var miniBasketViewModel = new MiniBasketRenderingViewModel
            {
                IsEmpty    = true,
                RefreshUrl = Url.Action("Refresh")
            };

            if (!_transactionLibrary.HasBasket())
            {
                return(View(miniBasketViewModel));
            }

            var purchaseOrder = _transactionLibrary.GetBasket();

            miniBasketViewModel.NumberOfItems = purchaseOrder.OrderLines.Sum(x => x.Quantity);
            miniBasketViewModel.IsEmpty       = miniBasketViewModel.NumberOfItems == 0;
            miniBasketViewModel.Total         = purchaseOrder.OrderTotal.HasValue ?
                                                new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency.ISOCode)
                                : new Money(0, purchaseOrder.BillingCurrency.ISOCode);

            return(View(miniBasketViewModel));
        }
        public void Rendering_When_Shipping_Has_New_Model()
        {
            //Arrange
            var purchaseOrder = new PurchaseOrder();
            var orderaddress  = new OrderAddress {
                AddressName = Constants.DefaultShipmentAddressName, Country = new Country()
            };

            purchaseOrder.OrderAddresses.Add(orderaddress);
            purchaseOrder.OrderStatus = new OrderStatus();
            _transactionLibrary.GetBasket().Returns(purchaseOrder);

            //Act
            var result = _controller.Rendering();

            //Assert
            var viewResult = result as ViewResult;
            var model      = viewResult != null ? viewResult.Model as ShippingPickerViewModel : null;

            Assert.NotNull(viewResult);
            Assert.NotNull(model);
            Assert.Equal(-1, model.SelectedShippingMethodId);
        }