Exemplo n.º 1
0
        public void Can_Add_Items_To_An_Order()
        {
            // create the cart
            Order order = new Order(new Member("Chev"));

            // add items to the cart
            Product hat = new Product("Cap", 110m);

            order.AddLineItem(hat, 5);

            Product race = new Product("Ticket", 90m);

            order.AddLineItem(race, 1);

            // add discounts
            Discount percentageOff = new PercentageOffDiscount("10% off all items", 0.10m);

            percentageOff.CanBeUsedInJuntionWithOtherDiscounts = false;
            order.AddDiscount(percentageOff);

            Discount spendXgetY = new SpendMoreThanXGetYDiscount("Spend more than R100 get 10% off", 100m, 0.1m);

            spendXgetY.SupercedesOtherDiscounts = true;
            order.AddDiscount(spendXgetY);

            Discount buyXGetY = new BuyXGetYFree("Buy 4 hats get 2 hat free", new List <Product> {
                hat
            }, 4, 2);

            buyXGetY.CanBeUsedInJuntionWithOtherDiscounts = false;
            buyXGetY.SupercedesOtherDiscounts             = true;
            order.AddDiscount(buyXGetY);

            // display the cart contents
            foreach (LineItem lineItem in order.LineItems)
            {
                Console.WriteLine("Product: {0}\t Price: {1:c}\t Quantity: {2} \t Subtotal: {4:c} \t Discount: {3:c} \t| Discounts Applied: {5}", lineItem.Product.Name, lineItem.Product.Price, lineItem.Quantity, lineItem.DiscountAmount, lineItem.Subtotal, lineItem.Discounts.Count);
            }
        }
Exemplo n.º 2
0
        private static Cart LoadCart()
        {
            // create the cart
            Cart cart = new Cart(new Member("Chev"));

            // add items to the cart
            Product hat = new Product("Cap", 110m);

            cart.AddLineItem(hat, 5);

            var race = new Product("Ticket", 90m);

            cart.AddLineItem(race, 1);

            // add discounts
            Discount percentageOff = new PercentageOffDiscount("10% off all items", 0.10m);

            percentageOff.CanBeUsedInJuntionWithOtherDiscounts = false;
            cart.AddDiscount(percentageOff);

            Discount spendXgetY = new SpendMoreThanXGetYDiscount("Spend more than R100 get 10% off", 100m, 0.1m);

            spendXgetY.SupercedesOtherDiscounts = true;
            cart.AddDiscount(spendXgetY);

            Discount buyXGetY = new BuyXGetYFree("Buy 4 hats get 2 hat free", new List <Product> {
                hat
            }, 4, 2)
            {
                CanBeUsedInJuntionWithOtherDiscounts = false,
                SupercedesOtherDiscounts             = true
            };

            cart.AddDiscount(buyXGetY);

            return(cart);
        }