コード例 #1
0
        public void VisitMemberExpression_WithInnerSqlSubStatementExpression()
        {
            var selectProjection = Expression.Constant(new Cook());
            var fakeStatement    = SqlStatementModelObjectMother.CreateSqlStatement(
                new NamedExpression("test", selectProjection), new SqlTable(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), JoinSemantics.Left));
            var memberInfo = typeof(Cook).GetProperty("Name");
            var queryModel = ExpressionHelper.CreateQueryModel <Cook>();

            queryModel.ResultOperators.Add(new FirstResultOperator(false));
            var expression       = new SubQueryExpression(queryModel);
            var memberExpression = Expression.MakeMemberAccess(expression, memberInfo);

            _stageMock
            .Expect(mock => mock.PrepareSqlStatement(queryModel, _context))
            .Return(fakeStatement);
            _stageMock.Replay();

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            _stageMock.VerifyAllExpectations();

            Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression)));
            var expectedSelectProjection = new NamedExpression("test", Expression.MakeMemberAccess(selectProjection, memberInfo));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedSelectProjection, ((SqlSubStatementExpression)result).SqlStatement.SelectProjection);
            Assert.That(((SqlSubStatementExpression)result).SqlStatement.DataInfo, Is.TypeOf(typeof(StreamedSequenceInfo)));
            Assert.That(((SqlSubStatementExpression)result).SqlStatement.DataInfo.DataType, Is.EqualTo(typeof(IQueryable <>).MakeGenericType(typeof(string))));
        }
コード例 #2
0
        public void VisitBinaryExpression()
        {
            var binaryExpression = Expression.And(Expression.Constant(1), Expression.Constant(1));
            var result           = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.SameAs(binaryExpression));
        }
コード例 #3
0
        public void VisitSubqueryExpressionTest_IsCountQuery()
        {
            var mainFromClause          = ExpressionHelper.CreateMainFromClause <Cook>();
            var querModel               = ExpressionHelper.CreateQueryModel(mainFromClause);
            var expression              = new SubQueryExpression(querModel);
            var sqlStatement            = SqlStatementModelObjectMother.CreateSqlStatement();
            var fakeSqlStatementBuilder = new SqlStatementBuilder(sqlStatement)
            {
                SelectProjection =
                    new AggregationExpression(typeof(int), sqlStatement.SelectProjection, AggregationModifier.Count)
            };

            var fakeSqlStatement = fakeSqlStatementBuilder.GetSqlStatement();

            _stageMock
            .Expect(mock => mock.PrepareSqlStatement(querModel, _context))
            .Return(fakeSqlStatement);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression)));
            Assert.That(((SqlSubStatementExpression)result).SqlStatement, Is.SameAs(fakeSqlStatement));
            Assert.That(
                ((AggregationExpression)((SqlSubStatementExpression)result).SqlStatement.SelectProjection).AggregationModifier,
                Is.EqualTo(AggregationModifier.Count));
        }
