Ejemplo n.º 1
0
        public void TestMethod3()
        {
            float expected = 100;
            float actual   = 0;


            Cart cart  = new Cart();
            SKU  skus  = new SKU('A', 50);
            SKU  skus1 = new SKU('B', 30);
            SKU  skus2 = new SKU('C', 20);
            SKU  skus3 = new SKU('D', 15);


            cart.AddItemToCart(new CartItem(skus, 1));
            cart.AddItemToCart(new CartItem(skus1, 1));
            cart.AddItemToCart(new CartItem(skus2, 1));


            PromotionCalculation e  = PromotionCalculation.Instance;
            PromotionType1       a1 = (PromotionType1)e.createInstanceForPromotionType(1);

            a1.setPromotionRules('A', 3, 130);
            a1.setPromotionRules('B', 2, 45);
            e.AddPromotionToList(a1);

            PromotionType2 a2 = (PromotionType2)e.createInstanceForPromotionType(2);

            a2.setPromotionRules('C', 'D', 30);
            e.AddPromotionToList(a2);


            e.applyPromotions(cart);
            actual = cart.CartTotal();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void ParseTestEmptyList()
        {
            float          sum            = 0;
            PromotionType1 PromotionType1 = new PromotionType1();
            var            cost           = PromotionType1.Parse(new List <SKUItems>());

            Assert.AreEqual(sum, cost);
        }
Ejemplo n.º 3
0
        public void ParseTestListVar2()
        {
            float          sum            = 130;
            DummyCart      dummyCart      = new DummyCart();
            var            listItems      = dummyCart.Generate0Promotion3();
            PromotionType1 PromotionType1 = new PromotionType1();
            var            cost           = PromotionType1.Parse(listItems);

            Assert.AreEqual(sum, cost);
            Assert.AreEqual(2, listItems.Count());
        }
        public void CalculateTotalPriceifSkuListHasCount0()
        {
            // Arrange
            PromotionType1 promotionType = new PromotionType1();

            // Act
            double result = promotionType.CalculateTotalPrice(new List <SKU>());

            // Assert
            Assert.AreEqual(0, result);
        }
        public void CalculateTotalPriceifQuantityIsNegative()
        {
            IList <SKU> skulist = new List <SKU>();

            skulist.Add(new SKU
            {
                Quantity = -1
            });
            // Arrange
            PromotionType1 promotionType = new PromotionType1();

            // Act
            double result = promotionType.CalculateTotalPrice(skulist);

            // Assert
            Assert.AreEqual(0, result);
        }
        public void CalculateTotalPriceifListIsNull()
        {
            Exception expectedex = null;
            // Arrange
            PromotionType1 promotionType = new PromotionType1();

            // Act
            try
            {
                var result = promotionType.CalculateTotalPrice(null);
            }
            catch (Exception ex)
            {
                expectedex = ex;
            }

            // Assert

            Assert.IsNotNull(expectedex);
        }
Ejemplo n.º 7
0
        public float ParseCost(List <SKUItems> sKUItems)
        {
            float           totalCost = 0;
            IPromotionLogic runningPromotion;

            runningPromotion = new PromotionType1();
            totalCost       += runningPromotion.Parse(sKUItems);

            runningPromotion = new PromotionType2();
            totalCost       += runningPromotion.Parse(sKUItems);

            runningPromotion = new PromotionType3();
            totalCost       += runningPromotion.Parse(sKUItems);


            foreach (var item in sKUItems)
            {
                totalCost += item.count * item.sKU.GetCost();
            }

            return(totalCost);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            //Inputs of SKU
            Cart cart  = new Cart();
            SKU  skus  = new SKU('A', 50);
            SKU  skus1 = new SKU('B', 30);
            SKU  skus2 = new SKU('C', 20);
            SKU  skus3 = new SKU('D', 15);

            //Add items into the cart and calculate original price of each sku
            cart.AddItemToCart(new CartItem(skus, 3));
            cart.AddItemToCart(new CartItem(skus1, 5));
            cart.AddItemToCart(new CartItem(skus2, 1));
            cart.AddItemToCart(new CartItem(skus3, 1));

            PromotionCalculation e = PromotionCalculation.Instance;
            //Assigning 1 for PromotionType1
            PromotionType1 a1 = (PromotionType1)e.createInstanceForPromotionType(1);

            a1.setPromotionRules('A', 3, 130);
            a1.setPromotionRules('B', 2, 45);
            e.AddPromotionToList(a1);

            //Assigning 2 for PromotionType2
            PromotionType2 a2 = (PromotionType2)e.createInstanceForPromotionType(2);

            a2.setPromotionRules('C', 'D', 30);
            e.AddPromotionToList(a2);

            float total = 0.0f;

            e.applyPromotions(cart);
            total = cart.CartTotal();
            Console.WriteLine("Cart Total :: " + total);
            Console.ReadLine();
        }
Ejemplo n.º 9
0
 internal void set(PromotionType1 promotionType1)
 {
     promotion = promotionType1;
 }