Exemple #1
0
        public void Setup()
        {
            promotionEngine = new PromotionEngine();

            this.productCart = new List <OrderDetail>()
            {
                new OrderDetail {
                    Product = 'A', OriginalUnitPrice = 50
                },
                new OrderDetail {
                    Product = 'B', OriginalUnitPrice = 30
                },
                new OrderDetail {
                    Product = 'C', OriginalUnitPrice = 20
                },
                new OrderDetail {
                    Product = 'D', OriginalUnitPrice = 15
                },
            };

            activePromotions = new List <PromoDefinition>()
            {
                new PromoDefinition {
                    PromoType = PromotionTypes.SingleSku, ProductList = new[] { 'A' }, Quantity = 3, Value = 130
                },
                new PromoDefinition {
                    PromoType = PromotionTypes.SingleSku, ProductList = new[] { 'B' }, Quantity = 2, Value = 45
                },
                new PromoDefinition {
                    PromoType = PromotionTypes.DualProducts, ProductList = new[] { 'C', 'D' }, Quantity = 1, Value = 30
                },
            };
        }
Exemple #2
0
    public void TestMethod()
    {
        var stock = new Stock()
        {
            Skus = new List <Sku>()
            {
                new Sku('A', 50), new Sku('B', 30), new Sku('C', 20), new Sku('D', 15)
            }
        };
        var cart = new Cart()
        {
            Skus = new List <CartSku>()
            {
                new CartSku('A', 50, 4), new CartSku('B', 30, 3)
            }
        };
        var promotion1 = new PromotionTypeA(3, new Sku('A', 130));
        var promotion2 = new PromotionTypeA(2, new Sku('B', 45));
        var engine     = new PromotionEngine(stock, new List <IPromotion>()
        {
            promotion1, promotion2
        });

        Assert.AreEqual(engine.applyPromotions(cart), 255);
    }
Exemple #3
0
        public void ApplyPromotionToGetTotalSum_OrdersArgumentIsEmpty_ReturnZero()
        {
            // Arrange
            Dictionary <string, double> pinfo1 = new Dictionary <string, double>();

            pinfo1.Add("A", 3);
            Dictionary <string, double> pinfo2 = new Dictionary <string, double>();

            pinfo2.Add("B", 2);
            Dictionary <string, double> pinfo3 = new Dictionary <string, double>();

            pinfo3.Add("C", 2);

            List <Promotion> promotions = new List <Promotion>()
            {
                new Promotion(1, pinfo1, 130),
                new Promotion(2, pinfo2, 45),
                new Promotion(3, pinfo3, 30)
            };


            // Act
            decimal result = PromotionEngine.ApplyPromotionToGetTotalSum(new List <Order>(), promotions, _productPricePairs);

            // Assert

            Assert.That(result, Is.EqualTo(0));
        }
