public void WhenApplicationWithErrorsThenExceptionsListReportsFaultyRules() { var testContext = new TestContext(); var pipeline = new FaultTolerantPromotionPipeline(); var ruleA = new PromotionRuleA(); var ruleB = new FaultyPromotionRule(); var ruleC = new PromotionRuleA(); var ruleD = new FaultyPromotionRule(); pipeline.AddRule(ruleA); pipeline.AddRule(ruleB); pipeline.AddRule(ruleC); pipeline.AddRule(ruleD); ICart cart = pipeline.Apply(testContext.CartFactory.Create()); Assert.NotNull(cart); Assert.NotEmpty(pipeline.LastApplyExceptions); Assert.Collection(pipeline.LastApplyExceptions, errorEntry => { Assert.True((object)errorEntry.Item1 == (object)ruleB); Assert.IsType <TestException>(errorEntry.Item2); }, errorEntry => { Assert.True((object)errorEntry.Item1 == (object)ruleD); Assert.IsType <TestException>(errorEntry.Item2); }); }
public void PairOfDifferentSkusForRule_Two() { var testContext = new TestContext(); var skuA = testContext.CreateNewSku("A", 100); var skuB = testContext.CreateNewSku("B", 200); var skuC = testContext.CreateNewSku("C", 300); var skuD = testContext.CreateNewSku("D", 400); var cart = testContext.CartFactory.Create(); cart.Add(skuA, 2); cart.Add(skuB, 3); cart.Add(skuC, 2); cart.Add(skuD, 3); cart.TestTotal(2 * 100 + 3 * 200 + 2 * 300 + 3 * 400); var pipeline = new FaultTolerantPromotionPipeline(); pipeline.AddRule(new PairOfDifferentSkusForRule(testContext.CartFactory, skuA, skuB, 100)); pipeline.AddRule(new PairOfDifferentSkusForRule(testContext.CartFactory, skuC, skuD, 200)); var newCart = pipeline.Apply(cart); newCart.TestTotal(2 * 100 + 1 * 200 + 2 * 200 + 1 * 400); }
public void WhenNoRulesThenExceptionsListIsEmpty() { var testContext = new TestContext(); var pipeline = new FaultTolerantPromotionPipeline(); ICart cart = pipeline.Apply(testContext.CartFactory.Create()); Assert.NotNull(cart); Assert.Empty(pipeline.LastApplyExceptions); }
public void WhenApplicationWithErrorsThenExceptionsListIsNotEmpty() { var testContext = new TestContext(); var pipeline = new FaultTolerantPromotionPipeline(); pipeline.AddRule(new PromotionRuleA()); pipeline.AddRule(new FaultyPromotionRule()); ICart cart = pipeline.Apply(testContext.CartFactory.Create()); Assert.NotNull(cart); Assert.NotEmpty(pipeline.LastApplyExceptions); }
public void WhenAllRulesFailThenReturnedCartIsTheSameAsOriginal() { var testContext = new TestContext(); var pipeline = new FaultTolerantPromotionPipeline(); var ruleA = new FaultyPromotionRule(); var ruleB = new FaultyPromotionRule(); pipeline.AddRule(ruleA); pipeline.AddRule(ruleB); ICart originalCart = testContext.CartFactory.Create(); ICart newCart = pipeline.Apply(originalCart); Assert.NotNull(newCart); Assert.True((object)newCart == (object)originalCart); }
public void CollectionOfSameSkuForRule_Two() { var testContext = new TestContext(); var skuA = testContext.CreateNewSku("A", 100); var skuB = testContext.CreateNewSku("B", 200); var cart = testContext.CartFactory.Create(); cart.Add(skuA, 2); cart.Add(skuB, 3); cart.TestTotal(2 * 100 + 3 * 200); var pipeline = new FaultTolerantPromotionPipeline(); pipeline.AddRule(new CollectionOfSameSkuForRule(testContext.CartFactory, skuA, 2, 50)); pipeline.AddRule(new CollectionOfSameSkuForRule(testContext.CartFactory, skuB, 2, 100)); var newCart = pipeline.Apply(cart); newCart.TestTotal(1 * 50 + 1 * 100 + 200); }
public void WhenPreviousRuleFaultsThenNextRulesActionIsPreserved() { var testContext = new TestContext(); var pipeline = new FaultTolerantPromotionPipeline(); var sku = testContext.CreateNewSku("S", 0); var ruleA = new FaultyPromotionRule(); var ruleB = new SideEffectsPromotionRule(sku); pipeline.AddRule(ruleA); pipeline.AddRule(ruleB); ICart cart = pipeline.Apply(testContext.CartFactory.Create()); Assert.NotNull(cart); Assert.NotEmpty(pipeline.LastApplyExceptions); Assert.Collection(cart, entry => { Assert.True((object)entry.Sku == (object)sku); }); }