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 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);
        }
示例#3
0
        public void Configure_should_throw_when_annotation_key_name_not_found()
        {
            var database              = new EdmModel(DataSpace.SSpace);
            var dependentTable        = database.AddTable("Source");
            var associationSetMapping = CreateIAMapping(database, dependentTable);

            var configuration = new ForeignKeyAssociationMappingConfiguration();

            configuration.MapKey("K1").HasColumnAnnotation("BadKey", "A1", "V1");

            Assert.Equal(
                Strings.BadKeyNameForAnnotation("BadKey", "A1"),
                Assert.Throws <InvalidOperationException>(
                    () => configuration.Configure(associationSetMapping, database, new MockPropertyInfo())).Message);
        }
示例#4
0
        public void Configure_should_apply_annotations_to_FK_columns()
        {
            var database              = new EdmModel(DataSpace.SSpace);
            var dependentTable        = database.AddTable("Source");
            var associationSetMapping = CreateIAMapping(database, dependentTable);

            var configuration = new ForeignKeyAssociationMappingConfiguration();

            configuration.MapKey("K1")
            .HasColumnAnnotation("K1", "A1", "V1")
            .HasColumnAnnotation("K1", "A2", "V2")
            .HasColumnAnnotation("K1", "A1", "V3");

            configuration.Configure(associationSetMapping, database, new MockPropertyInfo());

            var column = dependentTable.Properties.Single(p => p.Name == "K1");

            Assert.Equal("V3", column.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A1").Value);
            Assert.Equal("V2", column.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A2").Value);
        }
        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);
        }
        public void Configure_should_throw_when_annotation_key_name_not_found()
        {
            var database = new EdmModel(DataSpace.SSpace);
            var dependentTable = database.AddTable("Source");
            var associationSetMapping = CreateIAMapping(database, dependentTable);

            var configuration = new ForeignKeyAssociationMappingConfiguration();
            configuration.MapKey("K1").HasColumnAnnotation("BadKey", "A1", "V1");

            Assert.Equal(
                Strings.BadKeyNameForAnnotation("BadKey", "A1"),
                Assert.Throws<InvalidOperationException>(
                    () => configuration.Configure(associationSetMapping, database, new MockPropertyInfo())).Message);

        }
        public void Configure_should_apply_annotations_to_FK_columns()
        {
            var database = new EdmModel(DataSpace.SSpace);
            var dependentTable = database.AddTable("Source");
            var associationSetMapping = CreateIAMapping(database, dependentTable);

            var configuration = new ForeignKeyAssociationMappingConfiguration();
            configuration.MapKey("K1")
                .HasColumnAnnotation("K1", "A1", "V1")
                .HasColumnAnnotation("K1", "A2", "V2")
                .HasColumnAnnotation("K1", "A1", "V3");

            configuration.Configure(associationSetMapping, database, new MockPropertyInfo());

            var column = dependentTable.Properties.Single(p => p.Name == "K1");

            Assert.Equal("V3", column.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A1").Value);
            Assert.Equal("V2", column.Annotations.Single(a => a.Name == XmlConstants.CustomAnnotationPrefix + "A2").Value);
        }