public void ApplyContext_VisitResolvedJoinInfo_SameForeignTableInfo() { var resolvedJoinInfo = SqlStatementModelObjectMother.CreateResolvedJoinInfo(); _stageMock .Expect(mock => mock.ApplyContext(resolvedJoinInfo.ForeignTableInfo, SqlExpressionContext.ValueRequired, _mappingResolutionContext)) .Return(resolvedJoinInfo.ForeignTableInfo); _stageMock.Replay(); var result = SqlContextJoinInfoVisitor.ApplyContext(resolvedJoinInfo, SqlExpressionContext.ValueRequired, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(resolvedJoinInfo)); }
public void VisitSqlStatement_NoExpressionChanged_SameSqlStatementIsReturned() { var sqlStatement = SqlStatementModelObjectMother.CreateSqlStatementWithCook(); _stageMock .Expect(mock => mock.ApplyContext(sqlStatement.SelectProjection, SqlExpressionContext.ValueRequired, _mappingResolutionContext)) .Return(sqlStatement.SelectProjection); _stageMock.Replay(); var result = SqlContextSelectionAdjuster.ApplyContext(sqlStatement, SqlExpressionContext.ValueRequired, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); Assert.That(result.SelectProjection, Is.TypeOf(typeof(SqlTableReferenceExpression))); Assert.That(result.DataInfo, Is.SameAs(sqlStatement.DataInfo)); }
public void ResolveMemberAccess_OnEntityRefMemberExpression_NoOptimization() { var memberInfo = typeof(Cook).GetProperty("Substitution"); var entityRefMemberExpression = SqlStatementModelObjectMother.CreateSqlEntityRefMemberExpression(); _resolverMock .Stub(mock => mock.TryResolveOptimizedMemberExpression(entityRefMemberExpression, memberInfo)) .Return(null); var fakeEntityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook)); _stageMock .Expect( mock => mock.ResolveEntityRefMemberExpression( Arg.Is(entityRefMemberExpression), Arg <UnresolvedJoinInfo> .Matches(j => j.OriginatingEntity == entityRefMemberExpression.OriginatingEntity && j.MemberInfo == entityRefMemberExpression.MemberInfo && j.Cardinality == JoinCardinality.One), Arg.Is(_mappingResolutionContext))) .Return(fakeEntityExpression); var fakeResult = Expression.Constant(0); _resolverMock .Expect(mock => mock.ResolveMemberExpression(fakeEntityExpression, memberInfo)) .Return(fakeResult); var result = MemberAccessResolver.ResolveMemberAccess(entityRefMemberExpression, memberInfo, _resolverMock, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); _resolverMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(fakeResult)); }
public void CreateSqlQuery() { var fakePreparationResult = CreateSqlStatement(); _preparationStageMock .Expect(mock => mock.PrepareSqlStatement(_queryModel, null)) .Return(fakePreparationResult); var fakeResolutionResult = CreateSqlStatement(); _resolutionStageMock .Expect(mock => mock.ResolveSqlStatement(Arg.Is(fakePreparationResult), Arg <MappingResolutionContext> .Is.TypeOf)) .Return(fakeResolutionResult); _generationStageMock .Expect(mock => mock.GenerateTextForOuterSqlStatement(Arg <SqlCommandBuilder> .Is.TypeOf, Arg.Is(fakeResolutionResult))) .WhenCalled(mi => { var sqlCommandBuilder = ((SqlCommandBuilder)mi.Arguments[0]); sqlCommandBuilder.Append("TestTest"); sqlCommandBuilder.SetInMemoryProjectionBody(Expression.Constant(null)); }); var result = _sqlQueryGenerator.CreateSqlQuery(_queryModel); _preparationStageMock.VerifyAllExpectations(); _resolutionStageMock.VerifyAllExpectations(); _generationStageMock.VerifyAllExpectations(); Assert.That(result.SqlCommand.CommandText, Is.EqualTo("TestTest")); }
public void VisitSqlSubStatementExpression_LeavesSqlSubStatementExpression_ForStreamedSequenceInfo() { var sqlStatement = SqlStatementModelObjectMother.CreateSqlStatement(Expression.Constant(new Cook())); var expression = new SqlSubStatementExpression(sqlStatement); _stageMock .Expect(mock => mock.ResolveSqlStatement(sqlStatement, _mappingResolutionContext)) .Return(sqlStatement); _groupAggregateSimplifier .Expect(mock => mock.SimplifyIfPossible(expression, sqlStatement.SelectProjection)) .Return(expression); var visitor = CreateVisitor(new SqlStatementBuilder(sqlStatement)); var result = visitor.VisitExpression(expression); _stageMock.VerifyAllExpectations(); _groupAggregateSimplifier.VerifyAllExpectations(); Assert.That(result, Is.TypeOf(typeof(SqlSubStatementExpression))); Assert.That(((SqlSubStatementExpression)result).SqlStatement, Is.SameAs(sqlStatement)); }
public void VisitSqlTableReferenceExpression_ResolvesExpression() { var tableReferenceExpression = new SqlTableReferenceExpression(_sqlTable); var fakeResult = Expression.Constant(0); _stageMock .Expect(mock => mock.ResolveTableReferenceExpression(tableReferenceExpression, _mappingResolutionContext)) .Return(fakeResult); _stageMock.Replay(); _resolverMock .Expect(mock => mock.ResolveConstantExpression(fakeResult)) .Return(fakeResult); _resolverMock.Replay(); var result = _visitor.Visit(tableReferenceExpression); _stageMock.VerifyAllExpectations(); _resolverMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(fakeResult)); }
public void ResolveTableInfo_SubStatementTableInfo_SubStatementUnmodified() { var sqlSubStatementTableInfo = new ResolvedSubStatementTableInfo("c", _sqlStatement); _stageMock .Expect(mock => mock.ResolveSqlStatement(_sqlStatement, _mappingResolutionContext)) .Return(_sqlStatement); _resolverMock.Replay(); var result = (ResolvedSubStatementTableInfo)ResolvingTableInfoVisitor.ResolveTableInfo(sqlSubStatementTableInfo, _resolverMock, _generator, _stageMock, _mappingResolutionContext); _stageMock.VerifyAllExpectations(); Assert.That(result, Is.SameAs(sqlSubStatementTableInfo)); }
public void ApplyContext_ResolvedSubStatementTableInfo_SameTableInfo() { var subStatement = SqlStatementModelObjectMother.CreateSqlStatement_Resolved(typeof(Cook)); var subStatementTableInfo = new ResolvedSubStatementTableInfo("c", subStatement); _stageMock .Expect(mock => mock.ApplySelectionContext(subStatement, SqlExpressionContext.ValueRequired, _mappingresolutionContext)) .Return(subStatement); _stageMock.Replay(); var result = SqlContextTableInfoVisitor.ApplyContext(subStatementTableInfo, SqlExpressionContext.ValueRequired, _stageMock, _mappingresolutionContext); Assert.That(result, Is.SameAs(subStatementTableInfo)); _stageMock.VerifyAllExpectations(); }
public void ResolvePotentialEntity_EntityRefMember_NonOptimizable_ResolvesToJoinAndIdentity() { _resolverMock .Expect(mock => mock.TryResolveOptimizedIdentity(_entityRefMemberExpression)) .Return(null); var fakeResolvedEntity = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(); _stageMock .Expect( mock => mock.ResolveEntityRefMemberExpression( Arg.Is(_entityRefMemberExpression), Arg <UnresolvedJoinInfo> .Matches( e => e.OriginatingEntity == _entityRefMemberExpression.OriginatingEntity && e.MemberInfo == _entityRefMemberExpression.MemberInfo && e.Cardinality == JoinCardinality.One), Arg.Is(_context))) .Return(fakeResolvedEntity); var result = _entityIdentityResolver.ResolvePotentialEntity(_entityRefMemberExpression); _stageMock.VerifyAllExpectations(); SqlExpressionTreeComparer.CheckAreEqualTrees(fakeResolvedEntity.GetIdentityExpression(), result); }
public void SimplifyIfPossible_SimplifiableStatement_AddsAggregationAndReturnsReference() { Assert.That(_associatedGroupingSelectExpression.AggregationExpressions.Count, Is.EqualTo(0)); var expression = new SqlSubStatementExpression(_simplifiableResolvedSqlStatement); var preparedResolvedAggregate = new AggregationExpression( typeof(int), new NamedExpression("element", Expression.Constant("e")), AggregationModifier.Count); _stageMock .Expect(mock => mock.ResolveAggregationExpression(Arg <Expression> .Is.Anything, Arg.Is(_context))) .Return(preparedResolvedAggregate) .WhenCalled(mi => { var expectedReplacedAggregate = new AggregationExpression( typeof(int), ((NamedExpression)_associatedGroupingSelectExpression.ElementExpression).Expression, AggregationModifier.Count); SqlExpressionTreeComparer.CheckAreEqualTrees(expectedReplacedAggregate, (Expression)mi.Arguments[0]); }); _stageMock.Replay(); var result = _groupAggregateSimplifier.SimplifyIfPossible(expression, _simplifiableUnresolvedProjection); _stageMock.VerifyAllExpectations(); Assert.That(_associatedGroupingSelectExpression.AggregationExpressions.Count, Is.EqualTo(1)); Assert.That( ((NamedExpression)_associatedGroupingSelectExpression.AggregationExpressions[0]).Expression, Is.SameAs(preparedResolvedAggregate)); var expected = new SqlColumnDefinitionExpression(typeof(int), "q0", "a0", false); SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result); }
public void ResolveSqlTable_ResolvesTableInfo() { _stageMock .Expect(mock => mock.ResolveTableInfo(_unresolvedTableInfo, _mappingResolutionContext)) .Return(_fakeResolvedSimpleTableInfo); _stageMock.Replay(); _visitor.ResolveSqlTable(_sqlTable); _stageMock.VerifyAllExpectations(); Assert.That(_sqlTable.TableInfo, Is.SameAs(_fakeResolvedSimpleTableInfo)); }
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(); }