public void NewDiscountPricingRule_For0DiscountPrice_ThrowsArgumentOutOfRangeException() { var units = 1; var discountPrice = 0; var regularPricingRule = new RegularPricingRule(); Assert.ThrowsException <ArgumentOutOfRangeException>(() => new DiscountPricingRule(units, discountPrice, regularPricingRule)); }
public void ApplyPrice_Calculates_Price() { var regularPricing = new RegularPricingRule(); var orderItem = new OrderItem { Product = new Product { UnitPrice = 10 }, Units = 2 }; var price = regularPricing.ApplyPrice(orderItem); Assert.AreEqual(20, price); }
public void Checkout() { var product1 = new Product { UnitPrice = 10, PricingRules = new List <IPricingRule> { new RegularPricingRule() } }; var regPricingRule = new RegularPricingRule(); var product2 = new Product { UnitPrice = 20, PricingRules = new List <IPricingRule> { regPricingRule, new DiscountPricingRule(2, 35, regPricingRule) } }; var cartItems = new List <OrderItem> { new OrderItem { Product = product1, Units = 2 }, new OrderItem { Product = product2, Units = 3 } }; var register = new BillingRegister(); var total = register.Checkout(cartItems); Assert.AreEqual(75, total); }
public void ApplyPrice_For() { // Init var units = 3; var discountPrice = 25; var regularPricingRule = new RegularPricingRule(); var discountPricingRule = new DiscountPricingRule(units, discountPrice, regularPricingRule); var orderItem = new OrderItem { Product = new Product { UnitPrice = 10 }, Units = 4 }; // Call var price = discountPricingRule.ApplyPrice(orderItem); // Assert Assert.AreEqual(35, price); }
public void ApplyPrice_ForNullOrderItem_Throws() { var regularPricing = new RegularPricingRule(); Assert.ThrowsException <ArgumentNullException>(() => regularPricing.ApplyPrice(null)); }