Пример #1
0
        public void Should_apply_all_custom_strategies_and_return_expected_result()
        {
            var context = new TestExpressionExecutionContext(
                new DefaultExpressionExecutor(null),
                TestExpressionExecutionContext.Step0_Expression);

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

            context.AssertAllMethodsInvokedExacltyOnce();
        }
Пример #2
0
        public void Should_replace_expression_transformation_decorator()
        {
            var callCounter = new int[1];

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

            context
            .With(new Func <Expression, System.Linq.Expressions.Expression>(x => throw ShouldHaveBeenReplacedException))
            .With(new Func <Expression, System.Linq.Expressions.Expression>(x => throw ShouldHaveBeenReplacedException))
            .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);
        }
Пример #3
0
        public void Should_replace_result_to_dynamic_object_projection_decorator()
        {
            var callCounter = new int[1];

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

            context
            .With(new Func <object, DynamicObject>(x => throw ShouldHaveBeenReplacedException))
            .With(new Func <object, DynamicObject>(x => throw ShouldHaveBeenReplacedException))
            .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);
        }
Пример #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 DefaultExpressionExecutor(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 DynamicObject("result1");
            var customResult2 = new DynamicObject("result2");

            var callCounter = new int[3];

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

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

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