예제 #1
0
        public void Should_replace_result_to_dynamic_object_projection_decorator()
        {
            var callCounter = new int[1];

            var decorator = new TestExpressionExecutionDecorator(new ExpressionExecutor(null));

            decorator
            .With(new Func <object, IEnumerable <DynamicObject> >(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With(new Func <object, IEnumerable <DynamicObject> >(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With((object x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionDecorator.Step5_Result);
                return(TestExpressionExecutionDecorator.Step6_Result);
            })
            .Execute(TestExpressionExecutionDecorator.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutionDecorator.Step7_Result);

            decorator.AssertAllMethodsInvokedExacltyOnce(skip: 5);
            callCounter.ShouldAllBe(x => x == 1);
        }
예제 #2
0
        public void Should_apply_raw_result_processing_decorator()
        {
            var customResult1 = "result1";
            var customResult2 = "result2";

            var callCounter = new int[3];

            var decorator = new TestExpressionExecutionDecorator(new ExpressionExecutor(null));

            decorator
            .With((object x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionDecorator.Step5_Result);
                return(customResult1);
            })
            .With((object x) =>
            {
                callCounter[1]++;
                x.ShouldBeSameAs(customResult1);
                return(customResult2);
            })
            .With((object x) =>
            {
                callCounter[2]++;
                x.ShouldBeSameAs(customResult2);
                return(TestExpressionExecutionDecorator.Step5_Result);
            })
            .Execute(TestExpressionExecutionDecorator.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutionDecorator.Step7_Result);

            decorator.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }
예제 #3
0
        public void Should_replace_expression_execution_decorator()
        {
            var callCounter = new int[1];

            var decorator = new TestExpressionExecutionDecorator(new ExpressionExecutor(null));

            decorator
            .With(new Func <System.Linq.Expressions.Expression, object>(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With(new Func <System.Linq.Expressions.Expression, object>(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With((System.Linq.Expressions.Expression x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionDecorator.Step3_Expression);
                return(TestExpressionExecutionDecorator.Step4_Result);
            })
            .Execute(TestExpressionExecutionDecorator.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutionDecorator.Step7_Result);

            decorator.AssertAllMethodsInvokedExacltyOnce(skip: 3);
            callCounter.ShouldAllBe(x => x == 1);
        }
예제 #4
0
        public void Should_apply_all_custom_strategies_and_return_expected_result()
        {
            var decorator = new TestExpressionExecutionDecorator(new ExpressionExecutor(null));

            decorator
            .Execute(TestExpressionExecutionDecorator.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutionDecorator.Step7_Result);

            decorator.AssertAllMethodsInvokedExacltyOnce();
        }