public void CountIsTheNumberOfEntries() { var testContext = new TestContext(); Sku sku1 = testContext.CreateNewSku("A", 100); Sku sku2 = testContext.CreateNewSku("B", 200); Sku sku3 = testContext.CreateNewSku("C", 300); ICart cart = testContext.CartFactory.Create(); cart.Add(new SkuCartEntry() { Sku = sku1, Quantity = 1 }); cart.Add(new SkuCartEntry() { Sku = sku2, Quantity = 2 }); cart.Add(new SkuCartEntry() { Sku = sku3, Quantity = 3 }); Assert.NotEqual(cart.Quantity, cart.Count); Assert.Equal(3, cart.Count); }
public void MergeIsCommutative() { var testContext = new TestContext(); Sku sku1 = testContext.CreateNewSku("A", 100); Sku sku2 = testContext.CreateNewSku("B", 200); Sku sku3 = testContext.CreateNewSku("C", 300); ICart cart1 = testContext.CartFactory.Create(); cart1.Add(sku1); ICart cart2 = testContext.CartFactory.Create(); cart2.Add(sku2); cart2.Add(sku3); ICart mergedCart1 = cart1.Merge(cart2); ICart mergedCart2 = cart2.Merge(cart1); Assert.Equal(mergedCart1.Quantity, mergedCart2.Quantity); Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku1)); Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku2)); Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku3)); Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku1)); Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku2)); Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku3)); }
public void QuantityIsTheSumOfAllEntriesQuantity() { var testContext = new TestContext(); Sku sku1 = testContext.CreateNewSku("A", 100); Sku sku2 = testContext.CreateNewSku("B", 200); Sku sku3 = testContext.CreateNewSku("C", 300); int quantity1 = 1; int quantity2 = 2; int quantity3 = 3; ICart cart = testContext.CartFactory.Create(); cart.Add(sku1); cart.Add(new SkuCartEntry() { Sku = sku2, Quantity = quantity2 }); cart.Add(new SkuCartEntry() { Sku = sku3, Quantity = quantity3 }); Assert.Equal(quantity1 + quantity2 + quantity3, cart.Quantity); }
public static int Add(CartInfo entity, int userId) { if (userId > 0) { return(dal.Add(entity)); } else { return(CartHelper.AddToCart(entity)); } }
public void QuantityWithEntriesHavingNonUnitQuantities() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); cart.Add(new SkuCartEntry() { Sku = testContext.CreateNewSku("A", 100), Quantity = 2 }); cart.Add(testContext.CreateNewSku("B", 200)); Assert.Equal(3, cart.Quantity); }
public void TotalIsTheSumOfAllEntriesPrice() { var testContext = new TestContext(); Sku sku1 = testContext.CreateNewSku("A", 100); Sku sku2 = testContext.CreateNewSku("B", 200); Sku sku3 = testContext.CreateNewSku("C", 300); ICart cart = testContext.CartFactory.Create(); cart.Add(sku1); cart.Add(sku2); cart.Add(sku3); Assert.Equal(testContext.PriceList[sku1] + testContext.PriceList[sku2] + testContext.PriceList[sku3], cart.Total); }
public void WhenAddingASkuWithZeroUnitPriceThenTotalDoesNotChange() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); cart.Add(testContext.CreateNewSku("A", 100)); var total1 = cart.Total; Assert.NotEqual(0, total1); cart.Add(testContext.CreateNewSku("Z", 0)); var total2 = cart.Total; Assert.Equal(total1, total2); }
public void ToStringReturnsANonEmptyStringWhenCartIsNotEmpty() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); cart.Add(testContext.CreateNewSku("A", 100)); Assert.False(string.IsNullOrEmpty(cart.ToString())); }
public void WhenAddingASkuThenQuantityIsUnit() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); cart.Add(testContext.CreateNewSku("A", 100)); Assert.Equal(1, cart.First().Quantity); }
public void WhenSkuIsNotInPricelistThenAddRaisesException() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); decimal registeredSkuPrice = 100; var registeredSku = testContext.CreateNewSku("A", registeredSkuPrice); cart.Add(registeredSku); Assert.Equal(registeredSkuPrice, cart.Total); var unregisteredSku = new Sku("U"); Assert.Throws <StandardCart.SkuNotFoundInPriceListException>(() => { cart.Add(unregisteredSku); // Adding SKU but no price registered in pricelist }); }
public void WhenAddingASkuThenPriceIsSameAsItsUnitPrice() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); Sku sku = testContext.CreateNewSku("A", 100); cart.Add(sku); Assert.Equal(testContext.PriceList[sku], cart.First().Price); }
public void WhenAddingItemsThenTotalChanges() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); Assert.Equal(0, cart.Total); cart.Add(testContext.CreateNewSku("A", 100)); Assert.NotEqual(0, cart.Total); }
public void WhenAddingASkuWithQuantityThenPriceIsUnitByQuantity() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); Sku sku = testContext.CreateNewSku("A", 100); int quantity = 3; cart.Add(sku, quantity); Assert.Equal(testContext.PriceList[sku] * quantity, cart.First().Price); }
public void WhenMergingWithAnEmptyCartThenResultingCartHasSameTotalAsOriginal() { var testContext = new TestContext(); ICart cart = testContext.CartFactory.Create(); cart.Add(testContext.CreateNewSku("A", 100)); ICart mergedCart = cart.Merge(testContext.CartFactory.Create()); Assert.Equal(cart.Quantity, mergedCart.Quantity); }
static void Run(ICart cart, IDeliveryCostCalculator deliveryCostCalculator) { ICategory categoryConsumerElectronics = new Category("Consumer Electronics"); IProduct productAppleWatch = new Product(categoryConsumerElectronics, "Apple Watch", 2000.0); IProduct productAppleMacbookPro = new Product(categoryConsumerElectronics, "Apple Macbook Pro", 10000.0); ICategory categoryToysAndGames = new Category("Toys & Games"); IProduct productLego = new Product(categoryToysAndGames, "Lego Classic Pack", 100.0); cart.Add(productAppleWatch, 2); cart.Add(productAppleMacbookPro, 1); cart.Add(productLego, 10); ICollection <ICampaign> campaigns = new Collection <ICampaign>(); ICollection <ICoupon> coupons = new Collection <ICoupon>(); IRateCampaign inapplicableRateCampaign = new RateCampaign(categoryToysAndGames, "80% discount on Toys & Games category", .5, true, true, 50000.0, 20); IAmountCampaign lowAmountCampaign = new AmountCampaign(categoryConsumerElectronics, "100 TL discount on Toys & Games category", 100, false, false, 0.0, 0); IAmountCampaign bestAmountCampaign = new AmountCampaign(categoryConsumerElectronics, "1400 TL discount on Toys & Games category", 1400, false, true, 0.0, 3); IAmountCoupon inapplicableAmountCoupon = new AmountCoupon(5000, "5000 TL discount coupon", true, true, 50000, 50); IRateCoupon lowRateCoupon = new RateCoupon(.1, "10% discount coupon", false, false, 0.0, 0); IRateCoupon bestRateCoupon = new RateCoupon(.5, "50% discount coupon", true, true, 10000, 13); campaigns.Add(inapplicableRateCampaign); campaigns.Add(lowAmountCampaign); campaigns.Add(bestAmountCampaign); coupons.Add(inapplicableAmountCoupon); coupons.Add(lowRateCoupon); coupons.Add(bestRateCoupon); cart.ApplyDiscounts(campaigns, coupons); cart.DeliveryCost = deliveryCostCalculator.Calculate(cart); var response = cart.Print(); Console.Write(response); }
private void button_add_Click(object sender, EventArgs e) { if (textBox_costcentre.Text == string.Empty) { label_costcentre.ForeColor = System.Drawing.Color.Red; return; } P.Annotation = richTextBox_notice.Text; P.Ammount = trackBar_ammount.Value; P.Costcentre = textBox_costcentre.Text; P.Name = _productname; if (change) { _w.Remove(old); } _w.Add(P); Close(); }
public void AddToCart(IProduct p) { cart.Add(p); }
public void AddComment(Cart c) { cartRepository.Add(c); }