public void Given_ParcelTypeListWithCandidateForSmallDiscountAndMixedParcels_Should_ReturnTheValidDiscountList() { //Arrange var parcelCosts = new List <ParcelDeliveryCost> { new ParcelDeliveryCost("Parcel #1", ParcelType.Small, 8), new ParcelDeliveryCost("Parcel #2", ParcelType.Small, 8), new ParcelDeliveryCost("Parcel #3", ParcelType.Small, 8), new ParcelDeliveryCost("Parcel #4", ParcelType.Small, 10), new ParcelDeliveryCost("Parcel #7", ParcelType.Large, 20), new ParcelDeliveryCost("Parcel #8", ParcelType.XLarge, 25), new ParcelDeliveryCost("Parcel #9", ParcelType.XLarge, 25), new ParcelDeliveryCost("Parcel #10", ParcelType.Heavy, 50), new ParcelDeliveryCost("Parcel #5", ParcelType.Medium, 15), new ParcelDeliveryCost("Parcel #6", ParcelType.Medium, 20) }; var sut = new DiscountCalculator(); //Act var result = sut.CalculateDiscount(parcelCosts).ToArray(); //Assert result.Should().HaveCount(2) .And.Contain(m => m.Discount == 8m && m.Description == "Small - Discount") .And.Contain(m => m.Discount == 15m && m.Description == "Mixed - Discount"); }
public void TypeDiscount_DiscountTrue_Test() { //1. Arange _calc = new DiscountCalculator(); var beasts = new List <Beast> { new Beast { Name = "Koe", Price = 100, Type = "Boerderij" }, new Beast { Name = "Paard", Price = 100, Type = "Boerderij" }, new Beast { Name = "Varken", Price = 100, Type = "Boerderij" } }; //2. Act var result = _calc.TypeDiscount(beasts); //3. Assert Assert.AreEqual(10, result.PercentageDiscount); }
public void CalculatorExecutionTest() { // Arrange ICanDiscountStrategy canDiscountStrategy = new DayOfWeekCanDiscountStrategy(DayOfWeek.Friday); ICalculateDiscountStrategy calculateDiscountStrategy = new PercentageCalculateDiscountStrategy(0.5m); IDiscountCalculator discountCalculator = new DiscountCalculator(canDiscountStrategy, calculateDiscountStrategy); Order order = CreateOrderWith1Product("2019-10-18", 1000); // Act Action act = () => discountCalculator.CalculateDiscount(order); // Asserts act .ExecutionTime() .Should() .BeLessOrEqualTo(500.Milliseconds()); }
public Discount DateDiscount([PexAssumeUnderTest] DiscountCalculator target, DateTime date) { Discount result = target.DateDiscount(date); return(result); // TODO: add assertions to method DiscountCalculatorTest.DateDiscount(DiscountCalculator, DateTime) }
public void GetTotal_returns_correct_price_where_multiple_discounts_are_applied() { // Arrange var offers = new List <IDiscountOffer> { new FreeMilkOffer(), new HalfPriceBreadOffer() }; var basket = new Basket(); var calc = new DiscountCalculator(offers); var handler = new CheckoutHandler(calc); basket.AddItem(new Butter()); basket.AddItem(new Butter()); basket.AddItem(new Bread()); for (int i = 0; i < 8; i++) { basket.AddItem(new Milk()); } // Act var result = handler.CalculateBasketTotal(basket); // Assert Assert.Equal(9M, result); }
public void CalculateEmployeeDiscount( ) { var customer = new Customer { CustomerType = CustomerType.Employee, StartDate = DateTime.Now, }; // items Total $100 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 50M }, new Item { ItemType = ItemType.Other, Value = 50M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; // Input amount is $100, expected output is $65 // $30 discount from 30% discount + 5$ discount for $100 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(65M, amountOwed); }
public void GetBestPriceForZeroBooks() { var discountCalculator = new DiscountCalculator(); discountCalculator.GetBestPrice(null); Assert.AreEqual(0, discountCalculator.GetBestPrice(null)); }
public void CalculateLargeAmountDiscount2( ) { var customer = new Customer { CustomerType = CustomerType.Customer, StartDate = new DateTime(2011, 1, 1), }; // items Total $1000 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 900M }, new Item { ItemType = ItemType.Other, Value = 100M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; //Input amount is $1000, //discount % is then $50, //discount amount is $50 //output should be $900 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(900M, amountOwed); }
public void CalculateLargeAmountDiscountForOldCustomer( ) { var customer = new Customer { CustomerType = CustomerType.Customer, StartDate = new DateTime(2011, 1, 1), }; // items Total $990 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 900M }, new Item { ItemType = ItemType.Other, Value = 90M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; //Input amount is $990, //Discount % = $49.5 //Bulk discount = $45 //output should be $895.5 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(895.5M, amountOwed); }
public void CalculateLargeAmountDiscount( ) { var customer = new Customer { CustomerType = CustomerType.Customer, StartDate = DateTime.Now }; // items Total $990 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 900M }, new Item { ItemType = ItemType.Other, Value = 90M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; //Input amount is $990, discount is then $45, output should be $945 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(945M, amountOwed); }
public void CalculateCustomerDiscount2( ) { var customer = new Customer { CustomerType = CustomerType.Customer, StartDate = new DateTime(2011, 1, 1), }; // items Total $50 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 20M }, new Item { ItemType = ItemType.Other, Value = 30M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; //Input amount is $50 (less than $100) so expected output is also $47.5 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(47.5M, amountOwed); }
public void CalculateAffiliateDiscount( ) { var customer = new Customer { CustomerType = CustomerType.Affiliate, StartDate = DateTime.Now }; // items Total $100 var items = new List <Item> { new Item { ItemType = ItemType.Other, Value = 50M }, new Item { ItemType = ItemType.Other, Value = 50M } }; var shoppingCart = new ShoppingCart { Customer = customer, Items = items }; // Input amount is $100, expected output is $85 // $10 discount from the 10% + 5$ discount for being $100 var calculator = new DiscountCalculator( ); var amountOwed = calculator.CalculateDiscount(shoppingCart); Assert.AreEqual(85M, amountOwed); }
Given_ParcelTypeListWithCandidateForMediumDiscountWithNotEligibleDiscountParcels_Should_ReturnTheValidDiscountList() { //Arrange var parcelCosts = new List <ParcelDeliveryCost> { new ParcelDeliveryCost("Parcel #1", ParcelType.Medium, 8), new ParcelDeliveryCost("Parcel #2", ParcelType.Medium, 8), new ParcelDeliveryCost("Parcel #3", ParcelType.Medium, 8), new ParcelDeliveryCost("Parcel #4", ParcelType.Medium, 10), new ParcelDeliveryCost("Parcel #5", ParcelType.Medium, 10), new ParcelDeliveryCost("Parcel #6", ParcelType.Medium, 10), // Not Eligible Discounts new ParcelDeliveryCost("Parcel #7", ParcelType.Medium, 10), new ParcelDeliveryCost("Parcel #8", ParcelType.Medium, 10) }; var sut = new DiscountCalculator(); //Act var result = sut.CalculateDiscount(parcelCosts).ToArray(); //Assert result.Should().HaveCount(2) .And.Contain(m => m.Discount == 8m && m.Description == "Medium - Discount") .And.Contain(m => m.Discount == 10m && m.Description == "Medium - Discount"); }
public void TypeDiscount_DiscountFalse_Test() { //1. Arange _calc = new DiscountCalculator(); var beasts = new List <Beast> { new Beast { Name = "Koe", Price = 100, Type = "Boerderij" }, new Beast { Name = "Paard", Price = 100, Type = "Boerderij" }, new Beast { Name = "Hagedis", Price = 200, Type = "Woestijn" } }; //2. Act var result = _calc.TypeDiscount(beasts); //3. Assert Assert.IsNull(result); }
public void CheckMax() { IDiscountCalculator discountCalculator1 = new DiscountCalculator(new Func <ShoppingBasket, DiscountOfProducts>((ShoppingBasket shoppingBasket) => d1)); IDiscountCalculator discountCalculator2 = new DiscountCalculator(new Func <ShoppingBasket, DiscountOfProducts>((ShoppingBasket shoppingBasket) => d2)); IDiscountCalculator discountCalculator3 = discountCalculator1.Max(discountCalculator2); Assert.AreEqual(20, discountCalculator3.CalcDiscount(shoppingBasket).Discount); }
public ShoppingCartService(ProductService productService, ShoppingCartRepository shoppingCartRepository, DiscountCalculator discountCalculator) { _productService = productService; _shoppingCartRepository = shoppingCartRepository; _discountCalculator = discountCalculator; }
public void CalculateDiscount_IfTotalSumPriceIsLessThen100_Return0() { var discountCalculator = new DiscountCalculator(); var result = discountCalculator.CalculateDiscount(TestProducts2()); Assert.AreEqual(0, result); }
public With_all_discount_rules_applied() { _discountCalculator = new DiscountCalculator(new List <IDiscountRule> { new DiscountRuleFiveToTenItems(), new DiscountRuleTenToFifteenItems() }); }
public void CalculateDiscount_throws_null_argument_exception_when_passed_null_object() { // Arrrange var calc = new DiscountCalculator(new List <IDiscountOffer>()); // Assert Assert.Throws <ArgumentNullException>(() => calc.CalculateDiscount(null)); }
private decimal GetDiscountLine(ICartItem[] items, out IList <decimal> discountLines) { CartItemGroup group = new CartItemGroup(items); DiscountCalculator cal = new DiscountCalculator(); return(cal.GetDiscount(group, StoreContext.CheckoutDetails.Coupon, StoreContext.Customer, out discountLines)); }
public void SetUp() { _discountCalculator = new DiscountCalculator(new List <IDiscountRule> { new DiscountRuleFiveToTenItems(), new DiscountRuleTenToFifteenItems() }); }
protected override void TestSetUp() { IDiscountStrategy tieredDiscountStrategy = DiscountStrategyBuilder.BuildTieredStrategy() .Where.OrdersGreaterThanOrEqualTo(100.dollars()).GetDiscountOf(10.Percent()) .Build(); _calculator = new DiscountCalculator(tieredDiscountStrategy); }
public When_calculating_a_tiered_discount() { IDiscountStrategy tieredDiscountStrategy = DiscountStrategyBuilder.BuildTieredStrategy() .Where.OrdersGreaterThanOrEqualTo(100.dollars()).GetDiscountOf(10.Percent()) .Build(); _calculator = new DiscountCalculator(tieredDiscountStrategy); }
public void calculate_tshirt_price_two_day_delivery_with_no_discount() { var tshirtPrice = new TshirtPrice(_tshirtPriceProvider.TshirtPrice("2")); var discountCalculator = new DiscountCalculator(tshirtPrice, _discountProvider.Discount("None")); var price = discountCalculator.CalculatePrice(100); Assert.AreEqual(120, price); }
public void calculate_tshirt_price_two_day_delivery_with_studentmember_discount() { var tshirtPrice = new TshirtPrice(_tshirtPriceProvider.TshirtPrice("2")); var discountCalculator = new DiscountCalculator(tshirtPrice, _discountProvider.Discount("StudentMember")); var price = discountCalculator.CalculatePrice(100); Assert.AreEqual(84, price); }
public void SetUp() { _discountCalculator = new DiscountCalculator(new List<IDiscountRule> { new DiscountRuleFiveToTenItems(), new DiscountRuleTenToFifteenItems() }); }
public void calculate_tshirt_price_one_day_delivery_with_student_discount() { var tshirtPrice = new TshirtPrice(_tshirtPriceProvider.TshirtPrice("1")); var discountCalculator = new DiscountCalculator(tshirtPrice, _discountProvider.Discount("Student")); var price = discountCalculator.CalculatePrice(100); Assert.AreEqual(117, price); }
public void TestTotalOrder() { DiscountCalculator dc = new DiscountCalculator(new Promotion()); Order newOrder = dc.CalculateDiscount(GetOrder()); Assert.AreEqual(320.0, newOrder.TotalPrice, 0.001); }
public ActionResult Step4() { var calc = new DiscountCalculator(); var booking = _boekingRepository.TempBooking; booking.Discounts = calc.CalculateTotalDiscount(booking.Booking); booking.Price = calc.CalculateTotalPrice(booking.Booking); return(View(booking)); }
public void applyCoupon(Coupon coupon) { DiscountCalculator discountCalculator = new DiscountCalculator(ShoppingCartItemList); double maxCampaignAmount = discountCalculator.GetDiscountAmount(coupon); Coupon = coupon; CouponDiscount = maxCampaignAmount; TotalAmountAfterDiscount = TotalAmount - CouponDiscount; }
public void CalculateTotals() { try { if (view.CurrentWeightTicket.IsEntranceWeightTicket) { view.CurrentWeightTicket.EntranceNetWeight = view.CurrentWeightTicket.EntranceWeightKg - view.CurrentWeightTicket.ExitWeightKg; view.CurrentWeightTicket.ExitNetWeight = 0; view.CurrentWeightTicket.NetWeight = view.CurrentWeightTicket.EntranceNetWeight; } else { view.CurrentWeightTicket.ExitNetWeight = view.CurrentWeightTicket.ExitWeightKg - view.CurrentWeightTicket.EntranceWeightKg; view.CurrentWeightTicket.EntranceNetWeight = 0; view.CurrentWeightTicket.NetWeight = view.CurrentWeightTicket.ExitNetWeight; } if (view.CurrentWeightTicket.ApplyHumidity) { view.CurrentWeightTicket.HumidityDiscount = DiscountCalculator.GetDiscount(DiscountType.Humidity, view.CurrentWeightTicket.Humidity, view.CurrentWeightTicket.NetWeight, view.CurrentWeightTicket.IsEntranceWeightTicket); } else { view.CurrentWeightTicket.HumidityDiscount = 0; } if (view.CurrentWeightTicket.ApplyImpurities) { view.CurrentWeightTicket.ImpuritiesDiscount = DiscountCalculator.GetDiscount(DiscountType.Impurities, view.CurrentWeightTicket.Impurities, view.CurrentWeightTicket.NetWeight, view.CurrentWeightTicket.IsEntranceWeightTicket); } else { view.CurrentWeightTicket.ImpuritiesDiscount = 0; } view.CurrentWeightTicket.TotalWeightToPay = view.CurrentWeightTicket.NetWeight - view.CurrentWeightTicket.HumidityDiscount - view.CurrentWeightTicket.ImpuritiesDiscount; view.CurrentWeightTicket.SubTotal = view.CurrentWeightTicket.Price * (decimal)view.CurrentWeightTicket.TotalWeightToPay; if (view.CurrentWeightTicket.ApplyDrying) { view.CurrentWeightTicket.DryingDiscount = DiscountCalculator.GetDiscount(DiscountType.Drying, view.CurrentWeightTicket.Humidity, view.CurrentWeightTicket.NetWeight, view.CurrentWeightTicket.IsEntranceWeightTicket); } else { view.CurrentWeightTicket.DryingDiscount = 0; } view.CurrentWeightTicket.TotalToPay = view.CurrentWeightTicket.SubTotal - (decimal)view.CurrentWeightTicket.DryingDiscount - (decimal)view.CurrentWeightTicket.BrokenGrainDiscount - (decimal)view.CurrentWeightTicket.CrashedGrainDiscount - (decimal)view.CurrentWeightTicket.DamagedGrainDiscount - (decimal)view.CurrentWeightTicket.SmallGrainDiscount; view.CurrentWeightTicket.RaiseUpdateProperties(); } catch (Exception ex) { StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); MethodBase currentMethodName = sf.GetMethod(); Guid errorId = Guid.NewGuid(); //Log error here view.HandleException(ex, currentMethodName.Name, errorId); } }
public decimal GetPriceOfUniqueBooks(int numberOfUniqueBooks) { var discountCalculator = new DiscountCalculator(); switch (numberOfUniqueBooks) { case (1): return discountCalculator.GetDiscount(0); case (3): return discountCalculator.GetDiscount(10); case (4): return discountCalculator.GetDiscount(20); case (5): return discountCalculator.GetDiscount(25); default: return discountCalculator.GetDiscount(5); } }
public Basket(DiscountCalculator discountCalculator, TotalCalculator totalCalculator) { _discountCalculator = discountCalculator; _totalCalculator = totalCalculator; }
public Checkout(ICanTellDisplayTheTotal itemPriceTotaler, DiscountCalculator discountCalculator) { _itemPriceTotaler = itemPriceTotaler; _bob = discountCalculator; }
public Checkout(TotalCalculator totalCalculator, DiscountCalculator discountCalculator) { _basket = new Basket(discountCalculator, totalCalculator); }