コード例 #4
0
        public void VisitMemberExpression_WithInnerSqlCaseExpression()
        {
            var testPredicate1 = Expression.Constant(true);
            var testPredicate2 = Expression.Constant(false);
            var value1         = Expression.Constant(new TypeWithMember <int> (1));
            var value2         = Expression.Constant(new TypeWithMember <int> (2));
            var elseValue      = Expression.Constant(new TypeWithMember <int> (3));

            var caseExpression = new SqlCaseExpression(
                typeof(TypeWithMember <int>),
                new[] { new SqlCaseExpression.CaseWhenPair(testPredicate1, value1), new SqlCaseExpression.CaseWhenPair(testPredicate2, value2) },
                elseValue);
            var memberExpression = Expression.Property(caseExpression, "Property");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedResult = new SqlCaseExpression(
                typeof(int),
                new[]
            {
                new SqlCaseExpression.CaseWhenPair(testPredicate1, Expression.Property(value1, "Property")),
                new SqlCaseExpression.CaseWhenPair(testPredicate2, Expression.Property(value2, "Property"))
            },
                Expression.Property(elseValue, "Property"));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
コード例 #5
0
        public void VisitMemberExpression_WithInnerSqlCaseExpression_NoElse()
        {
            var predicate              = Expression.Constant(true);
            var valueTypeValue         = Expression.Constant(new TypeWithMember <int> (1));
            var nullableValueTypeValue = Expression.Constant(new TypeWithMember <int?> (1));
            var referenceTypeValue     = Expression.Constant(new TypeWithMember <string> ("hoy"));

            var valueTypeMemberExpression         = CreateMemberExpressionWithInnerSqlCaseExpression <int> (predicate, valueTypeValue, null);
            var nullableValueTypeMemberExpression = CreateMemberExpressionWithInnerSqlCaseExpression <int?> (predicate, nullableValueTypeValue, null);
            var referenceTypeMemberExpression     = CreateMemberExpressionWithInnerSqlCaseExpression <string> (predicate, referenceTypeValue, null);

            var valueTypeResult = SqlPreparationExpressionVisitor.TranslateExpression(
                valueTypeMemberExpression, _context, _stageMock, _methodCallTransformerProvider);
            var nullableValueTypeResult = SqlPreparationExpressionVisitor.TranslateExpression(
                nullableValueTypeMemberExpression, _context, _stageMock, _methodCallTransformerProvider);
            var referenceTypeResult = SqlPreparationExpressionVisitor.TranslateExpression(
                referenceTypeMemberExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedValueTypeResult = CreateSqlCaseExpressionWithInnerMemberExpressionNoElse <int?> (predicate, valueTypeValue);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedValueTypeResult, valueTypeResult);
            var expectedNullableValueTypeResult = CreateSqlCaseExpressionWithInnerMemberExpressionNoElse <int?> (predicate, nullableValueTypeValue);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedNullableValueTypeResult, nullableValueTypeResult);
            var expectedReferenceTypeResult = CreateSqlCaseExpressionWithInnerMemberExpressionNoElse <string> (predicate, referenceTypeValue);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedReferenceTypeResult, referenceTypeResult);
        }
コード例 #6
0
        public void VisitSubqueryExpressionTest_RevisitsResult()
        {
            var mainFromClause          = ExpressionHelper.CreateMainFromClause <Cook>();
            var querModel               = ExpressionHelper.CreateQueryModel(mainFromClause);
            var expression              = new SubQueryExpression(querModel);
            var fakeSqlStatementBuilder = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatement())
            {
                TopExpression = null
            };

            fakeSqlStatementBuilder.Orderings.Add(new Ordering(Expression.Constant("order"), OrderingDirection.Asc));
            fakeSqlStatementBuilder.SqlTables.Add(SqlStatementModelObjectMother.CreateSqlTable(typeof(Cook)));
            var fakeSqlStatement = fakeSqlStatementBuilder.GetSqlStatement();

            fakeSqlStatementBuilder.Orderings.Clear();
            var expectedStatement = fakeSqlStatementBuilder.GetSqlStatement();

            _stageMock
            .Expect(mock => mock.PrepareSqlStatement(querModel, _context))
            .Return(fakeSqlStatement);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression)));
            Assert.That(((SqlSubStatementExpression)result).SqlStatement, Is.EqualTo(expectedStatement));
        }
コード例 #7
0
        public void VisitNotSupportedExpression_ThrowsNotImplentedException()
        {
            var expression = new CustomExpression(typeof(int));
            var result     = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.EqualTo(expression));
        }
コード例 #8
0
        public void VisitMemberExpression_WithProperty_NotRegistered()
        {
            var memberExpression = Expression.Property(Expression.Constant(new TypeWithMember <int> (5)), "Property");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.SameAs(memberExpression));
        }
コード例 #9
0
        public void VisitConstantExpression_WithNoCollection_LeavesExpressionUnchanged()
        {
            var constantExpression = Expression.Constant("string");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(constantExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.SameAs(constantExpression));
        }
コード例 #10
0
        public void VisitQuerySourceReferenceExpression_CreatesSqlTableReferenceExpression()
        {
            var result = SqlPreparationExpressionVisitor.TranslateExpression(_cookQuerySourceReferenceExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlTableReferenceExpression)));
            Assert.That(((SqlTableReferenceExpression)result).SqlTable, Is.SameAs(_sqlTable));
            Assert.That(result.Type, Is.SameAs(typeof(Cook)));
        }