Exemple #4
0
        public void ScenarioATesting()
        {
            var orders = new List <Order>();

            order = new Order
            {
                Id                       = 1,
                OrderId                  = 1,
                SkuCode                  = "C",
                Qty                      = 1,
                DiscountPercentage       = Constant.ProductCDDiscount,
                ProductMinCountPromotion = Constant.ProductMinCountPromotionForCD,
                PromotionPriceTypeEnum   = EnumHelper.PromotionPriceTypeEnum.Combination,
                UnitPrice                = Constant.ProductCPrice
            };

            orders.Add(order);

            var promotionEngine = new PromotionEngine();

            var expected = promotionEngine.CalculatePromotion(orders);
            var actual   = 100D;

            Assert.AreEqual(actual, expected);
        }
        public void ApplyPromotion()
        {
            //arrange
            IPromotionEngine promotionEngine = new PromotionEngine();
            var cartItems = new List <CartItem> {
                new CartItem()
                {
                    UnitId = "A", UnitCount = 1, UnitPrice = 50
                },
                new CartItem()
                {
                    UnitId = "B", UnitCount = 1, UnitPrice = 30
                },
                new CartItem()
                {
                    UnitId = "C", UnitCount = 1, UnitPrice = 20
                },
            };
            decimal expectedResult = 100;

            //act
            var result = promotionEngine.ApplyPromotion(cartItems);

            //assert
            Assert.AreEqual(expectedResult, result);
        }
        public void VerifyBulkItemPromotionWithTwoItem()
        {
            ActivePromotion activePromotion = new ActivePromotion();

            BulkItemPromotion bulkItemPromotionA = new BulkItemPromotion("A", 3, 130);
            BulkItemPromotion bulkItemPromotionB = new BulkItemPromotion("B", 2, 45);


            activePromotion.AddPromotion(bulkItemPromotionA);
            activePromotion.AddPromotion(bulkItemPromotionB);

            CartItem cartItemA = new CartItem(50, "A", 5);
            CartItem cartItemB = new CartItem(30, "B", 3);


            Cart cart = new Cart();

            cart.AddItem(cartItemA);
            cart.AddItem(cartItemB);

            PromotionEngine promotionEngine = new PromotionEngine(activePromotion);

            int totalCost = promotionEngine.checkout(cart);

            Assert.AreEqual(305, totalCost);
        }
        public void TestMethod()
        {
            PromotionEngine promoEngine = new PromotionEngine();
            int             totalPrice  = promoEngine.GetTotalUnitsPrice();

            Assert.AreEqual(100, totalPrice);
        }
        public void VerifyMultiplePromotion_Scenerio_1()
        {
            ActivePromotion activePromotion = new ActivePromotion();

            BulkItemPromotion    bulkItemPromotionA    = new BulkItemPromotion("A", 3, 130);
            BulkItemPromotion    bulkItemPromotionB    = new BulkItemPromotion("B", 2, 45);
            CombineItemPromotion combineItemPromotionC = new CombineItemPromotion("C", "D", 30);


            activePromotion.AddPromotion(bulkItemPromotionA);
            activePromotion.AddPromotion(bulkItemPromotionB);
            activePromotion.AddPromotion(combineItemPromotionC);


            CartItem cartItemA = new CartItem(50, "A", 3);
            CartItem cartItemB = new CartItem(30, "B", 5);
            CartItem cartItemC = new CartItem(20, "C", 1);
            CartItem cartItemD = new CartItem(15, "D", 1);



            Cart cart = new Cart();

            cart.AddItem(cartItemA);
            cart.AddItem(cartItemB);
            cart.AddItem(cartItemC);
            cart.AddItem(cartItemD);

            PromotionEngine promotionEngine = new PromotionEngine(activePromotion);

            int totalCost = promotionEngine.checkout(cart);

            Assert.AreEqual(280, totalCost);
        }
Exemple #9
0
 public void Setup()
 {
     query           = new Query();
     promotionEngine = new PromotionEngine(query);
     mockQuery       = new Mock <IQuery>();
     dataMocks       = new DataMocks();
 }
Exemple #10
0
        public void ApplyPromotionToGetTotalSum_NoPromotionApplied_ReturnExpectedSum_Example1()
        {
            // Arrange

            List <Order> orders = new List <Order>();

            orders.AddRange(new Order[] {
                new Order()
                {
                    OrderId  = 1,
                    Products = new List <Product>
                    {
                        new Product
                        {
                            Id = "A"
                        },
                        new Product
                        {
                            Id = "B"
                        },
                        new Product
                        {
                            Id = "C"
                        }
                    }
                }
            });

            // Act
            decimal result = PromotionEngine.ApplyPromotionToGetTotalSum(orders, new List <Promotion>(), _productPricePairs);

            // Assert

            Assert.That(result, Is.EqualTo(100));
        }
Exemple #11
0
        public void CalculateTotalOrderAmount_Mock()
        {
            var cartItmes = new List <Cart>()
            {
                new Cart()
                {
                    Quantity = 1,
                    SkuId    = 'A'
                },
                new Cart()
                {
                    Quantity = 1,
                    SkuId    = 'B'
                },
                new Cart()
                {
                    Quantity = 1,
                    SkuId    = 'C'
                }
            };

            mockQuery.Setup(x => x.GetQuantityPromotionRules()).Returns(dataMocks.GetQuantityPromotionRules());
            mockQuery.Setup(x => x.GetSkus()).Returns(dataMocks.GetSkus());
            mockQuery.Setup(x => x.GetComboPromotionRule()).Returns(dataMocks.GetComboPromotionRule());
            mockQuery.Setup(x => x.GetSkuPromotionPairs()).Returns(dataMocks.GetSkuPromotionPairs());
            var result = new PromotionEngine(mockQuery.Object).CalculateTotalOrderAmount(cartItmes);

            Assert.AreEqual(100, result);
        }
