public void NoneTaxShouldNotAffectPrice() { Product product = Product.Sample; Tax tax = Tax.None; AffectPriceResult result = tax.ApplyTo(product.Price); string expected = "Product price reported as $20.25 before tax and $20.25 after 0% tax"; Assert.AreEqual(expected, result.DescribeWith(product, tax)); }
public void Tax20ShouldIncreasePriceAfterTax() { Product product = Product.Sample; Tax tax = new Tax(20); AffectPriceResult result = tax.ApplyTo(product.Price); string expected = "Product price reported as $20.25 before tax and $24.30 after 20% tax"; Assert.AreEqual(expected, result.DescribeWith(product, tax)); }
public void Discount15ShouldDecreasePriceAfterTax() { Product product = Product.Sample; Discount discount = new Discount(15); AffectPriceResult result = discount.ApplyTo(product.Price); string expected = "Discount: rate = 15%, amount = $3.04. Price: before = $20.25, after = $17.21"; Assert.AreEqual(expected, result.DescribeWith(product, discount)); }
public void NoneDiscountShouldNotAffectPrice() { Product product = Product.Sample; Discount discount = Discount.None; AffectPriceResult result = discount.ApplyTo(product.Price); string expected = "Discount: rate = 0%, amount = $0.00. Price: before = $20.25, after = $20.25"; Assert.AreEqual(expected, result.DescribeWith(product, discount)); }
public void Tax20Discount15ShouldAffectPriceAfterTax() { Product product = Product.Sample; Tax tax = new Tax(20); AffectPriceResult taxResult = tax.ApplyTo(product.Price); Discount discount = new Discount(15); AffectPriceResult discountResult = discount.ApplyTo(product.Price); Amount priceAfterAll = product.Price + taxResult.AffectedAmount - discountResult.AffectedAmount; Assert.AreEqual("20%", tax.ToString()); Assert.AreEqual("$4.05", taxResult.AffectedAmount.ToString()); Assert.AreEqual("15%", discount.ToString()); Assert.AreEqual("$3.04", discountResult.AffectedAmount.ToString()); Assert.AreEqual("$21.26", priceAfterAll.ToString()); }
public static string DescribeWith(this AffectPriceResult result, Product product, Discount discount) => $"Discount: rate = {discount}, amount = {result.AffectedAmount}. Price: before = {product.Price}, after = {result.AffectedPrice}";
public static string DescribeWith(this AffectPriceResult result, Product product, Tax tax) => $"Product price reported as {product.Price} before tax and {result.AffectedPrice} after {tax} tax";