コード例 #11
0
        public void VisitBinaryExpression_QuerySourceReferenceExpressionsOnBothSide()
        {
            var binaryExpression = Expression.Equal(_cookQuerySourceReferenceExpression, _cookQuerySourceReferenceExpression);
            var result           = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.AssignableTo(typeof(BinaryExpression)));
            Assert.That(((BinaryExpression)result).Left, Is.TypeOf(typeof(SqlTableReferenceExpression)));
            Assert.That(((BinaryExpression)result).Right, Is.TypeOf(typeof(SqlTableReferenceExpression)));
        }
コード例 #12
0
        public void VisitBinaryExpression_ReturnsSqlIsNullExpression_NullLeft()
        {
            var leftExpression   = Expression.Constant(null);
            var binaryExpression = Expression.Equal(leftExpression, _cookQuerySourceReferenceExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlIsNullExpression)));
            Assert.That(((SqlIsNullExpression)result).Expression, Is.TypeOf(typeof(SqlTableReferenceExpression)));
        }
コード例 #13
0
        public void VisitMemberExpression_WithProperty_Registered()
        {
            var stringExpression = Expression.Constant("test");
            var memberExpression = Expression.Property(stringExpression, "Length");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedResult = new SqlLengthExpression(stringExpression);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
コード例 #14
0
        public void VisitBinaryExpression_ReturnsSqlIsNotNullExpression_NullRight()
        {
            var rightExpression  = Expression.Constant(null);
            var leftExpression   = Expression.Constant("1");
            var binaryExpression = Expression.NotEqual(leftExpression, rightExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlIsNotNullExpression)));
            Assert.That(((SqlIsNotNullExpression)result).Expression, Is.SameAs(leftExpression));
        }
コード例 #15
0
        public void VisitConstantExpression_WithCollection_ReturnsSqlCollectionExpression()
        {
            var constantExpression = Expression.Constant(new[] { 1, 2, 3 });

            var result = SqlPreparationExpressionVisitor.TranslateExpression(constantExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedExpression = new SqlCollectionExpression(
                typeof(int[]), new[] { Expression.Constant(1), Expression.Constant(2), Expression.Constant(3) });

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
コード例 #16
0
        public void VisitBinaryExpression_NotEqual_WithNullOnLeftSide()
        {
            var leftExpression   = Expression.Constant(null);
            var binaryExpression = Expression.Coalesce(leftExpression, _cookQuerySourceReferenceExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.AssignableTo(typeof(BinaryExpression)));
            Assert.That(((BinaryExpression)result).Left, Is.TypeOf(typeof(ConstantExpression)));
            Assert.That(((BinaryExpression)result).Right, Is.TypeOf(typeof(SqlTableReferenceExpression)));
        }
コード例 #17
0
        public void VisitPartialEvaluationExceptionExpression_StripsExceptionAndVisitsInnerExpression()
        {
            var evaluatedExpression = Expression.Property(Expression.Constant(""), "Length");
            var exception           = new InvalidOperationException("What?");
            var expression          = new PartialEvaluationExceptionExpression(exception, evaluatedExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedExpression = new SqlLengthExpression(evaluatedExpression.Expression);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
コード例 #18
0
        public void VisitSqlSubStatmentExpression_NoTopExpression_ReturnsSame()
        {
            var builder = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatementWithCook());

            builder.Orderings.Clear();
            var sqlStatement = builder.GetSqlStatement();

            var subStatementExpression = new SqlSubStatementExpression(sqlStatement);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(subStatementExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.SameAs(subStatementExpression));
        }
コード例 #19
0
        public void VisitMethodCallExpression()
        {
            var method               = typeof(string).GetMethod("ToUpper", new Type[] { });
            var constantExpression   = Expression.Constant("Test");
            var methodCallExpression = Expression.Call(constantExpression, method);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(methodCallExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlFunctionExpression)));
            Assert.That(((SqlFunctionExpression)result).SqlFunctioName, Is.EqualTo("UPPER"));
            Assert.That(((SqlFunctionExpression)result).Args[0], Is.SameAs(constantExpression));
            Assert.That(((SqlFunctionExpression)result).Args.Count, Is.EqualTo(1));
        }
コード例 #20
0
        public void VisitNewExpression_NoMembers()
        {
            var expression = Expression.New(TypeForNewExpression.GetConstructor(typeof(int)), new[] { Expression.Constant(0) });

            var result = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf(typeof(NewExpression)));
            Assert.That(result, Is.Not.SameAs(expression));
            Assert.That(((NewExpression)result).Arguments.Count, Is.EqualTo(1));
            Assert.That(((NewExpression)result).Arguments[0], Is.TypeOf(typeof(NamedExpression)));
            Assert.That(((NewExpression)result).Members, Is.Null);
            Assert.That(((NamedExpression)((NewExpression)result).Arguments[0]).Name, Is.EqualTo("m0"));
        }
