public string ReceiptOneDefy(int amount) { var lineDiscount = new DiscountStrategyCalculator <LineViewModel>(); lineDiscount.Configure() .When(line => line.Quantity >= 20 && line.Price >= 1000) .ApplyDiscount(line => line.Quantity * line.Price * 0.1m); var orderVm = new OrderViewModel(Substitute.For <IDiscountCalculator <OrderViewModel> >(), lineDiscount, new Order("Anywhere Bike Shop", "USD", 0.0725m)); orderVm.AddLine(new Line(Defy, amount)); var generator = new StringReceiptBuilder(); return(generator.GenerateReceipt(orderVm)); }
public void Should_GetDiscount_With_MinOperation_Mins_Discounts() { var sut = new DiscountStrategyCalculator <Order>(DiscountStrategyOperations.Min); sut.Configure() .When(_ => true) .ApplyDiscount(_ => 20m) .When(_ => true) .ApplyDiscount(_ => 60m); var discount = sut.GetDiscount(new Order(Arg.Any <string>(), Arg.Any <string>(), 0.0725m)); Assert.That(discount, Is.EqualTo(20m)); }
public void Should_AddCalculator_Compose_With_Itself() { var calculator = new DiscountStrategyCalculator <Order>(DiscountStrategyOperations.Sum); var otherCalculator = new DiscountStrategyCalculator <Order>(); calculator.Configure() .When(_ => true) .ApplyDiscount(_ => 42m); otherCalculator.Configure() .When(_ => true) .ApplyDiscount(_ => 42m); calculator.AddCalculator(otherCalculator); Assert.That( calculator.GetDiscount(new Order(Arg.Any <string>(), Arg.Any <string>(), 0.0725m)), Is.EqualTo(84m)); }
public void Should_AddCalculator_Throw_ArgumentException_When_Cyclic_References() { var sut = new DiscountStrategyCalculator <Order>(); Assert.Throws <ArgumentException>(() => sut.AddCalculator(sut)); }