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); }
public void ParseTestEmptyList() { float sum = 0; PromotionType2 promotionType2 = new PromotionType2(); var cost = promotionType2.Parse(new List <SKUItems>()); Assert.AreEqual(sum, cost); }
public void ParseTestListVar2() { float sum = 45; DummyCart dummyCart = new DummyCart(); var listItems = dummyCart.Generate0Promotion3(); PromotionType2 promotionType2 = new PromotionType2(); var cost = promotionType2.Parse(listItems); Assert.AreEqual(sum, cost); Assert.AreEqual(1, listItems.Count()); }
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); }
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(); }