public override void SetUp() { base.SetUp(); _rdbmsPersistenceModelProvider = new RdbmsPersistenceModelProvider(); _dbCommandBuilderFactoryStrictMock = MockRepository.GenerateStrictMock <IDbCommandBuilderFactory>(); _objectReaderFactoryStrictMock = MockRepository.GenerateStrictMock <IObjectReaderFactory>(); _dbCommandBuilderStub = MockRepository.GenerateStub <IDbCommandBuilder> (); _dataContainerReaderStub = MockRepository.GenerateStub <IObjectReader <DataContainer> > (); _objectIDReaderStub = MockRepository.GenerateStub <IObjectReader <ObjectID> > (); _fakeStorageProviderCommandFactory = MockRepository.GenerateStub <IStorageProviderCommandFactory <IRdbmsProviderCommandExecutionContext> >(); _factory = new RelationLookupCommandFactory( _fakeStorageProviderCommandFactory, _dbCommandBuilderFactoryStrictMock, _rdbmsPersistenceModelProvider, _objectReaderFactoryStrictMock); _tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table1")); _unionViewDefinition = UnionViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "ViewName"), _tableDefinition); _foreignKeyValue = CreateObjectID(_tableDefinition); _foreignKeyStoragePropertyDefinitionStrictMock = MockRepository.GenerateStrictMock <IRdbmsStoragePropertyDefinition>(); _fakeComparedColumns = new[] { new ColumnValue(ColumnDefinitionObjectMother.IDColumn, _foreignKeyValue.Value) }; }
public override void SetUp() { base.SetUp(); _tableViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <TableDefinition> >(); _unionViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <UnionViewDefinition> >(); _filterViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <FilterViewDefinition> >(); _emptyViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <EmptyViewDefinition> >(); _builder = new ViewScriptBuilder( _tableViewElementFactoryStub, _unionViewElementFactoryStub, _filterViewElementFactoryStub, _emptyViewElementFactoryStub, new SqlCommentScriptElementFactory()); _tableDefinition1 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _tableDefinition2 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _unionViewDefinition1 = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _unionViewDefinition2 = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _filterViewDefinition1 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _filterViewDefinition2 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _emptyViewDefinition1 = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _emptyViewDefinition2 = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _fakeElement1 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement2 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement3 = MockRepository.GenerateStub <IScriptElement>(); }
public override void SetUp() { base.SetUp(); _indexScriptElementFactoryStub = MockRepository.GenerateStub <IIndexScriptElementFactory>(); _builder = new IndexScriptBuilder(_indexScriptElementFactoryStub, new SqlCommentScriptElementFactory()); _indexDefinition1 = MockRepository.GenerateStub <IIndexDefinition>(); _indexDefinition2 = MockRepository.GenerateStub <IIndexDefinition>(); _indexDefinition3 = MockRepository.GenerateStub <IIndexDefinition>(); _tableDefinition1 = TableDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition1 }); _tableDefinition2 = TableDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition2, _indexDefinition3 }); _unionViewDefinition1 = UnionViewDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition1 }); _unionViewDefinition2 = UnionViewDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition2, _indexDefinition3 }); _filterViewDefinition1 = FilterViewDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition1 }); _filterViewDefinition2 = FilterViewDefinitionObjectMother.CreateWithIndexes( SchemaGenerationFirstStorageProviderDefinition, new[] { _indexDefinition2, _indexDefinition3 }); _fakeElement1 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement2 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement3 = MockRepository.GenerateStub <IScriptElement>(); }
public void GetTableDefinition_UnionViewDefinition() { var unionViewDefinition = UnionViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"), _tableDefinition); var objectID = CreateObjectID(unionViewDefinition); _rdbmsPersistenceModelProviderStub.Stub(stub => stub.GetEntityDefinition(objectID.ClassDefinition)).Return(unionViewDefinition); _finder.GetTableDefinition(objectID); }
public void SetUp() { _validationRule = new ClassAboveTableIsAbstractValidationRule(); _abstractClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), isAbstract: true); _concreteClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), isAbstract: false); var storageProviderDefinition = new UnitTestStorageProviderStubDefinition("DefaultStorageProvider"); _tableDefinition = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName")); _unionViewDefinition = UnionViewDefinitionObjectMother.Create(storageProviderDefinition); _emptyViewDefinition = EmptyViewDefinitionObjectMother.Create(storageProviderDefinition); }
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(); }
public void GetCreateScript_GetDropScript_UnionViewDefinitionAdded() { var entityDefinition = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition); _builder.AddEntityDefinition(entityDefinition); var createScriptResult = _builder.GetCreateScript(); var dropScriptResult = _builder.GetDropScript(); Assert.That(((ScriptElementCollection)createScriptResult).Elements.Count, Is.EqualTo(1)); Assert.That(((ScriptStatement)((ScriptElementCollection)createScriptResult).Elements[0]).Statement, Is.EqualTo("-- Create all tables")); Assert.That(((ScriptElementCollection)dropScriptResult).Elements.Count, Is.EqualTo(1)); Assert.That(((ScriptStatement)((ScriptElementCollection)dropScriptResult).Elements[0]).Statement, Is.EqualTo("-- Drop all tables")); }
public override void SetUp() { base.SetUp(); _tableViewElementFactoryStub = MockRepository.GenerateStub <ISynonymScriptElementFactory <TableDefinition> >(); _unionViewElementFactoryStub = MockRepository.GenerateStub <ISynonymScriptElementFactory <UnionViewDefinition> >(); _filterViewElementFactoryStub = MockRepository.GenerateStub <ISynonymScriptElementFactory <FilterViewDefinition> >(); _emptyViewElementFactoryStub = MockRepository.GenerateStub <ISynonymScriptElementFactory <EmptyViewDefinition> >(); _builder = new SynonymScriptBuilder( _tableViewElementFactoryStub, _unionViewElementFactoryStub, _filterViewElementFactoryStub, _emptyViewElementFactoryStub, new SqlCommentScriptElementFactory()); _synonym1 = new EntityNameDefinition(null, "Synonym1"); _synonym2 = new EntityNameDefinition(null, "Synonym2"); _synonym3 = new EntityNameDefinition(null, "Synonym3"); _tableDefinition1 = TableDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym1 }); _tableDefinition2 = TableDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym2, _synonym3 }); _unionViewDefinition1 = UnionViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym1 }); _unionViewDefinition2 = UnionViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym2, _synonym3 }); _filterViewDefinition1 = FilterViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym1 }); _filterViewDefinition2 = FilterViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym2, _synonym3 }); _emptyViewDefinition1 = EmptyViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym1 }); _emptyViewDefinition2 = EmptyViewDefinitionObjectMother.CreateWithSynonyms( SchemaGenerationFirstStorageProviderDefinition, new[] { _synonym2, _synonym3 }); _fakeElement1 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement2 = MockRepository.GenerateStub <IScriptElement>(); _fakeElement3 = MockRepository.GenerateStub <IScriptElement>(); }
public override void SetUp() { base.SetUp(); _tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition); _filterViewDefinition = FilterViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "FilterView"), _tableDefinition); _unionViewDefinition = UnionViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "UnionView"), new[] { _tableDefinition }); _emptyViewDefinition = EmptyViewDefinitionObjectMother.Create(TestDomainStorageProviderDefinition); _mockRepository = new MockRepository(); _voidReceiverMock = _mockRepository.StrictMock <IVisitorCallReceiver> (); _nonVoidReceiverMock = _mockRepository.StrictMock <IVisitorCallReceiver <string> > (); }
public void SetUp() { _validationRule = new TableNamesAreDistinctWithinConcreteTableInheritanceHierarchyValidationRule(); _baseOfBaseClass = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(BaseOfBaseValidationDomainObjectClass)); _derivedBaseClass1 = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(BaseValidationDomainObjectClass), baseClass: _baseOfBaseClass); _derivedClass = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), baseClass: _derivedBaseClass1); _baseOfBaseClass.SetDerivedClasses(new[] { _derivedBaseClass1 }); _derivedBaseClass1.SetDerivedClasses(new[] { _derivedClass }); _derivedClass.SetDerivedClasses(new ClassDefinition[0]); var storageProviderDefinition = new UnitTestStorageProviderStubDefinition("DefaultStorageProvider"); _tableDefinition1 = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName1")); _tableDefinition2 = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName2")); _unionViewDefinition = UnionViewDefinitionObjectMother.Create(storageProviderDefinition); }
public void ResolveTable_UnionViewDefinitionWithSchemaName() { var unionViewDefinition = UnionViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition("schemaName", "UnionView"), new[] { (IRdbmsStorageEntityDefinition)_classDefinition.StorageEntityDefinition }); _classDefinition.SetStorageEntity(unionViewDefinition); _rdbmsPersistenceModelProviderStub .Stub(stub => stub.GetEntityDefinition(_classDefinition)) .Return(_classDefinition.StorageEntityDefinition as IRdbmsStorageEntityDefinition); var result = (ResolvedSimpleTableInfo)_storageSpecificExpressionResolver.ResolveTable(_classDefinition, "o"); Assert.That(result, Is.Not.Null); Assert.That(result.TableName, Is.EqualTo("schemaName.UnionView")); Assert.That(result.TableAlias, Is.EqualTo("o")); Assert.That(result.ItemType, Is.EqualTo(typeof(Order))); }
public void GetCreateScript_GetDropScript_UnionViewDefinitionAdded() { var entityDefinition = UnionViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "UnionView"), _tableDefinition1); _builder.AddEntityDefinition(entityDefinition); var createScriptResult = _builder.GetCreateScript(); var dropScriptResult = _builder.GetDropScript(); Assert.That(((ScriptElementCollection)createScriptResult).Elements.Count, Is.EqualTo(1)); Assert.That( ((ScriptStatement)((ScriptElementCollection)createScriptResult).Elements[0]).Statement, Is.EqualTo("-- Create foreign key constraints for tables that were created above")); Assert.That(((ScriptElementCollection)dropScriptResult).Elements.Count, Is.EqualTo(1)); Assert.That( ((ScriptStatement)((ScriptElementCollection)dropScriptResult).Elements[0]).Statement, Is.EqualTo("-- Drop foreign keys of all tables")); }
public override void SetUp() { base.SetUp(); _factory = new SqlUnionViewScriptElementFactory(); var property1 = SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column1"); var property2 = SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column2"); var tableDefinition1 = TableDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "TableName1"), null, ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty, SimpleStoragePropertyDefinitionObjectMother.TimestampProperty, new[] { property1 }); var tableDefinition2 = TableDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "TableName2"), null, ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty, SimpleStoragePropertyDefinitionObjectMother.TimestampProperty, new[] { property1, property2 }); _unionViewDefinitionWithCustomSchema = UnionViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "UnionView1"), new[] { tableDefinition1 }, ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty, SimpleStoragePropertyDefinitionObjectMother.TimestampProperty, new[] { property1 }); _unionViewDefinitionWithDefaultSchema = UnionViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "UnionView2"), new[] { tableDefinition1, tableDefinition2 }, ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty, SimpleStoragePropertyDefinitionObjectMother.TimestampProperty, new[] { property1, property2 }); }
public void CreateForSelect_UnionView() { var unionViewDefinition = UnionViewDefinitionObjectMother.Create( TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "UnionEntity"), _tableDefinition); var result = _factory.CreateForSelect( unionViewDefinition, new[] { _column1, _column2 }, new[] { _columnValue1, _columnValue2 }, new[] { _orderColumn1, _orderColumn2 }); Assert.That(result, Is.TypeOf(typeof(UnionSelectDbCommandBuilder))); var dbCommandBuilder = (UnionSelectDbCommandBuilder)result; Assert.That(dbCommandBuilder.UnionViewDefinition, Is.SameAs(unionViewDefinition)); Assert.That(((SelectedColumnsSpecification)dbCommandBuilder.SelectedColumns).SelectedColumns, Is.EqualTo(new[] { _column1, _column2 })); Assert.That( ((ComparedColumnsSpecification)dbCommandBuilder.ComparedColumns).ComparedColumnValues, Is.EqualTo(new[] { _columnValue1, _columnValue2 })); Assert.That(((OrderedColumnsSpecification)dbCommandBuilder.OrderedColumns).Columns, Is.EqualTo(new[] { _orderColumn1, _orderColumn2 })); }
public void PersistenceModelIsValidated() { var unionViewDefinition = UnionViewDefinitionObjectMother.Create(TestDomainStorageProviderDefinition); var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass)); classDefinition.SetStorageEntity(unionViewDefinition); classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection()); classDefinition.SetDerivedClasses(new ClassDefinition[0]); StubMockMappingLoaderWithValidation(new[] { classDefinition }, new RelationDefinition[0]); var persistenceModelLoaderStub = _mockRepository.Stub <IPersistenceModelLoader>(); persistenceModelLoaderStub .Stub(stub => stub.ApplyPersistenceModelToHierarchy(Arg <ClassDefinition> .Is.Anything)); persistenceModelLoaderStub .Stub(stub => stub.CreatePersistenceMappingValidator(Arg <ClassDefinition> .Is.Anything)) .Return(new PersistenceMappingValidator(new ClassAboveTableIsAbstractValidationRule())); _mockRepository.ReplayAll(); new MappingConfiguration(_mockMappingLoader, persistenceModelLoaderStub); }
public override void SetUp() { base.SetUp(); _factory = new SqlSynonymScriptElementFactory(); _tableDefinition1 = TableDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "TableName1")); _tableDefinition2 = TableDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "TableName2")); _unionViewDefinition1 = UnionViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "UnionView1")); _unionViewDefinition2 = UnionViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "UnionView2")); _filterViewDefinition1 = FilterViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "FilterView1")); _filterViewDefinition2 = FilterViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "FilterView2")); _emptyViewDefinition1 = EmptyViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition("SchemaName", "EmptyView1")); _emptyViewDefinition2 = EmptyViewDefinitionObjectMother.Create( SchemaGenerationFirstStorageProviderDefinition, new EntityNameDefinition(null, "EmptyView2")); _synonymWithCustomSchema = new EntityNameDefinition("SynonymSchemaName", "Synonym1"); _synonymWithDefaultSchema = new EntityNameDefinition(null, "Synonym2"); }