public void VisitJoinConditionExpression()
        {
            var resolvedTableInfo       = new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c");
            var leftKey                 = new SqlColumnDefinitionExpression(typeof(Cook), "c", "ID", false);
            var rightKey                = new SqlColumnDefinitionExpression(typeof(Cook), "a", "FK", false);
            var joinInfo                = new ResolvedJoinInfo(resolvedTableInfo, Expression.Equal(leftKey, rightKey));
            var sqlTable                = new SqlJoinedTable(joinInfo, JoinSemantics.Left);
            var joinConditionExpression = new JoinConditionExpression(sqlTable);

            _entityIdentityResolverMock
            .Expect(
                mock => mock.ResolvePotentialEntityComparison(
                    Arg <BinaryExpression> .Matches(b => b.Left == leftKey && b.Right == rightKey)))
            .Return(null)
            .WhenCalled(mi => mi.ReturnValue = mi.Arguments[0]);
            _compoundComparisonSplitterMock
            .Expect(
                mock => mock.SplitPotentialCompoundComparison(
                    Arg <BinaryExpression> .Matches(b => b.Left == leftKey && b.Right == rightKey)))
            .Return(null)
            .WhenCalled(mi => mi.ReturnValue = mi.Arguments[0]);

            var result = _visitor.Visit(joinConditionExpression);

            _entityIdentityResolverMock.VerifyAllExpectations();
            _compoundComparisonSplitterMock.VerifyAllExpectations();

            var expectedExpression = Expression.Equal(leftKey, rightKey);

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedExpression, result);
        }
Пример #2
0
        public void ResolveJoinInfo_ResolvesUnresolvedJoinInfo_AndResolvesJoinedTable()
        {
            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);

            var fakeResolvedForeignTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo(typeof(string));

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

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

            Assert.That(result, Is.Not.SameAs(resolvedJoinInfo));
            Assert.That(result.ForeignTableInfo, Is.SameAs(fakeResolvedForeignTableInfo));
            Assert.That(result.JoinCondition, Is.SameAs(condition));
            _resolverMock.VerifyAllExpectations();
            _stageMock.VerifyAllExpectations();
        }
Пример #3
0
        public new void ToString()
        {
            var foreignTableInfo = new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c");
            var joinInfo         = new ResolvedJoinInfo(foreignTableInfo, Expression.Equal(Expression.Constant(0), Expression.Constant(1)));
            var result           = joinInfo.ToString();

            Assert.That(result, Is.EqualTo("[CookTable] [c] ON (0 == 1)"));
        }
Пример #4
0
        public void ToString_Resolved()
        {
            var resolvedJoinInfo = new ResolvedJoinInfo(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), Expression.Constant(true));
            var expression       = new JoinConditionExpression(new SqlJoinedTable(resolvedJoinInfo, JoinSemantics.Left));

            var result = expression.ToString();

            Assert.That(result, Is.EqualTo("CONDITION(LEFT JOIN [CookTable] [c] ON True)"));
        }
Пример #5
0
        public void Initialization_NullableBooleanJoinCondition()
        {
            var foreignTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo();
            var joinCondition    = ExpressionHelper.CreateExpression(typeof(bool?));

            var joinInfo = new ResolvedJoinInfo(foreignTableInfo, joinCondition);

            Assert.That(joinInfo.ForeignTableInfo, Is.SameAs(foreignTableInfo));
            Assert.That(joinInfo.JoinCondition, Is.SameAs(joinCondition));
        }
        public void GenerateSql_JoinedTable_WithInnerJoinSemantics()
        {
            var condition = Expression.Constant(true);
            var joinInfo  = new ResolvedJoinInfo(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), condition);

            var sqlTable = new SqlTable(new SqlJoinedTable(joinInfo, JoinSemantics.Inner), JoinSemantics.Inner);

            Assert.That(
                () => SqlTableAndJoinTextGenerator.GenerateSql(sqlTable, _commandBuilder, _stageMock, isFirstTable: true),
                Throws.TypeOf <InvalidOperationException>().With.Message.EqualTo("SqlJoinedTable as TableInfo is not valid at this point."));
        }
Пример #7
0
        public IJoinInfo VisitResolvedJoinInfo(ResolvedJoinInfo joinInfo)
        {
            ArgumentUtility.CheckNotNull("joinInfo", joinInfo);
            var newForeignTableInfo = _stage.ResolveTableInfo(joinInfo.ForeignTableInfo, _context);
            var newCondition        = _stage.ResolveJoinCondition(joinInfo.JoinCondition, _context);

            if (newForeignTableInfo != joinInfo.ForeignTableInfo || newCondition != joinInfo.JoinCondition)
            {
                return(new ResolvedJoinInfo(newForeignTableInfo, newCondition));
            }
            return(joinInfo);
        }
        public IJoinInfo VisitResolvedJoinInfo(ResolvedJoinInfo joinInfo)
        {
            ArgumentUtility.CheckNotNull("joinInfo", joinInfo);

            var newTableInfo = (IResolvedTableInfo)_stage.ApplyContext(joinInfo.ForeignTableInfo, _expressionContext, _mappingResolutionContext);

            if (joinInfo.ForeignTableInfo != newTableInfo)
            {
                return(new ResolvedJoinInfo(newTableInfo, joinInfo.JoinCondition));
            }
            return(joinInfo);
        }