コード例 #21
0
        public void VisitMethodCallExpression_TransformerNotRegistered_NoObject_WrapsArgumentsIntoNamedExpressions()
        {
            var methodCallExpression = Expression.Call(
                MemberInfoFromExpressionUtility.GetMethod(() => int.Parse("")),
                Expression.Constant(""));

            var result = SqlPreparationExpressionVisitor.TranslateExpression(methodCallExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expected = Expression.Call(
                MemberInfoFromExpressionUtility.GetMethod(() => int.Parse("")),
                new[] { new NamedExpression("Arg0", Expression.Constant("")) });

            SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result);
        }
コード例 #22
0
        public void VisitBinaryExpression_WithConditionalExpressionInBinaryExpression()
        {
            var leftExpression    = Expression.Constant("Name");
            var testPredicate     = Expression.Constant(true);
            var ifTrueExpression  = Expression.Constant("true");
            var ifFalseExpression = Expression.Constant("false");
            var rightExpression   = Expression.Condition(testPredicate, ifTrueExpression, ifFalseExpression);
            var binaryExpression  = Expression.Equal(leftExpression, rightExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(binaryExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedResult = Expression.Equal(
                leftExpression, SqlCaseExpression.CreateIfThenElse(typeof(string), testPredicate, ifTrueExpression, ifFalseExpression));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
コード例 #23
0
        public void VisitMethodCallExpression_TransformerNotRegistered_WrapsArgumentsIntoNamedExpressions()
        {
            var methodCallExpression = Expression.Call(
                Expression.Constant(0),
                MemberInfoFromExpressionUtility.GetMethod(() => 0.ToString ("", null)),
                Expression.Constant(""),
                Expression.Constant(null, typeof(IFormatProvider)));

            var result = SqlPreparationExpressionVisitor.TranslateExpression(methodCallExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expected = Expression.Call(
                new NamedExpression("Object", Expression.Constant(0)),
                MemberInfoFromExpressionUtility.GetMethod(() => 0.ToString ("", null)),
                new[] { new NamedExpression("Arg0", Expression.Constant("")), new NamedExpression("Arg1", Expression.Constant(null, typeof(IFormatProvider))) });

            SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result);
        }
コード例 #24
0
        public void VisitConditionalExpression_VisitsSubExpressions()
        {
            var testPredicate         = Expression.Equal(Expression.Constant("test"), Expression.Constant(null, typeof(string)));
            var ifTrueExpression      = Expression.Equal(Expression.Constant("test"), Expression.Constant(null, typeof(string)));
            var ifFalseExpression     = Expression.Equal(Expression.Constant("test"), Expression.Constant(null, typeof(string)));
            var conditionalExpression = Expression.Condition(testPredicate, ifTrueExpression, ifFalseExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(conditionalExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlCaseExpression)));
            var sqlCaseExpression = (SqlCaseExpression)result;

            Assert.That(sqlCaseExpression.Cases, Has.Count.EqualTo(1));
            Assert.That(sqlCaseExpression.Cases[0].When, Is.TypeOf <SqlIsNullExpression>());
            Assert.That(sqlCaseExpression.Cases[0].Then, Is.TypeOf <SqlIsNullExpression> ());
            Assert.That(sqlCaseExpression.ElseCase, Is.TypeOf <SqlIsNullExpression> ());
        }
コード例 #25
0
        public void VisitMemberExpression_WithInnerCoalesceExpression_RevisitsResult()
        {
            var left  = Expression.Constant("left");
            var right = Expression.Constant("right");
            var coalesceExpression = Expression.Coalesce(left, right);
            var memberExpression   = Expression.Property(coalesceExpression, "Length");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedResult = SqlCaseExpression.CreateIfThenElse(
                typeof(int),
                new SqlIsNotNullExpression(coalesceExpression.Left),
                new SqlLengthExpression(coalesceExpression.Left),
                new SqlLengthExpression(coalesceExpression.Right));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
コード例 #26
0
        public void VisitSqlSubStatmentExpression_HasTopExpression_ReturnsNew()
        {
            var builder = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatementWithCook());

            builder.Orderings.Add(new Ordering(Expression.Constant("order"), OrderingDirection.Asc));
            var sqlStatement = builder.GetSqlStatement();

            builder.Orderings.Clear();
            var expectedStatement = builder.GetSqlStatement();

            var subStatementExpression = new SqlSubStatementExpression(sqlStatement);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(subStatementExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.Not.SameAs(subStatementExpression));
            Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression)));
            Assert.That(((SqlSubStatementExpression)result).SqlStatement, Is.EqualTo(expectedStatement));
        }
