public void ResolveSqlTable_ResolvesJoinInfo() { var memberInfo = typeof(Kitchen).GetProperty("Cook"); var entityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Kitchen)); var unresolvedJoinInfo = new UnresolvedJoinInfo(entityExpression, memberInfo, JoinCardinality.One); var join = _sqlTable.GetOrAddLeftJoin(unresolvedJoinInfo, memberInfo); var fakeResolvedJoinInfo = SqlStatementModelObjectMother.CreateResolvedJoinInfo(typeof(Cook)); using (_stageMock.GetMockRepository().Ordered()) { _stageMock .Expect(mock => mock.ResolveTableInfo(_unresolvedTableInfo, _mappingResolutionContext)) .Return(_fakeResolvedSimpleTableInfo); _stageMock .Expect(mock => mock.ResolveJoinInfo(join.JoinInfo, _mappingResolutionContext)) .Return(fakeResolvedJoinInfo); } _stageMock.Replay(); _visitor.ResolveSqlTable(_sqlTable); _stageMock.VerifyAllExpectations(); Assert.That(join.JoinInfo, Is.SameAs(fakeResolvedJoinInfo)); }
public void GenerateSql_ForJoinedTable_Recursive() { var originalTable = new SqlTable(new ResolvedSimpleTableInfo(typeof(Kitchen), "KitchenTable", "t1"), JoinSemantics.Inner); var memberInfo1 = typeof(Kitchen).GetProperty("Cook"); var memberInfo2 = typeof(Cook).GetProperty("Substitution"); var joinedTable1 = originalTable.GetOrAddLeftJoin(CreateResolvedJoinInfo(typeof(Cook), "t1", "ID", "CookTable", "t2", "FK"), memberInfo1); var joinedTable2 = joinedTable1.GetOrAddLeftJoin(CreateResolvedJoinInfo(typeof(Cook), "t2", "ID2", "CookTable2", "t3", "FK2"), memberInfo2); _stageMock .Expect(mock => mock.GenerateTextForJoinCondition(_commandBuilder, ((ResolvedJoinInfo)joinedTable1.JoinInfo).JoinCondition)) .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("X")); _stageMock .Expect(mock => mock.GenerateTextForJoinCondition(_commandBuilder, ((ResolvedJoinInfo)joinedTable2.JoinInfo).JoinCondition)) .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("Y")); _stageMock.Replay(); SqlTableAndJoinTextGenerator.GenerateSql(originalTable, _commandBuilder, _stageMock, true); _stageMock.VerifyAllExpectations(); Assert.That( _commandBuilder.GetCommandText(), Is.EqualTo( "[KitchenTable] AS [t1] LEFT OUTER JOIN " + "[CookTable] AS [t2] ON X LEFT OUTER JOIN " + "[CookTable2] AS [t3] ON Y")); }
public void ToString_WithJoins() { var joinInfo = SqlStatementModelObjectMother.CreateUnresolvedJoinInfo_KitchenCook(); var memberInfo = typeof(Kitchen).GetProperty("Cook"); _sqlTable.GetOrAddLeftJoin(joinInfo, memberInfo); var result = _sqlTable.ToString(); Assert.That(result, Is.EqualTo("[table1] [t] LEFT JOIN Kitchen.Cook")); }
public void GenerateSql_WithUnresolvedCollectionJoinInfo() { var originalTable = new SqlTable(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), JoinSemantics.Inner); var memberInfo = typeof(Restaurant).GetProperty("Cooks"); var collectionJoinInfo = new UnresolvedCollectionJoinInfo(Expression.Constant(new Cook[] { }), memberInfo); originalTable.GetOrAddLeftJoin(collectionJoinInfo, memberInfo); Assert.That( () => SqlTableAndJoinTextGenerator.GenerateSql(originalTable, _commandBuilder, _stageMock, false), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("UnresolvedCollectionJoinInfo is not valid at this point.")); }
public void GenerateSql_WithUnresolvedJoinInfo() { var originalTable = new SqlTable(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), JoinSemantics.Inner); var kitchenCookMember = typeof(Kitchen).GetProperty("Cook"); var entityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Kitchen)); var unresolvedJoinInfo = new UnresolvedJoinInfo(entityExpression, kitchenCookMember, JoinCardinality.One); originalTable.GetOrAddLeftJoin(unresolvedJoinInfo, kitchenCookMember); Assert.That( () => SqlTableAndJoinTextGenerator.GenerateSql(originalTable, _commandBuilder, _stageMock, false), Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("UnresolvedJoinInfo is not valid at this point.")); }
public void GenerateSql_ForJoinedTable() { var originalTable = new SqlTable(new ResolvedSimpleTableInfo(typeof(Kitchen), "KitchenTable", "t1"), JoinSemantics.Inner); var kitchenCookMember = typeof(Kitchen).GetProperty("Cook"); var joinedTable = originalTable.GetOrAddLeftJoin(CreateResolvedJoinInfo(typeof(Cook), "t1", "ID", "CookTable", "t2", "FK"), kitchenCookMember); joinedTable.JoinInfo = CreateResolvedJoinInfo(typeof(Cook), "t1", "ID", "CookTable", "t2", "FK"); _stageMock .Expect(mock => mock.GenerateTextForJoinCondition(_commandBuilder, ((ResolvedJoinInfo)joinedTable.JoinInfo).JoinCondition)) .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("([t1].[ID] = [t2].[FK])")); _stageMock.Replay(); SqlTableAndJoinTextGenerator.GenerateSql(originalTable, _commandBuilder, _stageMock, true); _stageMock.VerifyAllExpectations(); Assert.That( _commandBuilder.GetCommandText(), Is.EqualTo("[KitchenTable] AS [t1] LEFT OUTER JOIN [CookTable] AS [t2] ON ([t1].[ID] = [t2].[FK])")); }