Пример #9
0
        public IJoinInfo VisitResolvedJoinInfo(ResolvedJoinInfo joinInfo)
        {
            ArgumentUtility.CheckNotNull("joinInfo", joinInfo);

            joinInfo.ForeignTableInfo.Accept(this);

            _commandBuilder.Append(" ON ");

            _stage.GenerateTextForJoinCondition(_commandBuilder, joinInfo.JoinCondition);

            return(joinInfo);
        }
 public override void SetUp()
 {
     base.SetUp();
     _storageSpecificExpressionResolverStub = MockRepository.GenerateStub <IStorageSpecificExpressionResolver>();
     _storageNameProviderStub = MockRepository.GenerateStub <IStorageNameProvider>();
     _storageNameProviderStub.Stub(stub => stub.GetIDColumnName()).Return("ID");
     _storageNameProviderStub.Stub(stub => stub.GetClassIDColumnName()).Return("ClassID");
     _storageNameProviderStub.Stub(stub => stub.GetTimestampColumnName()).Return("Timestamp");
     _resolver                       = new MappingResolver(_storageSpecificExpressionResolverStub);
     _generator                      = new UniqueIdentifierGenerator();
     _orderTable                     = new SqlTable(new ResolvedSimpleTableInfo(typeof(Order), "Order", "o"), JoinSemantics.Inner);
     _fakeSimpleTableInfo            = new ResolvedSimpleTableInfo(typeof(Order), "OrderTable", "o");
     _fakeColumnDefinitionExpression = new SqlColumnDefinitionExpression(typeof(int), "o", "ColumnName", false);
     _fakeJoinInfo                   = new ResolvedJoinInfo(_fakeSimpleTableInfo, Expression.Constant(true));
 }
        public void VisitResolvedJoinInfo()
        {
            var condition        = Expression.Constant(true);
            var resolvedJoinInfo = new ResolvedJoinInfo(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), condition);

            _stageMock
            .Expect(mock => mock.GenerateTextForJoinCondition(_commandBuilder, condition))
            .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("condition"));
            _stageMock.Replay();

            _generator.VisitResolvedJoinInfo(resolvedJoinInfo);

            _stageMock.VerifyAllExpectations();
            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[CookTable] AS [c] ON condition"));
        }
        public void GenerateSql_JoinedTable_WithLeftJoinSemantics()
        {
            var condition = Expression.Constant(true);
            var joinInfo  = new ResolvedJoinInfo(new ResolvedSimpleTableInfo(typeof(Cook), "CookTable", "c"), condition);

            var sqlTable = SqlStatementModelObjectMother.CreateSqlTable_WithResolvedTableInfo("KitchenTable", "k", JoinSemantics.Inner);

            sqlTable.GetOrAddLeftJoin(joinInfo, ExpressionHelper.GetMember <Kitchen> (k => k.Cook));

            _stageMock
            .Expect(mock => mock.GenerateTextForJoinCondition(_commandBuilder, condition))
            .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("condition"));

            SqlTableAndJoinTextGenerator.GenerateSql(sqlTable, _commandBuilder, _stageMock, isFirstTable: true);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[KitchenTable] AS [k] LEFT OUTER JOIN [CookTable] AS [c] ON condition"));
        }
        public void ApplyContext_JoinInfo()
        {
            var sqlStatement = new SqlStatementBuilder(SqlStatementModelObjectMother.CreateSqlStatement_Resolved(typeof(Cook)))
            {
                SelectProjection = Expression.Constant(true),
                DataInfo         = new StreamedSequenceInfo(typeof(Cook[]), Expression.Constant(new Cook()))
            }.GetSqlStatement();
            var tableInfo = new ResolvedSubStatementTableInfo("c", sqlStatement);
            var joinInfo  = new ResolvedJoinInfo(tableInfo, Expression.Equal(new SqlLiteralExpression(1), new SqlLiteralExpression(1)));

            var result = _stage.ApplyContext(joinInfo, SqlExpressionContext.ValueRequired, _mappingResolutionContext);

            Assert.That(result, Is.Not.SameAs(joinInfo));
            Assert.That(
                ((ResolvedSubStatementTableInfo)((ResolvedJoinInfo)result).ForeignTableInfo).SqlStatement.SelectProjection,
                Is.TypeOf(typeof(SqlConvertedBooleanExpression)));
            Assert.That(
                ((ConstantExpression)
                 ((SqlConvertedBooleanExpression)((ResolvedSubStatementTableInfo)((ResolvedJoinInfo)result).ForeignTableInfo).SqlStatement.SelectProjection)
                 .Expression).Value,
                Is.EqualTo(1));
        }