Exemple #12
0
        public void ScenarioB()
        {
            promotionEngine = new PromotionEngine();
            _cart           = new Cart();

            _cart.Items.Add(new Sku()
            {
                Code = "A", Name = "A", Price = 50
            });
            _cart.Items.Add(new Sku()
            {
                Code = "A", Name = "A", Price = 50
            });
            _cart.Items.Add(new Sku()
            {
                Code = "A", Name = "A", Price = 50
            });
            _cart.Items.Add(new Sku()
            {
                Code = "A", Name = "A", Price = 50
            });
            _cart.Items.Add(new Sku()
            {
                Code = "A", Name = "A", Price = 50
            });

            _cart.Items.Add(new Sku()
            {
                Code = "B", Name = "B", Price = 30
            });
            _cart.Items.Add(new Sku()
            {
                Code = "B", Name = "B", Price = 30
            });
            _cart.Items.Add(new Sku()
            {
                Code = "B", Name = "B", Price = 30
            });
            _cart.Items.Add(new Sku()
            {
                Code = "B", Name = "B", Price = 30
            });
            _cart.Items.Add(new Sku()
            {
                Code = "B", Name = "B", Price = 30
            });

            _cart.Items.Add(new Sku()
            {
                Code = "C", Name = "C", Price = 20
            });

            Assert.AreEqual(370, promotionEngine.GetOrderValue(_cart));
        }
Exemple #13
0
        public void TestCalculateCost3(int output)
        {
            foreach (var item in test3)
            {
                OrderDetails.AddOrders(item.Key, item.Value);
            }

            var promotionEngine = new PromotionEngine();
            var cost            = promotionEngine.CalculateCost(OrderDetails);

            Assert.AreEqual(cost, output);
        }
        //scenation A - 3 * A = 130 ;5 * B = 45 + 45 + 30 ;1 * C ;1 * D = 30
        public void TestPromoCodeScenarioC()
        {
            decimal totalBillAmount = 0;

            promotionEngineObj = new PromotionEngine();
            var inputData         = CartData.PreparePromotionData2();
            var promotionCodeData = CartData.PreparePromotionCodeData();

            totalBillAmount = promotionEngineObj.ApplyPromotionCode(inputData.CartItems, promotionCodeData);

            Assert.AreEqual(280, totalBillAmount);
        }
Exemple #15
0
        public void ComputeBillScenarioCTest()
        {
            Item objItemA = new Item()
            {
                ItemId = 1, ItemName = "A", Description = "Test Item A", ItemPrice = 50
            };
            Item objItemB = new Item()
            {
                ItemId = 2, ItemName = "B", Description = "Test Item B", ItemPrice = 30
            };
            Item objItemC = new Item()
            {
                ItemId = 3, ItemName = "C", Description = "Test Item C", ItemPrice = 20
            };
            Item objItemD = new Item()
            {
                ItemId = 4, ItemName = "D", Description = "Test Item D", ItemPrice = 15
            };

            KartItem objKartItem1 = new KartItem(objItemA, 3);
            KartItem objKartItem2 = new KartItem(objItemB, 5);
            KartItem objKartItem3 = new KartItem(objItemC, 1);
            KartItem objKartItem4 = new KartItem(objItemD, 1);

            List <KartItem> objPurchasedItemList = new List <KartItem>();

            objPurchasedItemList.Add(objKartItem1);
            objPurchasedItemList.Add(objKartItem2);
            objPurchasedItemList.Add(objKartItem3);
            objPurchasedItemList.Add(objKartItem4);

            Kart objKart = new Kart(objPurchasedItemList);

            //Now setup the Promotions Rules
            List <KeyValuePair <Item, int> > kvpList = new List <KeyValuePair <Item, int> >();

            kvpList.Add(new KeyValuePair <Item, int>(objItemC, 1));
            kvpList.Add(new KeyValuePair <Item, int>(objItemD, 1));

            IPromotionRule objRuleA = new BuyNQtyAtFixedPrice("Promotion A", 130, 3, "A");
            IPromotionRule objRuleB = new BuyNQtyAtFixedPrice("Promotion B", 45, 2, "B");
            IPromotionRule objRuleC = new BuyNItemsAtFixedPrice("Combination C & D", 30, kvpList);

            //Creating instance of RuleEngine
            IPromotion objPromotion = new PromotionEngine();

            objPromotion.ApplyPromotion(objRuleA, objKart, true);
            objPromotion.ApplyPromotion(objRuleB, objKart, true);
            objPromotion.ApplyPromotion(objRuleC, objKart);

            Assert.AreEqual(280, objKart.CalculateAmountPayable());
        }
