public void Run() { Category electronic = new Category(CategoryType.Electronic); Category book = new Category(CategoryType.Books); Product television = new Product("Television", 1000, electronic); Product essentialCSharp = new Product("TestBook", 400, book); _shoppingCart.AddProduct(television, 6); _shoppingCart.AddProduct(essentialCSharp, 5); Coupon coupon = CouponFactory.GenerateCoupon(1000, 20, CouponType.Rate); // I have created 2 discounts type for electronic and book categories. // the expectation is to find the best discount option in the same category. Campaign campaign3 = CampaignFactory.GenerateCampaign(electronic, 5, 50, DiscountType.Rate); Campaign campaign = CampaignFactory.GenerateCampaign(electronic, 2, 20, DiscountType.Rate); Campaign campaign2 = CampaignFactory.GenerateCampaign(book, 2, 5, DiscountType.Amount); Campaign campaign4 = CampaignFactory.GenerateCampaign(book, 4, 15, DiscountType.Amount); Campaign[] campaigns = { campaign2, campaign, campaign3, campaign4 }; _shoppingCart.ApplyCampaigns(campaigns); _shoppingCart.ApplyCoupon(coupon); _shoppingCart.Print(); var deliveryCost = _costCalculator.CalculateCost(50, 2, _shoppingCart); var totalCartAmount = _shoppingCart.GetTotalAmount(); var appliedCampaignDiscount = _shoppingCart.GetCampaignDiscount(); var appliedCouponDiscount = _shoppingCart.GetCouponDiscount(); WriteSummaryText(deliveryCost, totalCartAmount, appliedCampaignDiscount, appliedCouponDiscount); }
public void ApplyDiscount_ShouldApplyDiscount_IfSameCategory(DiscountType discountType, decimal expected) { Category category = new Category(CategoryType.Electronic); Product product = new Product("Television", 1000, category); ShoppingCart shoppingCart = new ShoppingCart(); Campaign campaign = CampaignFactory.GenerateCampaign(category, 4, 20, discountType); shoppingCart.AddProduct(product, 5); campaign.ApplyDiscount(shoppingCart); Assert.Equal(expected, shoppingCart.DiscountedTotalAmount); }
public void ApplyCampaign_ShouldNotDecreaseAmount_IfMinimumItemIsNotSatisfied(DiscountType discountType, decimal expected) { Category category = new Category(CategoryType.Electronic); Product product = new Product("Television", 1000, category); ShoppingCart shoppingCart = new ShoppingCart(); Campaign campaign = CampaignFactory.GenerateCampaign(category, 4, 20, discountType); shoppingCart.AddProduct(product, 2); shoppingCart.ApplyCampaigns(); Assert.Equal(expected, shoppingCart.DiscountedTotalAmount); }
public void ApplyCampaign_ShouldDecreaseAmount_IfMinimumItemConditionSatisfied(DiscountType discountType, decimal expected) { Category category = new Category(CategoryType.Food); Product product = new Product("Apple", 1000, category); ShoppingCart shoppingCart = new ShoppingCart(); Campaign campaign = CampaignFactory.GenerateCampaign(category, 4, 20, discountType); shoppingCart.AddProduct(product, 5); shoppingCart.ApplyCampaigns(campaign); Assert.Equal(expected, shoppingCart.DiscountedTotalAmount); }
public void ApplyDiscount_ShouldNotApplyDiscount_IfNotSameCategory(DiscountType discountType) { Category category = new Category(CategoryType.Electronic); Category otherCategory = new Category(CategoryType.Food); Product product = new Product("Television", 1000, category); ShoppingCart shoppingCart = new ShoppingCart(); Campaign campaign = CampaignFactory.GenerateCampaign(otherCategory, 4, 20, discountType); shoppingCart.AddProduct(product, 5); bool result = campaign.ApplyDiscount(shoppingCart); Assert.False(result); }
public void ApplyCampaign_ShouldNotApplySuccesively_IfSameCampaign(DiscountType discountType, decimal expected) { Category category = new Category(CategoryType.Food); Product product = new Product("Food", 1000, category); ShoppingCart shoppingCart = new ShoppingCart(); Campaign campaign = CampaignFactory.GenerateCampaign(category, 4, 20, discountType); Campaign otherCampaign = CampaignFactory.GenerateCampaign(category, 4, 20, discountType); shoppingCart.AddProduct(product, 5); shoppingCart.ApplyCampaigns(campaign, otherCampaign); Assert.Equal(expected, shoppingCart.DiscountedTotalAmount); }
public void Run() { Category electronic = new Category(CategoryType.Electronic); Category book = new Category(CategoryType.Books); Product television = new Product("Television", 1000, electronic); Product essentialCSharp = new Product("EssentialCSharp", 400, book); _shoppingCart.AddProduct(television, 5); _shoppingCart.AddProduct(essentialCSharp, 1); Coupon coupon = CouponFactory.GenerateCoupon(1000, 20, DiscountType.Rate); Campaign campaign = CampaignFactory.GenerateCampaign(electronic, 2, 10, DiscountType.Amount); _shoppingCart.ApplyCampaigns(campaign); _shoppingCart.Print(); var deliveryCost = _costCalculator.CalculateCost(50, 2, _shoppingCart); var totalCartAmount = _shoppingCart.GetTotalAmount(); WriteClosingText(deliveryCost, totalCartAmount); }