private static Cart LoadCart() { // create the cart Cart cart = new Cart(new Member("Rohan")); // add items to the cart GenericProduct Trouser = new GenericProduct("Trouser", 110m); cart.AddLineItem(Trouser, 5); EventItem race = new EventItem("Ticket", 90m); cart.AddLineItem(race, 1); //Add Discount //This would generally be Dynamic from rule engine. Discount buyXGetY = new BuyXGetYFree("Buy 2 Trousers get 1 Trouser free", new List <Product> { Trouser }, 2, 1); buyXGetY.CanBeUsedInJuntionWithOtherDiscounts = false; buyXGetY.SupercedesOtherDiscounts = true; cart.AddDiscount(buyXGetY); return(cart); }
public void TestBuy2GetOneFree() { //Product Amount = $100 //Discount Applied is Buy 2 Get One Free //Total Quantity in Cart is 5 //Expected Discount should be $200 Cart cart = new Cart(new Member("Rohan")); // add items to the cart GenericProduct Trouser = new GenericProduct("Trouser", 100m); cart.AddLineItem(Trouser, 5); EventItem race = new EventItem("Ticket", 70m); cart.AddLineItem(race, 1); //Add Discount //This would generally be Dynamic from rule engine. Discount buyXGetY = new BuyXGetYFree("Buy 2 Trousers get 1 Trouser free", new List <Product> { Trouser }, 2, 1); buyXGetY.CanBeUsedInJuntionWithOtherDiscounts = false; buyXGetY.SupercedesOtherDiscounts = true; cart.AddDiscount(buyXGetY); Order order = ProcessCartToOrder(cart); LineItem item = order.LineItems.FirstOrDefault(x => x.Product.Name == "Trouser"); Assert.IsTrue(item.Subtotal == 300m); Assert.IsTrue(item.DiscountAmount == 200m); }
public void CalculateDiscount_Test7() { //Arrange var basket = new Basket(); basket.AddProduct(TestData.ProductOne); basket.AddProduct(TestData.ProductFour); var discountRule = new BuyXGetYFree(TestData.ProductThree, 2, TestData.ProductFour, 1); var expectedResult = 0; //Action var result = discountRule.CalculateDiscount(basket); //Asset Assert.AreEqual(expectedResult, result); }
public void Can_Add_Items_To_An_Order() { // create the cart Order order = new Order(new Member("Chev")); // add items to the cart Product hat = new Product("Cap", 110m); order.AddLineItem(hat, 5); Product race = new Product("Ticket", 90m); order.AddLineItem(race, 1); // add discounts Discount percentageOff = new PercentageOffDiscount("10% off all items", 0.10m); percentageOff.CanBeUsedInJuntionWithOtherDiscounts = false; order.AddDiscount(percentageOff); Discount spendXgetY = new SpendMoreThanXGetYDiscount("Spend more than R100 get 10% off", 100m, 0.1m); spendXgetY.SupercedesOtherDiscounts = true; order.AddDiscount(spendXgetY); Discount buyXGetY = new BuyXGetYFree("Buy 4 hats get 2 hat free", new List <Product> { hat }, 4, 2); buyXGetY.CanBeUsedInJuntionWithOtherDiscounts = false; buyXGetY.SupercedesOtherDiscounts = true; order.AddDiscount(buyXGetY); // display the cart contents foreach (LineItem lineItem in order.LineItems) { Console.WriteLine("Product: {0}\t Price: {1:c}\t Quantity: {2} \t Subtotal: {4:c} \t Discount: {3:c} \t| Discounts Applied: {5}", lineItem.Product.Name, lineItem.Product.Price, lineItem.Quantity, lineItem.DiscountAmount, lineItem.Subtotal, lineItem.Discounts.Count); } }
private static Cart LoadCart() { // create the cart Cart cart = new Cart(new Member("Chev")); // add items to the cart Product hat = new Product("Cap", 110m); cart.AddLineItem(hat, 5); var race = new Product("Ticket", 90m); cart.AddLineItem(race, 1); // add discounts Discount percentageOff = new PercentageOffDiscount("10% off all items", 0.10m); percentageOff.CanBeUsedInJuntionWithOtherDiscounts = false; cart.AddDiscount(percentageOff); Discount spendXgetY = new SpendMoreThanXGetYDiscount("Spend more than R100 get 10% off", 100m, 0.1m); spendXgetY.SupercedesOtherDiscounts = true; cart.AddDiscount(spendXgetY); Discount buyXGetY = new BuyXGetYFree("Buy 4 hats get 2 hat free", new List <Product> { hat }, 4, 2) { CanBeUsedInJuntionWithOtherDiscounts = false, SupercedesOtherDiscounts = true }; cart.AddDiscount(buyXGetY); return(cart); }
public PartialViewResult Fields(BuyXGetYFree buyXGetY) { return(PartialView(buyXGetY)); }