コード例 #27
0
        public void VisitConditionalExpression()
        {
            var testPredicate         = Expression.Constant(true);
            var ifTrueExpression      = Expression.Constant("true");
            var ifFalseExpression     = Expression.Constant("false");
            var conditionalExpression = Expression.Condition(testPredicate, ifTrueExpression, ifFalseExpression);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(conditionalExpression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlCaseExpression)));
            var sqlCaseExpression = (SqlCaseExpression)result;

            Assert.That(sqlCaseExpression.Type, Is.SameAs(typeof(string)));
            Assert.That(sqlCaseExpression.Cases, Has.Count.EqualTo(1));
            Assert.That(sqlCaseExpression.Cases[0].When, Is.EqualTo(testPredicate));
            Assert.That(sqlCaseExpression.Cases[0].Then, Is.EqualTo(ifTrueExpression));
            Assert.That(sqlCaseExpression.ElseCase, Is.EqualTo(ifFalseExpression));
        }
コード例 #28
0
        public void VisitMemberExpression_WithInnerSqlCaseExpression_RevisitsResult()
        {
            var predicate = Expression.Constant(true);
            var value     = Expression.Constant("value1");
            var elseValue = Expression.Constant("value2");

            var caseExpression   = new SqlCaseExpression(typeof(string), new[] { new SqlCaseExpression.CaseWhenPair(predicate, value) }, elseValue);
            var memberExpression = Expression.Property(caseExpression, "Length");

            var result = SqlPreparationExpressionVisitor.TranslateExpression(memberExpression, _context, _stageMock, _methodCallTransformerProvider);

            var expectedResult = new SqlCaseExpression(
                typeof(int),
                new[] { new SqlCaseExpression.CaseWhenPair(predicate, new SqlLengthExpression(value)) },
                new SqlLengthExpression(elseValue));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
コード例 #29
0
        public void VisitSubqueryExpressionTest_WithSqlTables()
        {
            var mainFromClause          = ExpressionHelper.CreateMainFromClause <Cook>();
            var querModel               = ExpressionHelper.CreateQueryModel(mainFromClause);
            var expression              = new SubQueryExpression(querModel);
            var fakeSqlStatementBuilder = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatement());

            fakeSqlStatementBuilder.SqlTables.Add(_sqlTable);
            var fakeSqlStatement = fakeSqlStatementBuilder.GetSqlStatement();

            _stageMock
            .Expect(mock => mock.PrepareSqlStatement(querModel, _context))
            .Return(fakeSqlStatement);

            var result = SqlPreparationExpressionVisitor.TranslateExpression(expression, _context, _stageMock, _methodCallTransformerProvider);

            Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression)));
            Assert.That(((SqlSubStatementExpression)result).SqlStatement, Is.SameAs(fakeSqlStatement));
        }
コード例 #30
0
        public void VisitMethodCallExpression_ExpressionPropertiesVisitedBeforeTransformation()
        {
            var method = MethodCallTransformerUtility.GetInstanceMethod(typeof(object), "ToString");
            var methodCallExpression = Expression.Call(_cookQuerySourceReferenceExpression, method);

            var transformerMock = MockRepository.GenerateMock <IMethodCallTransformer>();

            transformerMock
            .Expect(mock => mock.Transform(Arg.Is(methodCallExpression)))
            .Return(methodCallExpression);
            transformerMock.Replay();

            var registry = new MethodInfoBasedMethodCallTransformerRegistry();

            registry.Register(method, transformerMock);

            SqlPreparationExpressionVisitor.TranslateExpression(methodCallExpression, _context, _stageMock, registry);

            transformerMock.VerifyAllExpectations();
        }