Beispiel #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);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            // Loading Sku and Promotions
            InitializePromotion initializePromotion = new InitializePromotion();
            var skuList    = initializePromotion.InitializeSku();
            var promotions = initializePromotion.InitializePromo();

            // Getting User inputs
            InputModel inputModel = GetInputsFromUser();

            // Applying promotions
            PromotionCalculation calculation = new PromotionCalculation();
            var output = calculation.ApplyPromotions(inputModel, promotions, skuList);

            // Applying normal price for remaining items
            ApplyNormalPrice applyNormal = new ApplyNormalPrice();

            output = applyNormal.ApplyPrice(output, skuList);
            Console.WriteLine($"Price: {output.FinalPrice}");

            Console.ReadLine();
        }
 public void InitializeTest()
 {
     _promotionCalculation = new PromotionCalculation();
     _skuList = new List <SkuItem>
     {
         new SkuItem
         {
             Name = "A", Price = 50
         },
         new SkuItem
         {
             Name = "B", Price = 30
         },
         new SkuItem
         {
             Name = "C", Price = 20
         },
         new SkuItem
         {
             Name = "D", Price = 15
         }
     };
 }
Beispiel #4
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();
        }