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 Equals_should_return_false_when_table_names_dont_match() { var independentAssociationMappingConfiguration1 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration1.ToTable("Bar", "Foo"); var independentAssociationMappingConfiguration2 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration2.ToTable("Foo", "Bar"); Assert.NotEqual(independentAssociationMappingConfiguration1, independentAssociationMappingConfiguration2); }
public void Configure_should_throw_when_configured_table_not_found() { var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); var associationSetMapping = new DbAssociationSetMapping().Initialize(); var database = new DbDatabaseMetadata().Initialize(); Assert.Equal(Strings.TableNotFound("Split"), Assert.Throws<InvalidOperationException>(() => independentAssociationMappingConfiguration.Configure(associationSetMapping, database)).Message); }
public void Equals_should_return_true_when_table_names_and_columns_match() { var independentAssociationMappingConfiguration1 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration1.ToTable("Foo", "Bar"); independentAssociationMappingConfiguration1.MapKey("Baz"); var independentAssociationMappingConfiguration2 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration2.ToTable("Foo", "Bar"); independentAssociationMappingConfiguration2.MapKey("Baz"); Assert.Equal(independentAssociationMappingConfiguration1, independentAssociationMappingConfiguration2); }
public void Equals_should_return_false_when_table_names_dont_match() { var independentAssociationMappingConfiguration1 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration1.ToTable("Bar", "Foo"); var independentAssociationMappingConfiguration2 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration2.ToTable("Foo", "Bar"); Assert.NotEqual(independentAssociationMappingConfiguration1, independentAssociationMappingConfiguration2); }
public void Cloning_an_foreign_key_mapping_configuration_clones_its_table_and_column_information() { var configuration = new ForeignKeyAssociationMappingConfiguration(); configuration.MapKey("C1"); configuration.ToTable("T", "S"); var clone = (ForeignKeyAssociationMappingConfiguration)configuration.Clone(); Assert.Equal(configuration, clone); configuration.MapKey("C2"); Assert.NotEqual(configuration, clone); }
public void Equals_should_return_true_when_table_names_and_columns_match() { var independentAssociationMappingConfiguration1 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration1.ToTable("Foo", "Bar"); independentAssociationMappingConfiguration1.MapKey("Baz"); var independentAssociationMappingConfiguration2 = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration2.ToTable("Foo", "Bar"); independentAssociationMappingConfiguration2.MapKey("Baz"); Assert.Equal(independentAssociationMappingConfiguration1, independentAssociationMappingConfiguration2); }
public void Configure_should_split_key_constraint_when_to_table_configuration() { var database = new EdmModel().DbInitialize(); var sourceTable = database.AddTable("Source"); var principalTable = database.AddTable("P"); var fkColumn = new EdmProperty( "Fk", ProviderRegistry.Sql2008_ProviderManifest.GetStoreType( TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))); sourceTable.AddColumn(fkColumn); var foreignKeyConstraint = new ForeignKeyBuilder(database, "FK") { PrincipalTable = principalTable }; sourceTable.AddForeignKey(foreignKeyConstraint); foreignKeyConstraint.DependentColumns = new[] { fkColumn }; var targetTable = database.AddTable("Split"); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType()), database.GetEntitySet(sourceTable)).Initialize(); associationSetMapping.SourceEndMapping.AddProperty(new StorageScalarPropertyMapping(new EdmProperty("PK"), fkColumn)); var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); independentAssociationMappingConfiguration.Configure(associationSetMapping, database, new MockPropertyInfo()); Assert.True(targetTable.Properties.Contains(fkColumn)); Assert.True(targetTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.False(sourceTable.Properties.Contains(fkColumn)); Assert.False(sourceTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.Same(targetTable, associationSetMapping.Table); }
public void Configure_should_throw_when_configured_table_not_found() { var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); var associationSetMapping = new AssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), new EntitySet()) .Initialize(); var database = new EdmModel(DataSpace.SSpace); Assert.Equal( Strings.TableNotFound("Split"), Assert.Throws<InvalidOperationException>( () => independentAssociationMappingConfiguration .Configure(associationSetMapping, database, new MockPropertyInfo())). Message); }
public void Configure_should_throw_when_configured_table_not_found() { var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); var associationSetMapping = new StorageAssociationSetMapping( new AssociationSet("AS", new AssociationType()), new EntitySet()) .Initialize(); var database = new EdmModel().DbInitialize(); Assert.Equal( Strings.TableNotFound("Split"), Assert.Throws <InvalidOperationException>( () => independentAssociationMappingConfiguration .Configure(associationSetMapping, database, new MockPropertyInfo())). Message); }
public void Configure_should_split_key_constraint_when_to_table_configuration() { var database = new EdmModel(DataSpace.SSpace); var sourceTable = database.AddTable("Source"); var principalTable = database.AddTable("P"); var fkColumn = new EdmProperty( "Fk", ProviderRegistry.Sql2008_ProviderManifest.GetStoreType( TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))); sourceTable.AddColumn(fkColumn); var foreignKeyConstraint = new ForeignKeyBuilder(database, "FK") { PrincipalTable = principalTable }; sourceTable.AddForeignKey(foreignKeyConstraint); foreignKeyConstraint.DependentColumns = new[] { fkColumn }; var targetTable = database.AddTable("Split"); var associationSetMapping = new AssociationSetMapping( new AssociationSet("AS", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)), database.GetEntitySet(sourceTable)).Initialize(); associationSetMapping.SourceEndMapping.AddPropertyMapping(new ScalarPropertyMapping(new EdmProperty("PK"), fkColumn)); var independentAssociationMappingConfiguration = new ForeignKeyAssociationMappingConfiguration(); independentAssociationMappingConfiguration.ToTable("Split"); independentAssociationMappingConfiguration.Configure(associationSetMapping, database, new MockPropertyInfo()); Assert.True(targetTable.Properties.Contains(fkColumn)); Assert.True(targetTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.False(sourceTable.Properties.Contains(fkColumn)); Assert.False(sourceTable.ForeignKeyBuilders.Contains(foreignKeyConstraint)); Assert.Same(targetTable, associationSetMapping.Table); }