public void When_I_generate_a_receipt_with_regular_prices() { var sut = new ReceiptGenerator(); var productCatalog = new ProductCatalog(); productCatalog.AddProduct("apple", 0.75m); productCatalog.AddProduct("banana", 1.00m); var transaction = new CheckoutTransaction(productCatalog, new Promotions(new List<IPromotionalDiscountRule>())); transaction.AddItem("apple"); transaction.AddItem("banana"); transaction.AddItem("apple"); var actual = sut.Generate(transaction); Assert.That(actual, Is.EqualTo("Receipt:\n2 apple @ $0.75 is $1.50\n1 banana @ $1.00 is $1.00\nTotal is $2.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")); }
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); }