public void Can_only_override_lower_or_equal_source_Inverse()
        {
            var builder = CreateInternalSkipNavigationBuilder();
            IConventionSkipNavigation metadata = builder.Metadata;

            // the skip navigation is pointing to the automatically-generated
            // join entity type and so is its inverse
            var inverse = (SkipNavigation)metadata.TargetEntityType.Builder.HasSkipNavigation(
                Product.OrdersProperty,
                metadata.DeclaringEntityType)
                          .Metadata;

            Assert.NotNull(metadata.Inverse);
            Assert.Equal(ConfigurationSource.Convention, metadata.GetInverseConfigurationSource());
            Assert.NotNull(inverse.Inverse);
            Assert.Equal(ConfigurationSource.Convention, inverse.GetInverseConfigurationSource());

            // now explicitly assign the skip navigation's Inverse
            Assert.True(builder.CanSetInverse(inverse, ConfigurationSource.DataAnnotation));
            Assert.NotNull(builder.HasInverse(inverse, ConfigurationSource.DataAnnotation));

            Assert.Equal(inverse, metadata.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, metadata.GetInverseConfigurationSource());
            Assert.Equal(metadata, inverse.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, inverse.GetInverseConfigurationSource());

            Assert.True(builder.CanSetInverse(inverse, ConfigurationSource.Convention));
            Assert.False(builder.CanSetInverse(null, ConfigurationSource.Convention));
            Assert.NotNull(builder.HasInverse(inverse, ConfigurationSource.Convention));
            Assert.Null(builder.HasInverse(null, ConfigurationSource.Convention));

            Assert.Equal(inverse, metadata.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, metadata.GetInverseConfigurationSource());
            Assert.Equal(metadata, inverse.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, inverse.GetInverseConfigurationSource());

            Assert.True(builder.CanSetInverse(null, ConfigurationSource.DataAnnotation));
            Assert.NotNull(builder.HasInverse(null, ConfigurationSource.DataAnnotation));

            Assert.Null(metadata.Inverse);
            Assert.Null(metadata.GetInverseConfigurationSource());
            Assert.Null(inverse.Inverse);
            Assert.Null(inverse.GetInverseConfigurationSource());
        }
Пример #2
0
        public void Can_only_override_lower_or_equal_source_Inverse()
        {
            var builder = CreateInternalSkipNavigationBuilder();
            IConventionSkipNavigation metadata = builder.Metadata;

            var inverse = (SkipNavigation)metadata.TargetEntityType.Builder.HasSkipNavigation(
                Product.OrdersProperty,
                metadata.DeclaringEntityType)
                          .Metadata;

            Assert.Null(metadata.Inverse);
            Assert.Null(metadata.GetInverseConfigurationSource());
            Assert.Null(inverse.Inverse);
            Assert.Null(inverse.GetInverseConfigurationSource());

            Assert.True(builder.CanSetInverse(inverse, ConfigurationSource.DataAnnotation));
            Assert.NotNull(builder.HasInverse(inverse, ConfigurationSource.DataAnnotation));

            Assert.Equal(inverse, metadata.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, metadata.GetInverseConfigurationSource());
            Assert.Equal(metadata, inverse.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, inverse.GetInverseConfigurationSource());

            Assert.True(builder.CanSetInverse(inverse, ConfigurationSource.Convention));
            Assert.False(builder.CanSetInverse(null, ConfigurationSource.Convention));
            Assert.NotNull(builder.HasInverse(inverse, ConfigurationSource.Convention));
            Assert.Null(builder.HasInverse(null, ConfigurationSource.Convention));

            Assert.Equal(inverse, metadata.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, metadata.GetInverseConfigurationSource());
            Assert.Equal(metadata, inverse.Inverse);
            Assert.Equal(ConfigurationSource.DataAnnotation, inverse.GetInverseConfigurationSource());

            Assert.True(builder.CanSetInverse(null, ConfigurationSource.DataAnnotation));
            Assert.NotNull(builder.HasInverse(null, ConfigurationSource.DataAnnotation));

            Assert.Null(metadata.Inverse);
            Assert.Null(metadata.GetInverseConfigurationSource());
            Assert.Null(inverse.Inverse);
            Assert.Null(inverse.GetInverseConfigurationSource());
        }