示例#1
0
        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);
            });
        }
示例#2
0
        public void RulesAreExecutedInOrder()
        {
            var testContext = new TestContext();

            var pipeline = new TestPromotionPipeline();
            var ruleA    = new PromotionRuleA();
            var ruleB    = new PromotionRuleB();

            pipeline.AddRule(ruleA);
            pipeline.AddRule(ruleB);

            pipeline.Apply(testContext.CartFactory.Create());

            Assert.True(pipeline.RunHistory.Any());
            Assert.Equal(2, pipeline.RunHistory.Count);
            Assert.True((object)pipeline.RunHistory[0] == (object)ruleA);
            Assert.True((object)pipeline.RunHistory[1] == (object)ruleB);
        }