Exemple #16
0
        public void ScenarioCTest()
        {
            decimal totalCartAmount = 0.0M, totalPromotionDiscount = 0.0M;

            AddProduct();
            AddPromotionTypes();
            AddScenarioCProductToCart();
            PromotionEngine promotionEngine = new PromotionEngine(_promotionTypes);

            totalCartAmount        = _customerCart.GetTotalCartAmount();
            totalPromotionDiscount = promotionEngine.GetPromotionDiscount(_customerCart.CustomerItems);
            Assert.AreEqual(280, totalCartAmount - totalPromotionDiscount);
        }
Exemple #17
0
        public void ScenarioFutureTest()
        {
            //define test input and output values
            decimal expectedResult = 500;
            IEnumerable <CartSKU>   purchasedSKUs    = GetPurchasedSKUs(ScenarioFuture);
            IEnumerable <Promotion> activePromotions = GetActivePromotions();

            PromotionEngine systemUnderTest = new PromotionEngine();
            decimal         actualResult    = systemUnderTest.CalculateTotal(purchasedSKUs, activePromotions);

            //verify the result
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void TestCaseCart3()
        {
            //A = 3, B = 5, C = 1, D = 1
            PromotionEngine promotionEngine = new PromotionEngine();

            FillCartList3(promotionEngine);
            decimal orginalPrice = 335m, expectedPrice = 280m;

            (decimal actualPrice, decimal promoPrice) = promotionEngine.PromoCalculator();

            Assert.AreEqual(orginalPrice, actualPrice);
            Assert.AreEqual(expectedPrice, promoPrice);
        }
 // ... ToDo: "into the course"
 public NodeController(
     IContentLoader contentLoader
     , UrlResolver urlResolver
     , AssetUrlResolver assetUrlResolver
     , ThumbnailUrlResolver thumbnailUrlResolver
     , AssetUrlConventions assetUrlConvensions // Adv.
     , ICurrentMarket currentMarket
     , PromotionEngine promoEngine
     )
     : base(contentLoader, urlResolver, assetUrlResolver, thumbnailUrlResolver, currentMarket)
 {
     _promoEngine = promoEngine;
     _currMarket  = currentMarket;
 }
        public void EmptySkusTest()
        {
            //Arrange
            IList <OrderLine> orderLines = PromotionEngine.GetOrderLines("D");
            PromotionEngine   engine     = new PromotionEngine(orderLines);

            //Act
            decimal actualTotal = engine.Calculate();

            //Assert
            decimal expectedTotal = 0;

            Assert.AreEqual(expectedTotal, actualTotal);
        }
Exemple #21
0
        public void ApplyPromotionToGetTotalSum_ProductPriceDictionaryIsEmpty_ThrowArgumentNullException()
        {
            // Arrange
            Dictionary <string, double> pinfo1 = new Dictionary <string, double>();

            pinfo1.Add("A", 3);
            Dictionary <string, double> pinfo2 = new Dictionary <string, double>();

            pinfo2.Add("B", 2);
            Dictionary <string, double> pinfo3 = new Dictionary <string, double>();

            pinfo3.Add("C", 2);

            List <Promotion> promotions = new List <Promotion>()
            {
                new Promotion(1, pinfo1, 130),
                new Promotion(2, pinfo2, 45),
                new Promotion(3, pinfo3, 30)
            };

            List <Order> orders = new List <Order>();

            orders.AddRange(new Order[] {
                new Order()
                {
                    OrderId  = 1,
                    Products = new List <Product>
                    {
                        new Product
                        {
                            Id = "A"
                        },
                        new Product
                        {
                            Id = "B"
                        },
                        new Product
                        {
                            Id = "C"
                        }
                    }
                }
            });



            // Assert

            Assert.That(() => PromotionEngine.ApplyPromotionToGetTotalSum(orders, promotions, new Dictionary <string, int>()), Throws.ArgumentNullException);
        }
Exemple #22
0
        public void PromotionEngineTest_CalculateWrongTotal()
        {
            //Arrange
            int actualTotal = 270;
            Dictionary <string, int> userCart = new Dictionary <string, int>();

            userCart.Add("A", 5);
            PromotionEngine pe = new PromotionEngine();

            //Act
            int total = pe.CalculateTotalAfterPromotions(userCart);

            //Assert
            Assert.AreEqual(actualTotal, total, 0, "Wrong Total");
        }
 public void FillCartList2(PromotionEngine promotionEngine)
 {
     promotionEngine.CartList = new List <CartItem>();
     promotionEngine.CartList.Add(new CartItem()
     {
         SKU = 'A', Quantity = 5
     });
     promotionEngine.CartList.Add(new CartItem()
     {
         SKU = 'B', Quantity = 5
     });
     promotionEngine.CartList.Add(new CartItem()
     {
         SKU = 'C', Quantity = 1
     });
 }
Exemple #24
0
        static void Main(string[] args)
        {
            Dictionary <string, int> CustomerOrders = new Dictionary <string, int>();
            string input;

            Console.WriteLine("Enter the product and quanity by comma seperated");
            for (int i = 0; i < 4; i++)
            {
                input = Console.ReadLine();
                string[] words = input.Split(',');
                CustomerOrders.Add(words[0].ToUpper(), Convert.ToInt32(words[1]));
            }
            PromotionEngine pe = new PromotionEngine();

            Console.WriteLine(pe.CalculateTotalAfterPromotions(CustomerOrders));
            Console.ReadKey();
        }
Exemple #25
0
        public void PromotionEngineTest_CalculateTotal()
        {
            //Arrange
            int actualTotal = 205;
            Dictionary <string, int> userCart = new Dictionary <string, int>();

            userCart.Add("A", 3);
            userCart.Add("B", 2);
            userCart.Add("C", 1);
            userCart.Add("D", 1);
            PromotionEngine pe = new PromotionEngine();

            //Act
            int total = pe.CalculateTotalAfterPromotions(userCart);

            //Assert
            Assert.AreEqual(actualTotal, total, 0, "Correct Total");
        }
        public void VerifyBulkItemPromotionWithOneItem()
        {
            ActivePromotion activePromotion = new ActivePromotion();

            BulkItemPromotion bulkItemPromotion = new BulkItemPromotion("A", 3, 130);


            activePromotion.AddPromotion(bulkItemPromotion);

            CartItem cartItem = new CartItem(50, "A", 5);

            Cart cart = new Cart();

            cart.AddItem(cartItem);

            PromotionEngine promotionEngine = new PromotionEngine(activePromotion);

            int totalCost = promotionEngine.checkout(cart);

            Assert.AreEqual(230, totalCost);
        }
Exemple #27
0
        public void ComputeBillScenarioBTest()
        {
            Item objItemA = new Item()
            {
                ItemId = 1, ItemName = "A", Description = "Test Item A", ItemPrice = 50
            };
            Item objItemB = new Item()
            {
                ItemId = 2, ItemName = "B", Description = "Test Item B", ItemPrice = 30
            };
            Item objItemC = new Item()
            {
                ItemId = 3, ItemName = "C", Description = "Test Item C", ItemPrice = 20
            };

            KartItem objKartItem1 = new KartItem(objItemA, 5);
            KartItem objKartItem2 = new KartItem(objItemB, 5);
            KartItem objKartItem3 = new KartItem(objItemC, 1);

            List <KartItem> objPurchasedItemList = new List <KartItem>();

            objPurchasedItemList.Add(objKartItem1);
            objPurchasedItemList.Add(objKartItem2);
            objPurchasedItemList.Add(objKartItem3);

            Kart objKart = new Kart(objPurchasedItemList);

            IPromotionRule objRuleA = new BuyNQtyAtFixedPrice("Promotion A", 130, 3, "A");
            IPromotionRule objRuleB = new BuyNQtyAtFixedPrice("Promotion B", 45, 2, "B");

            IPromotion objPromotion = new PromotionEngine();

            objPromotion.ApplyPromotion(objRuleA, objKart, true);
            objPromotion.ApplyPromotion(objRuleB, objKart, true);

            Assert.AreEqual(370, objKart.CalculateAmountPayable());
        }