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 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 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); }); }