diff --git a/test/EFCore.Cosmos.Tests/Metadata/Conventions/CosmosConventionSetBuilderTests.cs b/test/EFCore.Cosmos.Tests/Metadata/Conventions/CosmosConventionSetBuilderTests.cs index ff8c780dcb0..393cfef6dd6 100644 --- a/test/EFCore.Cosmos.Tests/Metadata/Conventions/CosmosConventionSetBuilderTests.cs +++ b/test/EFCore.Cosmos.Tests/Metadata/Conventions/CosmosConventionSetBuilderTests.cs @@ -9,11 +9,6 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions { public class CosmosConventionSetBuilderTests : ConventionSetBuilderTests { - public override IReadOnlyModel Can_build_a_model_with_default_conventions_without_DI() - { - return null; - } - public override IReadOnlyModel Can_build_a_model_with_default_conventions_without_DI_new() { var model = base.Can_build_a_model_with_default_conventions_without_DI_new(); diff --git a/test/EFCore.Cosmos.Tests/ModelBuilding/CosmosModelBuilderGenericTest.cs b/test/EFCore.Cosmos.Tests/ModelBuilding/CosmosModelBuilderGenericTest.cs index 52faded7f5d..0b1d569a5eb 100644 --- a/test/EFCore.Cosmos.Tests/ModelBuilding/CosmosModelBuilderGenericTest.cs +++ b/test/EFCore.Cosmos.Tests/ModelBuilding/CosmosModelBuilderGenericTest.cs @@ -4,10 +4,13 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.EntityFrameworkCore.Cosmos.Internal; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Conventions; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; +using Xunit.Sdk; // ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.ModelBuilding @@ -18,17 +21,18 @@ public class CosmosGenericNonRelationship : GenericNonRelationship { public override void Properties_can_set_row_version() { - // Fails due to ETags + Assert.Equal( + CosmosStrings.NonETagConcurrencyToken(nameof(Quarks), "Charm"), + Assert.Throws( + () => base.Properties_can_set_row_version()).Message); } public override void Properties_can_be_made_concurrency_tokens() { - // Fails due to ETags - } - - public override void Properties_specified_by_string_are_shadow_properties_unless_already_known_to_be_CLR_properties() - { - // Fails due to extra shadow properties + Assert.Equal( + CosmosStrings.NonETagConcurrencyToken(nameof(Quarks), "Charm"), + Assert.Throws( + () => base.Properties_can_be_made_concurrency_tokens()).Message); } protected override void Mapping_throws_for_non_ignored_array() @@ -271,24 +275,29 @@ protected override TestModelBuilder CreateModelBuilder(Action(); + mb.Entity(); - public override void Base_types_are_mapped_correctly_if_discovered_last() - { - // Base discovered as owned + var mutableEntityTypes = mb.Model.GetEntityTypes().Where(e => e.ClrType == typeof(Q)).ToList(); + + Assert.Equal(2, mutableEntityTypes.Count); + + foreach (var mutableEntityType in mutableEntityTypes) + { + var mutableProperty = mutableEntityType.FindProperty(nameof(Q.ID)); + + Assert.Equal(ValueGenerated.Never, mutableProperty.ValueGenerated); + } } public override void Relationships_on_derived_types_are_discovered_first_if_base_is_one_sided() { // Base discovered as owned + Assert.Throws( + () => base.Relationships_on_derived_types_are_discovered_first_if_base_is_one_sided()); } protected override TestModelBuilder CreateModelBuilder(Action configure = null) @@ -488,12 +497,22 @@ public virtual void Can_use_implicit_join_entity_with_partition_keys_changed() public override void Join_type_is_automatically_configured_by_convention() { - // Many-to-many not configured by convention on Cosmos + // Cosmos many-to-many. Issue #23523. + Assert.Equal( + CoreStrings.NavigationNotAdded( + nameof(ImplicitManyToManyA), nameof(ImplicitManyToManyA.Bs), "List"), + Assert.Throws( + () => base.Join_type_is_automatically_configured_by_convention()).Message); } public override void ForeignKeyAttribute_configures_the_properties() { - // Many-to-many not configured by convention on Cosmos + // Cosmos many-to-many. Issue #23523. + Assert.Equal( + CoreStrings.NavigationNotAdded( + nameof(CategoryWithAttribute), nameof(CategoryWithAttribute.Products), "ICollection"), + Assert.Throws( + () => base.ForeignKeyAttribute_configures_the_properties()).Message); } protected override TestModelBuilder CreateModelBuilder(Action configure = null) @@ -505,11 +524,19 @@ public class CosmosGenericOwnedTypes : GenericOwnedTypes public override void Deriving_from_owned_type_throws() { // On Cosmos the base type starts as owned + Assert.Contains( + "(No exception was thrown)", + Assert.Throws( + () => base.Deriving_from_owned_type_throws()).Message); } public override void Configuring_base_type_as_owned_throws() { // On Cosmos the base type starts as owned + Assert.Contains( + "(No exception was thrown)", + Assert.Throws( + () => base.Deriving_from_owned_type_throws()).Message); } [ConditionalFact] diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs index bc41773e18f..2dab8e0e644 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpDbContextGeneratorTest.cs @@ -13,6 +13,7 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Design.Internal; +using Microsoft.EntityFrameworkCore.SqlServer.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.DependencyInjection; @@ -1075,23 +1076,28 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) skipBuild: true); } - [ConditionalFact(Skip = "issue #26007")] + [ConditionalFact] public void Temporal_table_works() { - Test( - modelBuilder => modelBuilder.Entity( - "Customer", e => - { - e.Property("Id"); - e.Property("Name"); - e.HasKey("Id"); - e.ToTable(tb => tb.IsTemporal()); - }), - new ModelCodeGenerationOptions { UseDataAnnotations = false }, - code => - { - AssertFileContents( - @"using System; + // Shadow properties. Issue #26007. + Assert.Equal( + SqlServerStrings.TemporalPeriodPropertyMustBeInShadowState("Customer", "PeriodStart"), + Assert.Throws( + () => + Test( + modelBuilder => modelBuilder.Entity( + "Customer", e => + { + e.Property("Id"); + e.Property("Name"); + e.HasKey("Id"); + e.ToTable(tb => tb.IsTemporal()); + }), + new ModelCodeGenerationOptions { UseDataAnnotations = false }, + code => + { + AssertFileContents( + @"using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; @@ -1115,7 +1121,9 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { -#warning " + DesignStrings.SensitiveInformationWarning + @" +#warning " + + DesignStrings.SensitiveInformationWarning + + @" optionsBuilder.UseSqlServer(""Initial Catalog=TestDatabase""); } } @@ -1145,12 +1153,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } } ", - code.ContextFile); - }, - model => - { - // TODO - }); + code.ContextFile); + }, + model => + { + // TODO + })).Message); } protected override void AddModelServices(IServiceCollection services) diff --git a/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs b/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs index f4764b2bcad..6d439b0134e 100644 --- a/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs +++ b/test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs @@ -15,6 +15,7 @@ using Microsoft.EntityFrameworkCore.TestUtilities; using Microsoft.Extensions.Logging; using Xunit; +using Xunit.Sdk; // ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Infrastructure @@ -900,7 +901,7 @@ public virtual void Passes_for_shared_columns() Validate(modelBuilder); } - [ConditionalFact(Skip = "Issue #23144")] + [ConditionalFact] public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_on_different_tables() { var modelBuilder = CreateConventionalModelBuilder(); @@ -911,14 +912,18 @@ public virtual void Detects_duplicate_foreignKey_names_within_hierarchy_on_diffe modelBuilder.Entity().ToTable("Cats"); modelBuilder.Entity().ToTable("Dogs"); - VerifyError( - RelationalStrings.DuplicateForeignKeyTableMismatch( - "{'FriendId'}", nameof(Dog), - "{'FriendId'}", nameof(Cat), - "FK", - "Cats", - "Dogs"), - modelBuilder); + // Should throw. Issue #23144. + Assert.Contains( + "(No exception was thrown)", + Assert.Throws( + () => VerifyError( + RelationalStrings.DuplicateForeignKeyTableMismatch( + "{'FriendId'}", nameof(Dog), + "{'FriendId'}", nameof(Cat), + "FK", + "Cats", + "Dogs"), + modelBuilder)).Message); } [ConditionalFact] diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index d96a079aad8..41bf2396fa9 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -10330,7 +10330,7 @@ public void Rename_property_on_subtype_and_add_similar_to_base() }); } - [ConditionalFact(Skip = "#15339")] + [ConditionalFact] public void Owner_pk_properties_appear_before_owned_pk_which_preserves_annotations() { Execute( @@ -10363,13 +10363,13 @@ public void Owner_pk_properties_appear_before_owned_pk_which_preserves_annotatio Assert.Equal(50, c.MaxLength); Assert.False(c.IsUnicode); }, + c => Assert.Equal("DisplayName", c.Name), c => { Assert.Equal("Created_Reason", c.Name); Assert.Equal(255, c.MaxLength); Assert.False(c.IsUnicode); - }, - c => Assert.Equal("DisplayName", c.Name) + } ); }); } diff --git a/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs b/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs index 214d9938c44..940f2e2a75f 100644 --- a/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs +++ b/test/EFCore.Relational.Tests/Update/CommandBatchPreparerTest.cs @@ -15,6 +15,7 @@ using Microsoft.EntityFrameworkCore.Update.Internal; using Microsoft.Extensions.DependencyInjection; using Xunit; +using Xunit.Sdk; // ReSharper disable RedundantArgumentDefaultValue // ReSharper disable InconsistentNaming @@ -408,7 +409,7 @@ public void Batch_command_throws_on_commands_with_circular_dependencies(bool sen : @"FakeEntity [Added] <- ForeignKey { 'RelatedId' } RelatedFakeEntity [Added] <- ForeignKey { 'RelatedId' } FakeEntity [Added]" + CoreStrings.SensitiveDataDisabled; - + Assert.Equal( CoreStrings.CircularDependency(ListLoggerFactory.NormalizeLineEndings(expectedCycle)), Assert.Throws( @@ -802,7 +803,7 @@ public void BatchCommands_throws_on_conflicting_values_for_shared_table_added_en [InlineData(EntityState.Added)] [InlineData(EntityState.Deleted)] - [ConditionalTheory(Skip = "Issue #17947")] + [ConditionalTheory] public void BatchCommands_creates_batch_on_incomplete_updates_for_shared_table_no_principal(EntityState state) { var currentDbContext = CreateContextServices(CreateSharedTableModel()).GetRequiredService(); @@ -821,53 +822,67 @@ public void BatchCommands_creates_batch_on_incomplete_updates_for_shared_table_n var commandBatches = CreateCommandBatchPreparer(updateAdapter: modelData, sensitiveLogging: true) .BatchCommands(new[] { firstEntry }, modelData).ToArray(); - Assert.Single(commandBatches); - Assert.Equal(1, commandBatches.First().ModificationCommands.Count); - - var command = commandBatches.First().ModificationCommands.Single(); - Assert.Equal(EntityState.Modified, command.EntityState); - Assert.Equal(4, command.ColumnModifications.Count); - - var columnMod = command.ColumnModifications[0]; - - Assert.Equal(nameof(DerivedRelatedFakeEntity.Id), columnMod.ColumnName); - Assert.True(columnMod.UseOriginalValueParameter); - Assert.False(columnMod.UseCurrentValueParameter); - Assert.Equal(first.Id, columnMod.OriginalValue); - Assert.True(columnMod.IsCondition); - Assert.True(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.False(columnMod.IsWrite); - - columnMod = command.ColumnModifications[1]; - - Assert.Equal("Discriminator", columnMod.ColumnName); - Assert.Equal(nameof(DerivedRelatedFakeEntity), columnMod.Value); - Assert.Equal(nameof(DerivedRelatedFakeEntity), columnMod.OriginalValue); - Assert.True(columnMod.IsCondition); - Assert.False(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.True(columnMod.IsWrite); - - columnMod = command.ColumnModifications[2]; + if (state == EntityState.Deleted) + { + // Detect indirect update dependencies. Issue #17947. + Assert.Throws( + () => Assert.Single(commandBatches)); + } + else + { + Assert.Single(commandBatches); + Assert.Equal(1, commandBatches.First().ModificationCommands.Count); - Assert.Equal(nameof(DerivedRelatedFakeEntity.RelatedId), columnMod.ColumnName); - Assert.Equal(first.RelatedId, columnMod.Value); - Assert.Equal(first.RelatedId, columnMod.OriginalValue); - Assert.True(columnMod.IsCondition); - Assert.False(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.True(columnMod.IsWrite); + var command = commandBatches.First().ModificationCommands.Single(); + Assert.Equal(EntityState.Modified, command.EntityState); - columnMod = command.ColumnModifications[3]; + // Detect indirect update dependencies. Issue #17947. + Assert.Equal( + "4", + Assert.Throws( + () => Assert.Equal(5, command.ColumnModifications.Count)).Actual); + } - Assert.Equal(nameof(AnotherFakeEntity.AnotherId), columnMod.ColumnName); - Assert.Equal(second.AnotherId, columnMod.Value); - Assert.Equal(second.AnotherId, columnMod.OriginalValue); - Assert.False(columnMod.IsCondition); - Assert.False(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.True(columnMod.IsWrite); + // var columnMod = command.ColumnModifications[0]; + // + // Assert.Equal(nameof(DerivedRelatedFakeEntity.Id), columnMod.ColumnName); + // Assert.True(columnMod.UseOriginalValueParameter); + // Assert.False(columnMod.UseCurrentValueParameter); + // Assert.Equal(first.Id, columnMod.OriginalValue); + // Assert.True(columnMod.IsCondition); + // Assert.True(columnMod.IsKey); + // Assert.False(columnMod.IsRead); + // Assert.False(columnMod.IsWrite); + // + // columnMod = command.ColumnModifications[1]; + // + // Assert.Equal("Discriminator", columnMod.ColumnName); + // Assert.Equal(nameof(DerivedRelatedFakeEntity), columnMod.Value); + // Assert.Equal(nameof(DerivedRelatedFakeEntity), columnMod.OriginalValue); + // Assert.True(columnMod.IsCondition); + // Assert.False(columnMod.IsKey); + // Assert.False(columnMod.IsRead); + // Assert.True(columnMod.IsWrite); + // + // columnMod = command.ColumnModifications[2]; + // + // Assert.Equal(nameof(DerivedRelatedFakeEntity.RelatedId), columnMod.ColumnName); + // Assert.Equal(first.RelatedId, columnMod.Value); + // Assert.Equal(first.RelatedId, columnMod.OriginalValue); + // Assert.True(columnMod.IsCondition); + // Assert.False(columnMod.IsKey); + // Assert.False(columnMod.IsRead); + // Assert.True(columnMod.IsWrite); + // + // columnMod = command.ColumnModifications[3]; + // + // Assert.Equal(nameof(AnotherFakeEntity.AnotherId), columnMod.ColumnName); + // Assert.Equal(second.AnotherId, columnMod.Value); + // Assert.Equal(second.AnotherId, columnMod.OriginalValue); + // Assert.False(columnMod.IsCondition); + // Assert.False(columnMod.IsKey); + // Assert.False(columnMod.IsRead); + // Assert.True(columnMod.IsWrite); } [InlineData(EntityState.Added)] @@ -896,7 +911,7 @@ public void BatchCommands_works_with_incomplete_updates_for_shared_table_no_leaf [InlineData(EntityState.Added)] [InlineData(EntityState.Deleted)] - [ConditionalTheory(Skip = "Issue #17947")] + [ConditionalTheory] public void BatchCommands_creates_batch_on_incomplete_updates_for_shared_table_no_middle_dependent(EntityState state) { var currentDbContext = CreateContextServices(CreateSharedTableModel()).GetRequiredService(); @@ -915,42 +930,44 @@ public void BatchCommands_creates_batch_on_incomplete_updates_for_shared_table_n var commandBatches = CreateCommandBatchPreparer(updateAdapter: modelData, sensitiveLogging: true) .BatchCommands(new[] { firstEntry, secondEntry }, modelData).ToArray(); - Assert.Equal(2, commandBatches.Length); - Assert.Equal(1, commandBatches.First().ModificationCommands.Count); + if (state == EntityState.Deleted) + { + // Detect indirect update dependencies. Issue #17947. + Assert.Equal( + "1", + Assert.Throws( + () => Assert.Equal(2, commandBatches.Length)).Actual); + } + else + { + Assert.Equal(2, commandBatches.Length); + Assert.Equal(1, commandBatches.First().ModificationCommands.Count); - var command = commandBatches.First().ModificationCommands.Single(); - Assert.Equal(EntityState.Modified, command.EntityState); - Assert.Equal(3, command.ColumnModifications.Count); + var command = commandBatches.First().ModificationCommands.Single(); + Assert.Equal(EntityState.Modified, command.EntityState); - var columnMod = command.ColumnModifications[0]; + Assert.Equal(2, command.ColumnModifications.Count); - Assert.Equal(nameof(DerivedRelatedFakeEntity.Id), columnMod.ColumnName); - Assert.Equal(first.Id, columnMod.Value); - Assert.Equal(first.Id, columnMod.OriginalValue); - Assert.True(columnMod.IsCondition); - Assert.True(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.False(columnMod.IsWrite); + var columnMod = command.ColumnModifications[0]; - columnMod = command.ColumnModifications[1]; - - Assert.Equal(nameof(DerivedRelatedFakeEntity.RelatedId), columnMod.ColumnName); - Assert.Equal(first.RelatedId, columnMod.Value); - Assert.Equal(first.RelatedId, columnMod.OriginalValue); - Assert.True(columnMod.IsCondition); - Assert.False(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.True(columnMod.IsWrite); + Assert.Equal(nameof(DerivedRelatedFakeEntity.Id), columnMod.ColumnName); + Assert.Equal(first.Id, columnMod.Value); + Assert.Equal(first.Id, columnMod.OriginalValue); + Assert.True(columnMod.IsCondition); + Assert.True(columnMod.IsKey); + Assert.False(columnMod.IsRead); + Assert.False(columnMod.IsWrite); - columnMod = command.ColumnModifications[2]; + columnMod = command.ColumnModifications[1]; - Assert.Equal(nameof(AnotherFakeEntity.AnotherId), columnMod.ColumnName); - Assert.Equal(second.AnotherId, columnMod.Value); - Assert.Equal(second.AnotherId, columnMod.OriginalValue); - Assert.False(columnMod.IsCondition); - Assert.False(columnMod.IsKey); - Assert.False(columnMod.IsRead); - Assert.True(columnMod.IsWrite); + Assert.Equal(nameof(AnotherFakeEntity.AnotherId), columnMod.ColumnName); + Assert.Equal(second.AnotherId, columnMod.Value); + Assert.Equal(second.AnotherId, columnMod.OriginalValue); + Assert.False(columnMod.IsCondition); + Assert.False(columnMod.IsKey); + Assert.False(columnMod.IsRead); + Assert.True(columnMod.IsWrite); + } } private static IServiceProvider CreateContextServices(IModel model) diff --git a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs index c53b5400060..6d010a93cbc 100644 --- a/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs +++ b/test/EFCore.SqlServer.Tests/ModelBuilding/SqlServerModelBuilderGenericTest.cs @@ -837,7 +837,6 @@ public virtual void Owned_type_collections_can_be_mapped_to_different_tables() Assert.Null(owned.GetSchema()); } - [ConditionalFact] public override void Can_configure_owned_type() { var modelBuilder = CreateModelBuilder(); @@ -900,7 +899,6 @@ static void AssertOwnership(IEntityType owner) } } - [ConditionalFact] public override void Can_configure_owned_type_key() { var modelBuilder = CreateModelBuilder(); diff --git a/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs index a0091e7175e..860a7e9a0f5 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; using Xunit; @@ -885,41 +886,50 @@ public void Query_owned() }); } - [ConditionalFact(Skip = "Issue#24807")] + [ConditionalFact] public void Query_subowned() { Seed(); using var context = new QueryFixupContext(); - var subDependent1 = context.Set() - .Include(a => a.OrderDetails.BillingAddress.OrderDetails.Order) - .Select(o => o.OrderDetails.BillingAddress) - .Single(); - var subDependent2 = context.Set() - .Include(a => a.OrderDetails.ShippingAddress.OrderDetails.Order) - .Select(o => o.OrderDetails.ShippingAddress) - .Single(); - - AssertFixup( - context, - () => - { - Assert.Equal("BillMe", subDependent1.Street); - Assert.Equal("ShipMe", subDependent2.Street); - var dependent = subDependent1.OrderDetails; - Assert.Same(dependent, subDependent2.OrderDetails); - Assert.NotNull(dependent.Order); - var principal = dependent.Order; - - var subDependent1Entry = context.Entry(subDependent1); - Assert.Equal(principal.Id, subDependent1Entry.Property("OrderDetailsId").CurrentValue); - Assert.Equal(typeof(OrderDetails).DisplayName() + "." + nameof(OrderDetails.BillingAddress) + "#" + typeof(Address).ShortDisplayName(), subDependent1Entry.Metadata.Name); - - var subDependent2Entry = context.Entry(subDependent2); - Assert.Equal(principal.Id, subDependent2Entry.Property("OrderDetailsId").CurrentValue); - Assert.Equal(typeof(OrderDetails).DisplayName() + "." + nameof(OrderDetails.ShippingAddress) + "#" + typeof(Address).ShortDisplayName(), subDependent2Entry.Metadata.Name); - }); + // Owned entity without owner. Issue #24807. + Assert.Equal( + CoreStrings.OwnedEntitiesCannotBeTrackedWithoutTheirOwner, + Assert.Throws( + () => + { + var subDependent1 = context.Set() + .Include(a => a.OrderDetails.BillingAddress.OrderDetails.Order) + .Select(o => o.OrderDetails.BillingAddress) + .Single(); + }).Message); + + // var subDependent2 = context.Set() + // .Include(a => a.OrderDetails.ShippingAddress.OrderDetails.Order) + // .Select(o => o.OrderDetails.ShippingAddress) + // .Single(); + // + // AssertFixup( + // context, + // () => + // { + // Assert.Equal("BillMe", subDependent1.Street); + // Assert.Equal("ShipMe", subDependent2.Street); + // + // var dependent = subDependent1.OrderDetails; + // Assert.Same(dependent, subDependent2.OrderDetails); + // Assert.NotNull(dependent.Order); + // var principal = dependent.Order; + // + // var subDependent1Entry = context.Entry(subDependent1); + // Assert.Equal(principal.Id, subDependent1Entry.Property("OrderDetailsId").CurrentValue); + // Assert.Equal(typeof(OrderDetails).DisplayName() + "." + nameof(OrderDetails.BillingAddress) + "#" + typeof(Address).ShortDisplayName(), subDependent1Entry.Metadata.Name); + // + // var subDependent2Entry = context.Entry(subDependent2); + // Assert.Equal(principal.Id, subDependent2Entry.Property("OrderDetailsId").CurrentValue); + // Assert.Equal(typeof(OrderDetails).DisplayName() + "." + nameof(OrderDetails.ShippingAddress) + "#" + typeof(Address).ShortDisplayName(), subDependent2Entry.Metadata.Name); + // }); } private static void Seed() diff --git a/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs b/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs index 12c75dda118..6064914722f 100644 --- a/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/InheritanceTestBase.cs @@ -124,7 +124,7 @@ public virtual void Can_set_and_remove_base_type() Assert.Null(pickle.BaseType); var pickleClone = modelBuilder.Model.Clone().FindEntityType(pickle.Name); - var initialProperties = pickleClone.GetProperties().ToList(); + var initialProperties = pickleClone.GetProperties().Where(p => p.Name != "__jObject").ToList(); var initialKeys = pickleClone.GetKeys().ToList(); var initialIndexes = pickleClone.GetIndexes().ToList(); var initialForeignKeys = pickleClone.GetForeignKeys().ToList(); @@ -135,9 +135,13 @@ public virtual void Can_set_and_remove_base_type() var ingredient = ingredientBuilder.Metadata; Assert.Same(typeof(Ingredient), pickle.BaseType.ClrType); + + var actualProperties = pickle.GetProperties().Where(p => p.Name != "__jObject").ToList(); AssertEqual( - initialProperties, pickle.GetProperties().Where(p => p.Name != "Discriminator"), + initialProperties.Where(p => p.Name != "Discriminator"), + actualProperties.Where(p => p.Name != "Discriminator"), new PropertyComparer(compareAnnotations: false)); + AssertEqual(initialKeys, pickle.GetKeys()); AssertEqual(initialIndexes, pickle.GetIndexes()); AssertEqual(initialForeignKeys, pickle.GetForeignKeys()); @@ -146,15 +150,19 @@ public virtual void Can_set_and_remove_base_type() pickleBuilder.HasBaseType(null); Assert.Null(pickle.BaseType); - AssertEqual(initialProperties, pickle.GetProperties(), new PropertyComparer(compareAnnotations: false)); + actualProperties = pickle.GetProperties().Where(p => p.Name != "__jObject").ToList(); + AssertEqual(initialProperties, actualProperties, new PropertyComparer(compareAnnotations: false)); AssertEqual(initialKeys, pickle.GetKeys()); AssertEqual(initialIndexes, pickle.GetIndexes()); AssertEqual(initialForeignKeys, pickle.GetForeignKeys()); AssertEqual(initialReferencingForeignKeys, pickle.GetReferencingForeignKeys()); + actualProperties = ingredient.GetProperties().Where(p => p.Name != "__jObject").ToList(); AssertEqual( - initialProperties, ingredient.GetProperties().Where(p => p.Name != "Discriminator"), + initialProperties.Where(p => p.Name != "Discriminator"), + actualProperties.Where(p => p.Name != "Discriminator"), new PropertyComparer(compareAnnotations: false)); + AssertEqual(initialKeys, ingredient.GetKeys()); AssertEqual(initialIndexes, ingredient.GetIndexes()); Assert.Equal(initialForeignKeys.Count(), ingredient.GetForeignKeys().Count()); diff --git a/test/EFCore.Tests/ModelBuilding/ModelBuilderNonGenericStringTest.cs b/test/EFCore.Tests/ModelBuilding/ModelBuilderNonGenericStringTest.cs index 3ae80cb2e28..2a2fef62cdf 100644 --- a/test/EFCore.Tests/ModelBuilding/ModelBuilderNonGenericStringTest.cs +++ b/test/EFCore.Tests/ModelBuilding/ModelBuilderNonGenericStringTest.cs @@ -12,6 +12,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; +using Xunit.Sdk; #nullable enable @@ -26,18 +27,14 @@ public class NonGenericStringOwnedTypes : OwnedTypesTestBase protected override TestModelBuilder CreateTestModelBuilder(TestHelpers testHelpers, Action? configure) => new NonGenericStringTestModelBuilder(testHelpers, configure); - // Shadow navigations not supported #3864 - public override void Can_configure_owned_type_collection_with_one_call() - { - } - public override void OwnedType_can_derive_from_Collection() { - } - - // Owned type configuration doesn't apply to "derived" types when using shadow entity types - public override void Can_configure_owned_type_collection_with_one_call_afterwards() - { + // Shadow navigations. Issue #3864. + Assert.Equal( + CoreStrings.AmbiguousSharedTypeEntityTypeName( + "Microsoft.EntityFrameworkCore.ModelBuilding.ModelBuilderTest+DependentEntity"), + Assert.Throws( + () => base.OwnedType_can_derive_from_Collection()).Message); } } @@ -49,6 +46,11 @@ protected override TestModelBuilder CreateTestModelBuilder(TestHelpers testHelpe public override void WithMany_pointing_to_keyless_entity_throws() { // Test throws exception before reaching the first exception due to entity type being property bag entity + Assert.Equal( + CoreStrings.NavigationSingleWrongClrType( + "Reference", "KeylessCollectionNavigation", "KeylessReferenceNavigation", "Dictionary"), + Assert.Throws( + () => base.WithMany_pointing_to_keyless_entity_throws()).Actual); } } diff --git a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs index e115c2b47c6..bc31fe3324f 100644 --- a/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/NonRelationshipTestBase.cs @@ -654,8 +654,9 @@ public virtual void Properties_specified_by_string_are_shadow_properties_unless_ Assert.Equal(-1, entityType.FindProperty("Up").GetShadowIndex()); Assert.Equal(-1, entityType.FindProperty("Down").GetShadowIndex()); - Assert.Equal(0, entityType.FindProperty("Gluon").GetShadowIndex()); - Assert.Equal(1, entityType.FindProperty("Photon").GetShadowIndex()); + Assert.NotEqual(-1, entityType.FindProperty("Gluon").GetShadowIndex()); + Assert.NotEqual(-1, entityType.FindProperty("Photon").GetShadowIndex()); + Assert.NotEqual(entityType.FindProperty("Gluon").GetShadowIndex(), entityType.FindProperty("Photon").GetShadowIndex()); } [ConditionalFact]