public void Should_replace_expression_transformation_executor()
        {
            var callCounter = new int[1];

            var executor = new TestExpressionExecutor();

            executor
            .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(TestExpressionExecutor.Step1_Expression);
                return(TestExpressionExecutor.Step2_Expression);
            })
            .Execute(TestExpressionExecutor.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutor.Step7_Result);

            executor.AssertAllMethodsInvokedExacltyOnce(skip: 1);
            callCounter.ShouldAllBe(x => x == 1);
        }
        public void Should_apply_remote_expression_preparation_executor()
        {
            var customExpression1 = new ConstantExpression("exp1");
            var customExpression2 = new ConstantExpression("exp2");

            var callCounter = new int[3];

            var executor = new TestExpressionExecutor();

            executor
            .With(x =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutor.Step1_Expression);
                return(customExpression1);
            })
            .With(x =>
            {
                callCounter[1]++;
                x.ShouldBeSameAs(customExpression1);
                return(customExpression2);
            })
            .With(x =>
            {
                callCounter[2]++;
                x.ShouldBeSameAs(customExpression2);
                return(TestExpressionExecutor.Step1_Expression);
            })
            .Execute(TestExpressionExecutor.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutor.Step7_Result);

            executor.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }
        public void Should_apply_dynamic_object_result_processing_executor()
        {
            var customResult1 = new[] { new DynamicObject("result1") };
            var customResult2 = new[] { new DynamicObject("result2") };

            var callCounter = new int[3];

            var executor = new TestExpressionExecutor();

            executor
            .With((IEnumerable <DynamicObject> x) =>
            {
                callCounter[0]++;
                x.ShouldBeSameAs(TestExpressionExecutor.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(TestExpressionExecutor.Step7_Result);
            })
            .Execute(TestExpressionExecutor.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutor.Step7_Result);

            executor.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }
        public void Should_replace_result_to_dynamic_object_projection_executor()
        {
            var callCounter = new int[1];

            var executor = new TestExpressionExecutor();

            executor
            .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(TestExpressionExecutor.Step5_Result);
                return(TestExpressionExecutor.Step6_Result);
            })
            .Execute(TestExpressionExecutor.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutor.Step7_Result);

            executor.AssertAllMethodsInvokedExacltyOnce(skip: 5);
            callCounter.ShouldAllBe(x => x == 1);
        }
        public void Should_apply_raw_result_processing_executor()
        {
            var customResult1 = "result1";
            var customResult2 = "result2";

            var callCounter = new int[3];

            var executor = new TestExpressionExecutor();

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

            executor.AssertAllMethodsInvokedExacltyOnce();
            callCounter.ShouldAllBe(x => x == 1);
        }
        public void Should_apply_all_custom_strategies_and_return_expected_result()
        {
            var executor = new TestExpressionExecutor();

            executor
            .Execute(TestExpressionExecutor.Step0_Expression)
            .ShouldBeSameAs(TestExpressionExecutor.Step7_Result);

            executor.AssertAllMethodsInvokedExacltyOnce();
        }