public void ResolveTableInfo_Unresolved()
        {
            var resolvedTableInfo = new ResolvedSimpleTableInfo(typeof(int), "Table", "t");

            _resolverMock.Expect(mock => mock.ResolveTableInfo(_unresolvedTableInfo, _generator)).Return(resolvedTableInfo);
            _resolverMock.Replay();

            var result = ResolvingTableInfoVisitor.ResolveTableInfo(resolvedTableInfo, _resolverMock, _generator, _stageMock, _mappingResolutionContext);

            Assert.That(result, Is.SameAs(resolvedTableInfo));
        }
        public void ResolvePotentialEntity_EntityRefMember_OptimizesReferenceViaResolver()
        {
            var fakeOptimizedIdentity = ExpressionHelper.CreateExpression();

            _resolverMock
            .Expect(mock => mock.TryResolveOptimizedIdentity(_entityRefMemberExpression))
            .Return(fakeOptimizedIdentity);

            var result = _entityIdentityResolver.ResolvePotentialEntity(_entityRefMemberExpression);

            _resolverMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeOptimizedIdentity));
        }
Exemplo n.º 3
0
        public void ResolveMemberAccess_OnEntity()
        {
            var memberInfo          = typeof(Cook).GetProperty("Substitution");
            var sqlEntityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook));
            var fakeResult          = Expression.Constant(0);

            _resolverMock
            .Expect(mock => mock.ResolveMemberExpression(sqlEntityExpression, memberInfo))
            .Return(fakeResult);
            _resolverMock.Replay();

            var result = MemberAccessResolver.ResolveMemberAccess(sqlEntityExpression, memberInfo, _resolverMock, _stageMock, _mappingResolutionContext);

            _resolverMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeResult));
        }
Exemplo n.º 4
0
        public void VisitSqlSubStatementExpression_ConvertsToSqlTable_ForStreamedSingleValueInfo()
        {
            var sqlStatement             = SqlStatementModelObjectMother.CreateSqlStatement_Single();
            var fakeResolvedSqlStatement = SqlStatementModelObjectMother.CreateSqlStatement_Single();
            var expression = new SqlSubStatementExpression(sqlStatement);

            var      resolvedReference = Expression.Constant("fake");
            SqlTable sqlTable          = null;

            _stageMock
            .Expect(mock => mock.ResolveSqlStatement(sqlStatement, _mappingResolutionContext))
            .Return(fakeResolvedSqlStatement);
            _groupAggregateSimplifier
            .Expect(
                mock => mock.SimplifyIfPossible(
                    Arg <SqlSubStatementExpression> .Matches(e => e.SqlStatement == fakeResolvedSqlStatement), Arg.Is(sqlStatement.SelectProjection)))
            .Return(null)
            .WhenCalled(mi => mi.ReturnValue = mi.Arguments[0]);
            _stageMock
            .Expect(mock => mock.ResolveTableReferenceExpression(Arg <SqlTableReferenceExpression> .Is.Anything, Arg.Is(_mappingResolutionContext)))
            .WhenCalled(
                mi =>
            {
                var expectedStatement =
                    new SqlStatementBuilder(fakeResolvedSqlStatement)
                {
                    DataInfo = new StreamedSequenceInfo(typeof(IEnumerable <int>), fakeResolvedSqlStatement.SelectProjection)
                }.GetSqlStatement();
                sqlTable = (SqlTable)((SqlTableReferenceExpression)mi.Arguments[0]).SqlTable;
                Assert.That(((ResolvedSubStatementTableInfo)sqlTable.TableInfo).SqlStatement, Is.EqualTo(expectedStatement));
            })
            .Return(resolvedReference);

            _resolverMock.Expect(mock => mock.ResolveConstantExpression(resolvedReference)).Return(resolvedReference);

            var sqlStatementBuilder = new SqlStatementBuilder(sqlStatement);
            var visitor             = CreateVisitor(sqlStatementBuilder);

            Assert.That(sqlStatementBuilder.SqlTables.Count, Is.EqualTo(0));

            var result = visitor.VisitExpression(expression);

            _stageMock.VerifyAllExpectations();
            _groupAggregateSimplifier.VerifyAllExpectations();
            _resolverMock.VerifyAllExpectations();

            Assert.That(result, Is.SameAs(resolvedReference));
            Assert.That(sqlStatementBuilder.SqlTables.Count, Is.EqualTo(1));
            Assert.That(sqlStatementBuilder.SqlTables[0], Is.EqualTo(sqlTable));
        }
Exemplo n.º 5
0
        public void ResolveJoinInfo_ResolvesUnresolvedJoinInfo()
        {
            var foreignTableInfo = new ResolvedSimpleTableInfo(typeof(string), "Cook", "c");
            var condition        = ExpressionHelper.CreateExpression(typeof(bool));

            var resolvedJoinInfo = new ResolvedJoinInfo(foreignTableInfo, condition);

            _resolverMock
            .Expect(mock => mock.ResolveJoinInfo(_unresolvedJoinInfo, _generator))
            .Return(resolvedJoinInfo);

            _stageMock
            .Expect(mock => mock.ResolveTableInfo(foreignTableInfo, _mappingResolutionContext))
            .Return(foreignTableInfo);
            _stageMock
            .Expect(mock => mock.ResolveJoinCondition(condition, _mappingResolutionContext))
            .Return(condition);

            var result = ResolvingJoinInfoVisitor.ResolveJoinInfo(_unresolvedJoinInfo, _resolverMock, _generator, _stageMock, _mappingResolutionContext);

            Assert.That(result, Is.SameAs(resolvedJoinInfo));
            _resolverMock.VerifyAllExpectations();
            _stageMock.VerifyAllExpectations();
        }
        public void VisitConstantExpression()
        {
            var constantExpression = Expression.Constant(0);

            _stageMock.Replay();
            _resolverMock
            .Expect(mock => mock.ResolveConstantExpression(constantExpression))
            .Return(constantExpression);
            _resolverMock.Replay();

            var result = _visitor.Visit(constantExpression);

            _stageMock.VerifyAllExpectations();
            _resolverMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(constantExpression));
        }
        public void ResolveSelectExpression()
        {
            var expression          = Expression.Constant(true);
            var sqlStatementBuilder = new SqlStatementBuilder();
            var fakeResult          = Expression.Constant(0);

            _resolverMock
            .Expect(mock => mock.ResolveConstantExpression(expression))
            .Return(fakeResult);
            _resolverMock
            .Expect(mock => mock.ResolveConstantExpression(fakeResult))
            .Return(fakeResult);
            _resolverMock.Replay();

            var result = _stage.ResolveSelectExpression(expression, sqlStatementBuilder, _mappingResolutionContext);

            _resolverMock.VerifyAllExpectations();

            Assert.That(result, Is.TypeOf(typeof(ConstantExpression)));
            Assert.That(((ConstantExpression)result).Value, Is.EqualTo(0));
        }