protected void btnAction_Command(object sender, CommandEventArgs e) { if (e.CommandName == "Save") { if (Page.IsValid) { Campaign campaign = new Campaign(); campaign.Name = txtName.Text; campaign.Description = txtDesc.Text; campaign.Active = cbActive.Checked; campaign.Paused = cbPaused.Checked; campaign.CampaignType = ddlType.SelectedValue; campaign.WinningVersion = new CSBusiness.Version(); if (ddlWinningVersion.SelectedIndex > 0) { campaign.WinningVersion.VersionId = Convert.ToInt32(ddlWinningVersion.SelectedValue); } if (cId > 0) { campaign.CampaignId = cId; } AddVersions(ref campaign); CampaignFactory.SaveCampaign(campaign); lblSuccess.Visible = true; CampaignManager.InitializeCampaigns(); } } if (cId == 0) { Response.Redirect("CampaignList.aspx"); } }
protected void dlVersionList_ItemCommand(object sender, DataListCommandEventArgs e) { int campaignId = (int)dlCampaignList.DataKeys[e.Item.ItemIndex]; CampaignFactory.RemoveCampaign(campaignId); BindCampaign(); }
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); }
static void Main(string[] args) { Category category = new Category("Food"); Product banana = new Product("Banana", 10, category); Product apple = new Product("Apple", 15, category); Category electronicCategory = new Category("Electronic"); Product samsung = new Product("Samsung", 200, electronicCategory); Product nokia = new Product("Nokia", 100, electronicCategory); CampaignFactory campaignFactory = new CampaignFactory(); AmountCampaign campaignFood = campaignFactory.ProduceCampaign(category, 25, 5, DiscountType.Amount) as AmountCampaign; AmountCampaign campaignElectronic = campaignFactory.ProduceCampaign(electronicCategory, 50, 1, DiscountType.Amount) as AmountCampaign; DeliveryCostCalculator calculator = new DeliveryCostCalculator(1, 2, 2.99d); Cart shoppingCart = new Cart(calculator); shoppingCart.AddItem(banana, 8); shoppingCart.AddItem(apple, 5); shoppingCart.AddItem(samsung, 1); shoppingCart.AddItem(nokia, 2); shoppingCart.ApplyDiscounts(campaignFood, campaignElectronic); shoppingCart.Print(); }
public void ProduceCampaign_WhenCalledWithNullCategory_ThrowsException() { //Arrange CampaignFactory factory = new CampaignFactory(); //Act && Assert var exception = Assert.Throws <ArgumentNullException>(() => factory.ProduceCampaign(null, 50, 10, DiscountType.Rate)); Assert.Equal("Value cannot be null. (Parameter 'category')", exception.Message); }
public void AddCampaign_WhenNewCampaignCreated_AddThatCampaignToCategory() { //Arrange & Act Category foodCategory = new Category("Food"); CampaignFactory campaignFactory = new CampaignFactory(); AmountCampaign campaign = campaignFactory.ProduceCampaign(foodCategory, 10, 2, Business.DiscountType.Amount) as AmountCampaign; //Assert Assert.Contains(campaign, foodCategory.campaigns); }
public void ProduceCampaign_WhenCalledForRateCampaign_ReturnsRateCampaignObject() { //Arrange Category category = new Category("Food"); CampaignFactory factory = new CampaignFactory(); //Act ICampaign coupon = factory.ProduceCampaign(category, 50, 10, DiscountType.Rate); //Assert Assert.IsType <RateCampaign>(coupon); }
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_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_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 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 Run() { #region Get Delivery cost values from config. var costPerDelivery = _config.GetValue <double>("Delivery:CostPerDelivery"); var costPerProduct = _config.GetValue <double>("Delivery:CostPerProduct"); var fixedCost = _config.GetValue <double>("Delivery:FixedCost"); #endregion #region Category and product creation var computerCategory = new Category.Category("Computer"); var phoneCategory = new Category.Category("Phone"); var ipone = new Iphone(7500, phoneCategory); var macbook = new Macbook(18500, computerCategory); #endregion #region Shopping cart creation IShoppingCart cart = new Cart.ShoppingCart(new DeliveryCostCalculator(costPerDelivery, costPerProduct, fixedCost)); cart.AddItem(ipone, 10); cart.AddItem(macbook, 5); #endregion #region Get campaign type from CampaignFactory with CampaignTypes enum. CampaignFactory campaignFactory = new CampaignFactory(); var campaign2 = campaignFactory.Get(computerCategory, 1500, 1, CampaignTypes.Amount); var campaign3 = campaignFactory.Get(phoneCategory, 2, 1, CampaignTypes.Rate); #endregion #region Apply first campaign discount then coupon cart.ApplyDiscounts(campaign2, campaign3); CouponFactory couponFactory = new CouponFactory(); var coupon = couponFactory.Get(500, 150, CouponTypes.Amount); cart.ApplyCoupon(coupon); #endregion Console.WriteLine(cart.Print()); Console.ReadLine(); }
public void GetDiscount_WhenCalledForAmountCampaign_ReturnsPercentageOfDiscount() { //Arrange double discountRate = 10; double totalPrice = 200; double expectedDiscount = 20; Category category = new Category("Food"); CampaignFactory factory = new CampaignFactory(); RateCampaign campaign = factory.ProduceCampaign(category, discountRate, 3, DiscountType.Rate) as RateCampaign; //Act double discount = campaign.GetDiscount(totalPrice); //Assert Assert.Equal(expectedDiscount, discount); }
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); }
public CampaignTest() { campaignFactory = new CampaignFactory(); electronicCategory = new Category.Category("Electronic"); }
private void BindCampaign() { dlCampaignList.DataSource = CampaignFactory.GetAllCampaigns(); dlCampaignList.DataKeyField = "CampaignId"; dlCampaignList.DataBind(); }