Exemplo n.º 1
0
        public void Non_nullability_logs_when_navigation_to_dependent()
        {
            var dependentEntityTypeBuilder = CreateInternalEntityTypeBuilder <Dependent>();
            var principalEntityTypeBuilder =
                dependentEntityTypeBuilder.ModelBuilder.Entity(typeof(Principal), ConfigurationSource.Convention);

            var relationshipBuilder = dependentEntityTypeBuilder.HasRelationship(
                principalEntityTypeBuilder.Metadata,
                nameof(Dependent.Principal),
                nameof(Principal.Dependent),
                ConfigurationSource.Convention);

            Assert.Equal(nameof(Dependent), relationshipBuilder.Metadata.DeclaringEntityType.DisplayName());
            Assert.False(relationshipBuilder.Metadata.IsRequired);

            var navigation = principalEntityTypeBuilder.Metadata.FindNavigation(nameof(Principal.Dependent));

            navigation = RunConvention(relationshipBuilder, navigation);

            Assert.Equal(nameof(Dependent), navigation.ForeignKey.DeclaringEntityType.DisplayName());
            Assert.False(navigation.ForeignKey.IsRequired);
            Assert.Empty(ListLoggerFactory.Log);

            relationshipBuilder.HasEntityTypes(
                relationshipBuilder.Metadata.PrincipalEntityType,
                relationshipBuilder.Metadata.DeclaringEntityType,
                ConfigurationSource.Convention);

            navigation = RunConvention(relationshipBuilder, navigation);

            Assert.Equal(nameof(Dependent), navigation.ForeignKey.DeclaringEntityType.DisplayName());
            Assert.False(navigation.ForeignKey.IsRequired);
            var logEntry = ListLoggerFactory.Log.Single();

            Assert.Equal(LogLevel.Debug, logEntry.Level);
            Assert.Equal(
                CoreResources.LogNonNullableReferenceOnDependent(new TestLogger <TestLoggingDefinitions>()).GenerateMessage(
                    nameof(Dependent.Principal), nameof(Dependent)), logEntry.Message);
        }