public void Configure_should_split_key_constraint_when_to_table_configuration() { var database = new DbDatabaseMetadata().Initialize(); var sourceTable = database.AddTable("Source"); var fkColumn = sourceTable.AddColumn("Fk"); var foreignKeyConstraint = new DbForeignKeyConstraintMetadata(); foreignKeyConstraint.DependentColumns.Add(fkColumn); sourceTable.ForeignKeyConstraints.Add(foreignKeyConstraint); var targetTable = database.AddTable("Split"); var associationSetMapping = new DbAssociationSetMapping().Initialize(); associationSetMapping.Table = sourceTable; associationSetMapping.SourceEndMapping.PropertyMappings.Add(new DbEdmPropertyMapping { Column = fkColumn }); var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); independentAssociationMappingConfiguration.Configure(associationSetMapping, database); Assert.True(targetTable.Columns.Contains(fkColumn)); Assert.True(targetTable.ForeignKeyConstraints.Contains(foreignKeyConstraint)); Assert.False(sourceTable.Columns.Contains(fkColumn)); Assert.False(sourceTable.ForeignKeyConstraints.Contains(foreignKeyConstraint)); Assert.Same(targetTable, associationSetMapping.Table); }
public void AddTable_should_create_and_add_table_to_default_schema() { var database = new DbDatabaseMetadata().Initialize(); var table = database.AddTable("T"); Assert.True(database.Schemas.First().Tables.Contains(table)); Assert.Equal("T", database.Schemas.First().Tables.First().Name); }
public void Configure_should_rename_table_when_table_configured() { var database = new DbDatabaseMetadata().Initialize(); var table = database.AddTable("OriginalName"); var associationSetMapping = new DbAssociationSetMapping().Initialize(); associationSetMapping.Table = table; var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.ToTable("NewName"); manyToManyAssociationMappingConfiguration.Configure(associationSetMapping, database); Assert.Equal("NewName", table.GetTableName().Name); Assert.Same(manyToManyAssociationMappingConfiguration, table.GetConfiguration()); }
public void ApplyDatabase_should_run_targeted_model_conventions() { var database = new DbDatabaseMetadata().Initialize(); var table = database.AddTable("T"); var mockConvention = new Mock<IDbConvention<DbTableMetadata>>(); var conventionsConfiguration = new ConventionsConfiguration( new IConvention[] { mockConvention.Object }); conventionsConfiguration.ApplyDatabase(database); mockConvention.Verify(c => c.Apply(table, database), Times.AtMostOnce()); }