public void InversePropertyAttribute_overrides_configuration_from_convention_source() { var dependentEntityTypeBuilder = CreateInternalEntityTypeBuilder <Dependent>(); var principalEntityTypeBuilder = dependentEntityTypeBuilder.ModelBuilder.Entity(typeof(Principal), ConfigurationSource.Convention); dependentEntityTypeBuilder.Relationship( principalEntityTypeBuilder, nameof(Dependent.Principal), nameof(Principal.Dependents), ConfigurationSource.Convention); Assert.Contains(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Principal.Dependents)); Assert.DoesNotContain(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Principal.Dependent)); Assert.Contains(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Dependent.Principal)); var convention = new InversePropertyAttributeConvention(CreateTypeMapper(), CreateLogger()); convention.Apply(dependentEntityTypeBuilder); Assert.DoesNotContain(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Principal.Dependents)); Assert.Contains(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Principal.Dependent)); Assert.Contains(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(Dependent.Principal)); convention.Apply(dependentEntityTypeBuilder.ModelBuilder); }
public void InversePropertyAttribute_does_not_configure_ambiguous_navigations() { var dependentEntityTypeBuilder = CreateInternalEntityTypeBuilder <AmbiguousDependent>(); var principalEntityTypeBuilder = dependentEntityTypeBuilder.ModelBuilder.Entity(typeof(AmbiguousPrincipal), ConfigurationSource.Convention); dependentEntityTypeBuilder.Relationship( principalEntityTypeBuilder, nameof(AmbiguousDependent.AmbiguousPrincipal), nameof(AmbiguousPrincipal.Dependent), ConfigurationSource.Convention); Assert.Contains(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousPrincipal.Dependent)); Assert.Contains(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousDependent.AmbiguousPrincipal)); Assert.DoesNotContain(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousDependent.AnotherAmbiguousPrincipal)); var convention = new InversePropertyAttributeConvention(CreateTypeMapper(), CreateLogger()); convention.Apply(dependentEntityTypeBuilder); Assert.DoesNotContain(principalEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousPrincipal.Dependent)); Assert.DoesNotContain(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousDependent.AnotherAmbiguousPrincipal)); Assert.DoesNotContain(dependentEntityTypeBuilder.Metadata.GetNavigations(), nav => nav.Name == nameof(AmbiguousDependent.AmbiguousPrincipal)); convention.Apply(dependentEntityTypeBuilder.ModelBuilder); Assert.Equal(1, Log.Count); Assert.Equal(LogLevel.Information, Log[0].Level); Assert.Equal(CoreStrings.LogMultipleInversePropertiesSameTarget.GenerateMessage( "AmbiguousDependent.AmbiguousPrincipal, AmbiguousDependent.AnotherAmbiguousPrincipal", nameof(AmbiguousPrincipal.Dependent)), Log[0].Message); }