public void Creates_unique_foreign_key_using_dependent_PK_if_no_matching_FK_property_found() { var fk = new ForeignKeyConvention().FindOrCreateForeignKey(PrincipalType, DependentType, "SomeNav", "SomeInverse", isUnqiue: true); Assert.Same(DependentType.GetKey().Properties.Single(), fk.Properties.Single()); Assert.Same(PrimaryKey, fk.ReferencedProperties.Single()); Assert.True(fk.IsUnique); Assert.True(fk.IsRequired); }
public void Creates_foreign_key_matching_principal_type_name_plus_PK_name() { var fkProperty = DependentType.AddProperty("PrincipalEntityPeEKaY", typeof(int)); var fk = new ForeignKeyConvention().FindOrCreateForeignKey(PrincipalType, DependentType, "SomeNav", "SomeInverse", isUnqiue: false); Assert.Same(fkProperty, fk.Properties.Single()); Assert.Same(PrimaryKey, fk.ReferencedProperties.Single()); Assert.False(fk.IsUnique); Assert.True(fk.IsRequired); }
public void Creates_foreign_key_based_on_type_name_if_no_appropriate_property_is_found() { var fk = new ForeignKeyConvention().FindOrCreateForeignKey(PrincipalType, DependentType, null, null, isUnqiue: false); Assert.Equal("PrincipalEntityId", fk.Properties.Single().Name); Assert.Equal(typeof(int), fk.Properties.Single().PropertyType); Assert.True(fk.Properties.Single().IsShadowProperty); Assert.False(fk.Properties.Single().IsConcurrencyToken); Assert.Same(PrimaryKey, fk.ReferencedProperties.Single()); Assert.False(fk.IsUnique); Assert.True(fk.IsRequired); }
public void Creates_foreign_key_using_given_property() { DependentType.AddProperty("SomeNavID", typeof(int)); DependentType.AddProperty("SomeNavPeEKaY", typeof(int)); DependentType.AddProperty("PrincipalEntityID", typeof(int)); DependentType.AddProperty("PrincipalEntityPeEKaY", typeof(int)); var fkProperty = DependentType.AddProperty("No!No!", typeof(int)); var fk = new ForeignKeyConvention().FindOrCreateForeignKey( PrincipalType, DependentType, "SomeNav", "SomeInverse", new[] { new[] { fkProperty } }, isUnqiue: false); Assert.Same(fkProperty, fk.Properties.Single()); Assert.Same(PrimaryKey, fk.ReferencedProperties.Single()); Assert.False(fk.IsUnique); Assert.True(fk.IsRequired); }
public void Does_not_match_existing_FK_if_FK_already_has_different_uniqueness() { var fkProperty = DependentType.AddProperty("SharedFk", typeof(int)); var fk = DependentType.AddForeignKey(PrincipalType.GetKey(), fkProperty); fk.IsUnique = true; var newFk = new ForeignKeyConvention().FindOrCreateForeignKey( PrincipalType, DependentType, "SomeNav", "SomeInverse", new[] { new[] { fkProperty } }, isUnqiue: false); Assert.NotSame(fk, newFk); Assert.Same(fkProperty, newFk.Properties.Single()); Assert.Same(PrimaryKey, newFk.ReferencedProperties.Single()); Assert.False(newFk.IsUnique); Assert.True(newFk.IsRequired); }