public void Create_DefaultSchema_WithOrderings() { var tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table")); var builder = new SelectDbCommandBuilder( tableDefinition, _selectedColumnsStub, _comparedColumnsStrictMock, _orderedColumnsStub, _sqlDialectStub); _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("Table")).Return("[delimited Table]"); _comparedColumnsStrictMock.Expect(stub => stub.AddParameters(_dbCommandStub, _sqlDialectStub)); _comparedColumnsStrictMock .Expect( stub => stub.AppendComparisons( Arg <StringBuilder> .Is.Anything, Arg.Is(_dbCommandStub), Arg.Is(_sqlDialectStub))) .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[ID] = @ID")); _comparedColumnsStrictMock.Replay(); _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("[Name] ASC, [City] DESC")); var result = builder.Create(_commandExecutionContextStub); _comparedColumnsStrictMock.VerifyAllExpectations(); Assert.That( result.CommandText, Is.EqualTo( "SELECT [Column1], [Column2], [Column3] FROM [delimited Table] WHERE [ID] = @ID ORDER BY [Name] ASC, [City] DESC;")); }
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(); }