Пример #1
0
        private void DummyEcommerceMethod3()
        {
            //DocSection:DisplayFreeShippingOffers
            // Initializes the needed services
            ShoppingService shoppingService = new ShoppingService();
            PricingService  pricingService  = new PricingService();

            // Gets the current shopping cart
            ShoppingCart shoppingCart = shoppingService.GetCurrentShoppingCart();

            // Gets the remaining amount for free shipping
            decimal remainingFreeShipping = pricingService.CalculateRemainingAmountForFreeShipping(shoppingCart);
            //EndDocSection:DisplayFreeShippingOffers
        }
Пример #2
0
        public void FreeShipping_RemainingAmountForFreeShipping_FreeShippingAppliedCorrectly(int itemUnits, bool freeShipping)
        {
            var cart = CreateEmptyShoppingCart();

            cart.AddItem(Factory.SKUAvailable.SKUID, itemUnits);
            cart.ShippingOption = Factory.ShippingOptionDefault;

            var service = new PricingService();

            decimal expectedAmount = (decimal)(ShippingDiscount.DiscountItemMinOrderAmount - cart.OriginalCart.TotalItemsPrice);

            expectedAmount = Math.Max(0, expectedAmount);

            decimal remainingAmount     = service.CalculateRemainingAmountForFreeShipping(cart);
            bool    cartHasFreeShipping = cart.Shipping == 0;

            CMSAssert.All(
                () => Assert.AreEqual(freeShipping, cartHasFreeShipping, "Free shipping applied incorrectly"),
                () => Assert.AreEqual(expectedAmount, remainingAmount, "Remaining amount does not match")
                );
        }