public void ReturnPriceLessPreferredCustomerDiscountGivenPreferredCustomerAndQuatityGreatherThanOne() { // Arrange var units = 1; var unitPrice = 2.5m; customer = new Customer { IsPreferred = true }; // Act var calculatedPrice = pricingCalculator.Calculate(units, customer, unitPrice); // Assert var expectedPrice = unitPrice * units * (1 - PricingCalculator.PreferredCustomerDiscount); Assert.AreEqual(expectedPrice, calculatedPrice); }
public void PricingCalculator_Calculate_Args_Null_Items() { // ARRANGE var calculator = new PricingCalculator(); // ACT Exception ex = Assert.Throws <ArgumentNullException>( () => calculator.Calculate(null)); // ASSERT Assert.Equal("Value cannot be null. (Parameter 'items')", ex.Message); }
public void CalculatePricing_When_No_Promotions() { // ARRANGE var cart = TestData.Cart1; var calculator = new PricingCalculator(); // ACT var result = calculator.Calculate(cart); // ASSERT Assert.Equal(24.77M, result.TotalPrice); Assert.Equal(0M, result.TotalDiscount); Assert.Equal(result.TotalPrice, result.TotalPriceToPay); }
public void CalculatePricing_With_BuyALotGetADiscount_Promotion() { // ARRANGE var cart = TestData.Cart1; var calculator = new PricingCalculator(); // ACT var result = calculator.Calculate( cart, new BuyALotGetADiscountPromotion(3, 2) // buy at least 3 items and get 2% of discount ); // ASSERT Assert.Equal(24.77M, result.TotalPrice); Assert.Equal(0.4954M, result.TotalDiscount); Assert.Equal(result.TotalPriceToPay, result.TotalPrice - result.TotalDiscount); }
public void CalculatePricing_With_Buy3GetOneFree_Promotion() { // ARRANGE var cart = TestData.Cart1; var calculator = new PricingCalculator(); // ACT var result = calculator.Calculate( cart, new BuyManyGetSomeFreePromotion(3, 1, "kg", new Guid(TestData.ApplesSku)) // get 1kg of apples free for each 3kg (buy 3 get 1 free) ); // ASSERT Assert.Equal(24.77M, result.TotalPrice); Assert.Equal(1.55M, result.TotalDiscount); Assert.Equal(result.TotalPriceToPay, result.TotalPrice - result.TotalDiscount); }
public void CalculatePricing_With_Two_Promotions() { // ARRANGE var cart = TestData.Cart1; var calculator = new PricingCalculator(); // ACT var result = calculator.Calculate( cart, new BuyManyGetSomeFreePromotion(3, 1, "kg", new Guid(TestData.ApplesSku)), // get 1kg of apples free for each 3kg (buy 3 get 1 free) new BuyALotGetADiscountPromotion(3, 2) // buy at least 3 items and get 2% of discount ); // ASSERT Assert.Equal(24.77M, result.TotalPrice); Assert.Equal(2.0454M, result.TotalDiscount); Assert.Equal(result.TotalPriceToPay, result.TotalPrice - result.TotalDiscount); }