public void VisitAdditionalFromClause_WithWhereCondition_AddsWhereCondition()
        {
            var fromClause = ExpressionHelper.CreateAdditionalFromClause();

            var preparedTable = new SqlTable(SqlStatementModelObjectMother.CreateResolvedTableInfo(), JoinSemantics.Inner);
            // TODO RMLNQSQL-2: Add existing where condition and assert that the new where condition is added, does not replace the original one.
            var whereCondition             = ExpressionHelper.CreateExpression(typeof(bool));
            var preparedFromExpressionInfo = new FromExpressionInfo(
                preparedTable,
                new Ordering[] { },
                new SqlTableReferenceExpression(preparedTable),
                whereCondition);

            _stageMock
            .Expect(
                mock => mock.PrepareFromExpression(
                    Arg <Expression> .Matches(e => e == fromClause.FromExpression),
                    Arg <ISqlPreparationContext> .Matches(c => c != _context),
                    Arg <Func <ITableInfo, SqlTable> > .Is.Anything))
            .Return(preparedFromExpressionInfo);

            _stageMock.Replay();

            _visitor.VisitAdditionalFromClause(fromClause, _queryModel, 0);

            _stageMock.VerifyAllExpectations();

            Assert.That(_visitor.SqlStatementBuilder.WhereCondition, Is.SameAs(whereCondition));
        }
Example #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();
        }
 public void SetUp()
 {
     _stageMock                = MockRepository.GenerateMock <IMappingResolutionStage>();
     _resolverMock             = MockRepository.GenerateMock <IMappingResolver>();
     _unresolvedTableInfo      = SqlStatementModelObjectMother.CreateUnresolvedTableInfo(typeof(Cook));
     _resolvedTableInfo        = SqlStatementModelObjectMother.CreateResolvedTableInfo(typeof(Cook));
     _generator                = new UniqueIdentifierGenerator();
     _sqlStatement             = SqlStatementModelObjectMother.CreateSqlStatement_Resolved(typeof(Cook));
     _mappingResolutionContext = new MappingResolutionContext();
 }
Example #4
0
        public void Initialization_NonBooleanJoinCondition()
        {
            var foreignTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo();
            var joinCondition    = ExpressionHelper.CreateExpression(typeof(int));

            Assert.That(
                () => new ResolvedJoinInfo(foreignTableInfo, joinCondition),
                Throws.ArgumentException.With.Message.EqualTo(
                    "The join condition must have boolean (or nullable boolean) type.\r\nParameter name: joinCondition"));
        }
Example #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));
        }
Example #6
0
        public void SetUp()
        {
            _stageMock = MockRepository.GenerateStrictMock <IMappingResolutionStage>();
            _mappingResolutionContext = new MappingResolutionContext();

            _visitor = new TestableSqlStatementResolver(_stageMock, _mappingResolutionContext);

            _unresolvedTableInfo         = SqlStatementModelObjectMother.CreateUnresolvedTableInfo(typeof(Cook));
            _sqlTable                    = SqlStatementModelObjectMother.CreateSqlTable(_unresolvedTableInfo);
            _fakeResolvedSimpleTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo(typeof(Cook));
        }
        public void SetUp()
        {
            _resolverMock = MockRepository.GenerateMock <IMappingResolver>();
            _uniqueIdentifierGenerator = new UniqueIdentifierGenerator();

            _unresolvedTableInfo         = SqlStatementModelObjectMother.CreateUnresolvedTableInfo(typeof(Cook));
            _sqlTable                    = SqlStatementModelObjectMother.CreateSqlTable(_unresolvedTableInfo);
            _fakeResolvedSimpleTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo(typeof(Cook));

            _stage = new DefaultMappingResolutionStage(_resolverMock, _uniqueIdentifierGenerator);

            _mappingResolutionContext = new MappingResolutionContext();
        }
Example #8
0
        public void ResolveJoinInfo_WithResolvedJoinInfo_ReresolvesTableInfo_AndKeys()
        {
            var resolvedJoinInfo = SqlStatementModelObjectMother.CreateResolvedJoinInfo();

            var fakeResolvedTableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo();

            _stageMock
            .Expect(mock => mock.ResolveTableInfo(resolvedJoinInfo.ForeignTableInfo, _mappingResolutionContext))
            .Return(fakeResolvedTableInfo);
            var fakeResolvedJoinCondition = ExpressionHelper.CreateExpression(typeof(bool));

            _stageMock
            .Expect(mock => mock.ResolveJoinCondition(resolvedJoinInfo.JoinCondition, _mappingResolutionContext))
            .Return(fakeResolvedJoinCondition);

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

            _stageMock.VerifyAllExpectations();
            Assert.That(result.ForeignTableInfo, Is.SameAs(fakeResolvedTableInfo));
            Assert.That(result.JoinCondition, Is.SameAs(fakeResolvedJoinCondition));
        }
Example #9
0
 public void SetUp()
 {
     _tableInfo = SqlStatementModelObjectMother.CreateResolvedTableInfo();
 }