Example #1
0
        public void Get_Checkout_Total_Cost_WithDiscount()
        {//check the cost for the checkout items
            //some of the items with offer
            IList <KeyValuePair <int, OfferFlags> > lstProductOffer;

            lstProductOffer = new List <KeyValuePair <int, OfferFlags> >()
            {
                new KeyValuePair <int, OfferFlags>(1, OfferFlags.BuyOneGetOneFree),
                new KeyValuePair <int, OfferFlags>(2, OfferFlags.ThreeForTwo)
            };

            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 2
            };
            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 3, ProductId = 1, Quantity = 1
            };
            cart.AddItem(item);
            var tot = cart.GetTotalCost(lstProductOffer);

            Assert.AreEqual(1.1M, tot);
        }
Example #2
0
        private static void ShoppingCart()
        {
            IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>();
            IList <IProduct>      _lstProduct   = new List <IProduct>();

            //set up store products
            _lstProduct = SetupProducts();

            //check out items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);

            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 1
            };
            cart.AddItem(item);

            //get the cost for the checkout items
            var tot = cart.GetTotalCost();

            Console.WriteLine($"Total number of the items checked out and the cost: {cart.GetTotalItems().Count}  {tot.ToString("C")}.");
        }
Example #3
0
        public void Get_Checkout_Total_Cost()
        {//check the cost for the checkout items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 2
            };
            cart.AddItem(item);
            var tot = cart.GetTotalCost();

            Assert.AreEqual(1.1M, tot);
        }
Example #4
0
        private static void ShoppingCartWithOffer()
        {
            IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>();
            IList <IProduct>      _lstProduct   = new List <IProduct>();

            //set up store products
            _lstProduct = SetupProducts();

            //set up offers
            IList <KeyValuePair <int, OfferFlags> > lstProductOffer;

            lstProductOffer = new List <KeyValuePair <int, OfferFlags> >()
            {
                new KeyValuePair <int, OfferFlags>(1, OfferFlags.BuyOneGetOneFree),
                new KeyValuePair <int, OfferFlags>(2, OfferFlags.ThreeForTwo)
            };

            //check out items
            var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct);
            var item = new CheckoutItem()
            {
                CheckoutItemId = 1, ProductId = 1, Quantity = 1
            };

            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 2, ProductId = 2, Quantity = 1
            };
            cart.AddItem(item);
            item = new CheckoutItem()
            {
                CheckoutItemId = 3, ProductId = 1, Quantity = 1
            };
            cart.AddItem(item);

            //get the cost for the checkout items with the offers
            var tot = cart.GetTotalCost(lstProductOffer);

            Console.WriteLine($"Total number of the items checked out with offers and the cost: {cart.GetTotalItems().Count}  {tot.ToString("C")}.");
        }