public void Create_WithOneUnionedTable()
        {
            var unionViewDefinition = UnionViewDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, null, _table1);

            var builder = new UnionSelectDbCommandBuilder(
                unionViewDefinition,
                _originalSelectedColumnsStub,
                _comparedColumnsStrictMock,
                _orderedColumnsStub,
                _sqlDialectStub);

            _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("customSchema")).Return("[delimited customSchema]");
            _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("Table1")).Return("[delimited Table1]");
            _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("FKID")).Return("[delimited FKID]");
            _sqlDialectStub.Stub(stub => stub.GetParameterName("FKID")).Return("pFKID");

            _orderedColumnsStub.Stub(stub => stub.UnionWithSelectedColumns(_originalSelectedColumnsStub)).Return(_fullSelectedColumnsStub);
            _orderedColumnsStub.Stub(stub => stub.IsEmpty).Return(false);
            _orderedColumnsStub
            .Stub(stub => stub.AppendOrderings(Arg <StringBuilder> .Is.Anything, Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[Column1] ASC, [Column2] DESC"));

            var adjustedSelectedColumnsStub = MockRepository.GenerateStub <ISelectedColumnsSpecification>();

            adjustedSelectedColumnsStub
            .Stub(stub => stub.AppendProjection(Arg <StringBuilder> .Is.Anything, Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[Column1], [Column2], [Column3]"));
            _fullSelectedColumnsStub
            .Stub(stub => stub.AdjustForTable(_table1))
            .Return(adjustedSelectedColumnsStub);

            _comparedColumnsStrictMock
            .Expect(stub => stub.AddParameters(_dbCommandStub, _sqlDialectStub))
            .Repeat.Once();
            _comparedColumnsStrictMock
            .Expect(stub => stub.AppendComparisons(
                        Arg <StringBuilder> .Is.Anything,
                        Arg.Is(_dbCommandStub),
                        Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[delimited FKID] = pFKID"))
            .Repeat.Once();
            _comparedColumnsStrictMock.Replay();

            var result = builder.Create(_commandExecutionContextStub);

            Assert.That(
                result.CommandText,
                Is.EqualTo("SELECT [Column1], [Column2], [Column3] FROM [delimited Table1] WHERE [delimited FKID] = pFKID ORDER BY [Column1] ASC, [Column2] DESC;"));
            _sqlDialectStub.VerifyAllExpectations();
            _comparedColumnsStrictMock.VerifyAllExpectations();
        }
Esempio n. 2
0
        public override void SetUp()
        {
            base.SetUp();

            _selectedColumnsStub = MockRepository.GenerateStub <ISelectedColumnsSpecification>();
            _selectedColumnsStub
            .Stub(stub => stub.AppendProjection(Arg <StringBuilder> .Is.Anything, Arg <ISqlDialect> .Is.Anything))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[Column1], [Column2], [Column3]"));
            _comparedColumnsStrictMock = MockRepository.GenerateStrictMock <IComparedColumnsSpecification> ();
            _orderedColumnsStub        = MockRepository.GenerateStub <IOrderedColumnsSpecification> ();

            _sqlDialectStub = MockRepository.GenerateStub <ISqlDialect>();
            _sqlDialectStub.Stub(stub => stub.StatementDelimiter).Return(";");
            _dbDataParameterStub         = MockRepository.GenerateStub <IDbDataParameter>();
            _dataParameterCollectionMock = MockRepository.GenerateStrictMock <IDataParameterCollection>();

            _dbCommandStub = MockRepository.GenerateStub <IDbCommand>();
            _dbCommandStub.Stub(stub => stub.CreateParameter()).Return(_dbDataParameterStub);
            _dbCommandStub.Stub(stub => stub.Parameters).Return(_dataParameterCollectionMock);

            _commandExecutionContextStub = MockRepository.GenerateStub <IRdbmsProviderCommandExecutionContext>();
            _commandExecutionContextStub.Stub(stub => stub.CreateDbCommand()).Return(_dbCommandStub);
        }