public void When_additional_item_discount_is_added() { var sut = new ProductCatalog(); sut.AddAdditionalItemDiscount("apple", 3, 2, 100); Assert.That(sut.QuantityDiscounts.Count(), Is.EqualTo(0)); Assert.That(sut.AdditionalItemDiscounts.Count(), Is.EqualTo(1)); Assert.True(sut.AdditionalItemDiscounts.First(p => p.Barcode == "apple").QuantityFullPrice == 3); Assert.True(sut.AdditionalItemDiscounts.First(p => p.Barcode == "apple").QuantityDiscounted == 2.00); }
public void Begin() { if (!_cartData.Any()) { _consoleWriter.WriteLine("Error cart is empty"); return; } var productCatalog = new ProductCatalog(); foreach (var productCatalogLine in _productCatalogData) { var parts = productCatalogLine.Split(','); if (parts[0] == "PRODUCT") { var barcode = parts[1].Trim(); var price = Decimal.Parse(parts[2]); productCatalog.AddProduct(barcode, price); } else if (parts[0] == "QUANTITY_DISCOUNT") { var barcode = parts[1].Trim(); var quantity = Convert.ToInt32(parts[2]); var discountPrice = Convert.ToDecimal(parts[3]); productCatalog.AddQuantityDiscount(barcode, quantity, discountPrice); } else if (parts[0] == "ADDITIONAL_ITEM_DISCOUNT") { var barcode = parts[1].Trim(); var quantity = Convert.ToInt32(parts[2]); var quantityDiscounted = Convert.ToInt32(parts[3]); var dicountPercentage = Convert.ToDouble(parts[4]); productCatalog.AddAdditionalItemDiscount(barcode, quantity, quantityDiscounted, dicountPercentage); } } var promotionalDiscountRules = new List <IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog) }; var transaction = new CheckoutTransaction(productCatalog, new Promotions(promotionalDiscountRules)); foreach (var cartLine in _cartData) { transaction.AddItem(cartLine); } var reportGenerator = new ReceiptGenerator(); var receipt = reportGenerator.Generate(transaction); _consoleWriter.WriteLine(receipt); }
public void When_constructed_with_applicable_additional_item_discount() { var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var sut = new Bill(new List<string>() { "apple", "banana", "apple", "apple", "apple", "apple" }, productCatalog, new Promotions(new List<IPromotionalDiscountRule>() {new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog)})); Assert.That(sut.Total, Is.EqualTo(3.25m)); Assert.That(sut.LineItems.Count(), Is.EqualTo(2)); Assert.That(sut.LineItems.ElementAt(0).PricePerUnit, Is.EqualTo(0.75m)); Assert.That(sut.LineItems.ElementAt(0).DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50")); }
public void When_promotion_applies() { var productCatalog = new ProductCatalog(); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); productCatalog.AddProduct("apple", 0.75m); var sut = new AdditionalItemDiscountRule(productCatalog); var promotions = new Promotions(new List<IPromotionalDiscountRule>() { sut }); var lineItem = new LineItem("apple", 7, productCatalog, promotions); var actual = sut.PromotionApplies(lineItem); Assert.That(actual, Is.True); }
public void When_calculating_rule() { var productCatalog = new ProductCatalog(); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); productCatalog.AddProduct("apple", 0.75m); var sut = new AdditionalItemDiscountRule(productCatalog); var promotions = new Promotions(new List<IPromotionalDiscountRule>() { sut }); var lineItem = new LineItem("apple", 7, productCatalog, promotions); var actual = sut.Calculate(lineItem); Assert.That(actual.DiscountedSubTotal, Is.EqualTo(3m)); Assert.That(actual.DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $3.00, Savings $2.25")); }
public void When_constructed_with_additional_item_discount() { var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var sut = new LineItem("apple", 5, productCatalog, new Promotions(new List<IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog)})); Assert.That(sut.Barcode, Is.EqualTo("apple")); Assert.That(sut.Quantity, Is.EqualTo(5)); Assert.That(sut.PricePerUnit, Is.EqualTo(0.75m)); Assert.That(sut.SubTotal, Is.EqualTo(3.75m)); Assert.That(sut.DiscountedSubTotal, Is.EqualTo(2.25m)); Assert.That(sut.DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50")); }
public void When_promotion_applies() { var productCatalog = new ProductCatalog(); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); productCatalog.AddProduct("apple", 0.75m); var sut = new AdditionalItemDiscountRule(productCatalog); var promotions = new Promotions(new List <IPromotionalDiscountRule>() { sut }); var lineItem = new LineItem("apple", 7, productCatalog, promotions); var actual = sut.PromotionApplies(lineItem); Assert.That(actual, Is.True); }
public void When_calculating_rule() { var productCatalog = new ProductCatalog(); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); productCatalog.AddProduct("apple", 0.75m); var sut = new AdditionalItemDiscountRule(productCatalog); var promotions = new Promotions(new List <IPromotionalDiscountRule>() { sut }); var lineItem = new LineItem("apple", 7, productCatalog, promotions); var actual = sut.Calculate(lineItem); Assert.That(actual.DiscountedSubTotal, Is.EqualTo(3m)); Assert.That(actual.DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $3.00, Savings $2.25")); }
public void When_constructed_with_additional_item_discount() { var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var sut = new LineItem("apple", 5, productCatalog, new Promotions(new List <IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog) })); Assert.That(sut.Barcode, Is.EqualTo("apple")); Assert.That(sut.Quantity, Is.EqualTo(5)); Assert.That(sut.PricePerUnit, Is.EqualTo(0.75m)); Assert.That(sut.SubTotal, Is.EqualTo(3.75m)); Assert.That(sut.DiscountedSubTotal, Is.EqualTo(2.25m)); Assert.That(sut.DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50")); }
public void When_constructed_with_applicable_additional_item_discount() { var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var sut = new Bill(new List <string>() { "apple", "banana", "apple", "apple", "apple", "apple" }, productCatalog, new Promotions(new List <IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog) })); Assert.That(sut.Total, Is.EqualTo(3.25m)); Assert.That(sut.LineItems.Count(), Is.EqualTo(2)); Assert.That(sut.LineItems.ElementAt(0).PricePerUnit, Is.EqualTo(0.75m)); Assert.That(sut.LineItems.ElementAt(0).DiscountNote, Is.EqualTo("***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50")); }
public void When_I_generate_a_receipt_with_additional_item_discount() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); productCatalog.AddAdditionalItemDiscount("apple", 1, 1, 100); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List <IPromotionalDiscountRule>() { new AdditionalItemDiscountRule(productCatalog), new QuantityDiscountRule(productCatalog) })); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n5 apple @ $0.75 is $3.75\n***Discount on apple: Buy 1 apple get 1 at $0.00, New Price $2.25, Savings $1.50\n1 banana @ $1.00 is $1.00\nTotal is $3.25")); }