コード例 #1
0
        public void Should_replace_expression_transformation_decorator()
        {
            var callCounter = new int[1];

            var context = new TestExpressionExecutionContext(
                new ExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

            context
            .With(new Func <Expression, System.Linq.Expressions.Expression>(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With(new Func <Expression, System.Linq.Expressions.Expression>(x =>
            {
                throw new Exception("should have been replaced by next strategy");
            }))
            .With((Expression x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionContext.Step1_Expression);
                return(TestExpressionExecutionContext.Step2_Expression);
            })
            .Execute()
            .ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);

            context.AssertAllMethodsInvokedExacltyOnce(skip: 1);
            callCounter.ShouldAllBe(x => x == 1);
        }
コード例 #2
0
        public void Should_replace_result_to_dynamic_object_projection_decorator()
        {
            var callCounter = new int[1];

            var context = new TestExpressionExecutionContext(
                new ExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

            context
            .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(TestExpressionExecutionContext.Step5_Result);
                return(TestExpressionExecutionContext.Step6_Result);
            })
            .Execute()
            .ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);

            context.AssertAllMethodsInvokedExacltyOnce(skip: 5);
            callCounter.ShouldAllBe(x => x == 1);
        }
コード例 #3
0
        public void Should_apply_all_custom_strategies_and_return_expected_result()
        {
            var context = new TestExpressionExecutionContext(
                new ExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

            context
            .Execute()
            .ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);

            context.AssertAllMethodsInvokedExacltyOnce();
        }
コード例 #4
0
        public void Should_apply_system_expression_preparation_decorator()
        {
            var customExpression1 = System.Linq.Expressions.Expression.Constant("exp1");
            var customExpression2 = System.Linq.Expressions.Expression.Constant("exp2");

            var callCounter = new int[3];

            var context = new TestExpressionExecutionContext(
                new ExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

            context
            .With((System.Linq.Expressions.Expression x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionContext.Step3_Expression);
                return(customExpression1);
            })
            .With((System.Linq.Expressions.Expression x) =>
            {
                callCounter[1]++;
                x.ShouldBeSameAs(customExpression1);
                return(customExpression2);
            })
            .With((System.Linq.Expressions.Expression x) =>
            {
                callCounter[2]++;
                x.ShouldBeSameAs(customExpression2);
                return(TestExpressionExecutionContext.Step3_Expression);
            })
            .Execute()
            .ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);

            context.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }
コード例 #5
0
        public void Should_apply_dynamic_object_result_processing_decorator()
        {
            var customResult1 = new[] { new DynamicObject("result1") };
            var customResult2 = new[] { new DynamicObject("result2") };

            var callCounter = new int[3];

            var context = new TestExpressionExecutionContext(
                new ExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

            context
            .With((IEnumerable <DynamicObject> x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);
                return(customResult1);
            })
            .With((IEnumerable <DynamicObject> x) =>
            {
                callCounter[1]++;
                x.ShouldBeSameAs(customResult1);
                return(customResult2);
            })
            .With((IEnumerable <DynamicObject> x) =>
            {
                callCounter[2]++;
                x.ShouldBeSameAs(customResult2);
                return(TestExpressionExecutionContext.Step7_Result);
            })
            .Execute()
            .ShouldBeSameAs(TestExpressionExecutionContext.Step7_Result);

            context.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }