diff --git a/test/EFCore.InMemory.FunctionalTests/Query/IncompleteMappingInheritanceQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/IncompleteMappingInheritanceQueryInMemoryTest.cs index 16166a04634..7c9699316b7 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/IncompleteMappingInheritanceQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/IncompleteMappingInheritanceQueryInMemoryTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; using Xunit; @@ -14,10 +15,10 @@ public IncompleteMappingInheritanceQueryInMemoryTest(IncompleteMappingInheritanc { } - [ConditionalFact] - public override void Can_query_all_animal_views() + public override async Task Can_query_all_animal_views(bool async) { - var message = Assert.Throws(() => base.Can_query_all_animal_views()).Message; + var message = (await Assert.ThrowsAsync( + () => base.Can_query_all_animal_views(async))).Message; Assert.Equal( CoreStrings.TranslationFailed( diff --git a/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryFixture.cs b/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryFixture.cs index 6c9a9073f25..17cc34add13 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryFixture.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryFixture.cs @@ -4,7 +4,7 @@ using System; using System.Linq; using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Microsoft.EntityFrameworkCore.TestUtilities; namespace Microsoft.EntityFrameworkCore.Query diff --git a/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryTest.cs b/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryTest.cs index 5a49b1a4a81..ab00d72d334 100644 --- a/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryTest.cs +++ b/test/EFCore.InMemory.FunctionalTests/Query/InheritanceQueryInMemoryTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Diagnostics; using Xunit; using Xunit.Abstractions; @@ -16,10 +17,10 @@ public InheritanceQueryInMemoryTest(InheritanceQueryInMemoryFixture fixture, ITe //TestLoggerFactory.TestOutputHelper = testOutputHelper; } - [ConditionalFact] - public override void Can_query_all_animal_views() + public override async Task Can_query_all_animal_views(bool async) { - var message = Assert.Throws(() => base.Can_query_all_animal_views()).Message; + var message = (await Assert.ThrowsAsync( + () => base.Can_query_all_animal_views(async))).Message; Assert.Equal( CoreStrings.TranslationFailed( diff --git a/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs b/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs index f0a8a4186eb..a6b9990b5ad 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/InheritanceQueryRelationalFixture.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Microsoft.EntityFrameworkCore.TestUtilities; namespace Microsoft.EntityFrameworkCore.Query @@ -33,7 +33,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity().Property(e => e.CaffeineGrams).HasColumnName("CaffeineGrams"); modelBuilder.Entity().HasNoKey().ToQuery( - () => context.Set().FromSqlRaw("SELECT * FROM Animal")); + () => context.Set().FromSqlRaw("SELECT * FROM Animals")); modelBuilder.Entity().HasDiscriminator().HasValue("Kiwi"); modelBuilder.Entity().HasDiscriminator().HasValue("Eagle"); } diff --git a/test/EFCore.Relational.Specification.Tests/Query/InheritanceRelationalQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/InheritanceRelationalQueryTestBase.cs index 66bc4ee529c..a102aebd8a2 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/InheritanceRelationalQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/InheritanceRelationalQueryTestBase.cs @@ -3,7 +3,7 @@ using System; using System.Linq; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; @@ -22,14 +22,14 @@ protected InheritanceRelationalQueryTestBase(TFixture fixture) public virtual void FromSql_on_root() { using var context = CreateContext(); - context.Set().FromSqlRaw(NormalizeDelimitersInRawString("select * from [Animal]")).ToList(); + context.Set().FromSqlRaw(NormalizeDelimitersInRawString("select * from [Animals]")).ToList(); } [ConditionalFact] public virtual void FromSql_on_derived() { using var context = CreateContext(); - context.Set().FromSqlRaw(NormalizeDelimitersInRawString("select * from [Animal]")).ToList(); + context.Set().FromSqlRaw(NormalizeDelimitersInRawString("select * from [Animals]")).ToList(); } [ConditionalFact] @@ -44,7 +44,7 @@ public virtual void Casting_to_base_type_joining_with_query_type_works() private void GetEntityWithAuditHistoryQuery(InheritanceContext context, IQueryable query) where T : Animal { - var queryTypeQuery = context.Set().FromSqlRaw(NormalizeDelimitersInRawString("Select * from [Animal]")); + var queryTypeQuery = context.Set().FromSqlRaw(NormalizeDelimitersInRawString("Select * from [Animals]")); var animalQuery = query.Cast(); diff --git a/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryFixture.cs b/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryFixture.cs index bf1a61295d9..5a4a8ad2f97 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryFixture.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryFixture.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Microsoft.EntityFrameworkCore.TestUtilities; namespace Microsoft.EntityFrameworkCore.Query diff --git a/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryTestBase.cs index 98bd092e199..9941e982c91 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/TPTInheritanceQueryTestBase.cs @@ -3,6 +3,7 @@ // ReSharper disable InconsistentNaming +using System.Threading.Tasks; using Xunit; namespace Microsoft.EntityFrameworkCore.Query @@ -15,190 +16,190 @@ public TPTInheritanceQueryTestBase(TFixture fixture) { } - [ConditionalFact(Skip = "Issue#2266")] - public override void Byte_enum_value_constant_used_in_projection() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Byte_enum_value_constant_used_in_projection(bool async) { - base.Byte_enum_value_constant_used_in_projection(); + return base.Byte_enum_value_constant_used_in_projection(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_filter_all_animals() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_filter_all_animals(bool async) { - base.Can_filter_all_animals(); + return base.Can_filter_all_animals(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_include_animals() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_include_animals(bool async) { - base.Can_include_animals(); + return base.Can_include_animals(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_include_prey() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_include_prey(bool async) { - base.Can_include_prey(); + return base.Can_include_prey(async); } - [ConditionalFact(Skip = "Issue#2266")] + [ConditionalTheory(Skip = "Issue#2266")] public override void Can_insert_update_delete() { base.Can_insert_update_delete(); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_all_animals() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_all_animals(bool async) { - base.Can_query_all_animals(); + return base.Can_query_all_animals(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_all_animal_views() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_all_animal_views(bool async) { - base.Can_query_all_animal_views(); + return base.Can_query_all_animal_views(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_all_birds() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_all_birds(bool async) { - base.Can_query_all_birds(); + return base.Can_query_all_birds(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_all_plants() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_all_plants(bool async) { - base.Can_query_all_plants(); + return base.Can_query_all_plants(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_all_types_when_shared_column() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_all_types_when_shared_column(bool async) { - base.Can_query_all_types_when_shared_column(); + return base.Can_query_all_types_when_shared_column(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_just_kiwis() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_just_kiwis(bool async) { - base.Can_query_just_kiwis(); + return base.Can_query_just_kiwis(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_just_roses() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_just_roses(bool async) { - base.Can_query_just_roses(); + return base.Can_query_just_roses(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_query_when_shared_column() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_query_when_shared_column(bool async) { - base.Can_query_when_shared_column(); + return base.Can_query_when_shared_column(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_backwards_is_animal() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_backwards_is_animal(bool async) { - base.Can_use_backwards_is_animal(); + return base.Can_use_backwards_is_animal(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_backwards_of_type_animal() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_backwards_of_type_animal(bool async) { - base.Can_use_backwards_of_type_animal(); + return base.Can_use_backwards_of_type_animal(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_is_kiwi() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_is_kiwi(bool async) { - base.Can_use_is_kiwi(); + return base.Can_use_is_kiwi(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_is_kiwi_in_projection() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_is_kiwi_in_projection(bool async) { - base.Can_use_is_kiwi_in_projection(); + return base.Can_use_is_kiwi_in_projection(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_is_kiwi_with_other_predicate() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_is_kiwi_with_other_predicate(bool async) { - base.Can_use_is_kiwi_with_other_predicate(); + return base.Can_use_is_kiwi_with_other_predicate(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_animal() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_animal(bool async) { - base.Can_use_of_type_animal(); + return base.Can_use_of_type_animal(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_bird() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_bird(bool async) { - base.Can_use_of_type_bird(); + return base.Can_use_of_type_bird(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_bird_first() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_bird_first(bool async) { - base.Can_use_of_type_bird_first(); + return base.Can_use_of_type_bird_first(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_bird_predicate() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_bird_predicate(bool async) { - base.Can_use_of_type_bird_predicate(); + return base.Can_use_of_type_bird_predicate(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_bird_with_projection() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_bird_with_projection(bool async) { - base.Can_use_of_type_bird_with_projection(); + return base.Can_use_of_type_bird_with_projection(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_kiwi() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_kiwi(bool async) { - base.Can_use_of_type_kiwi(); + return base.Can_use_of_type_kiwi(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_kiwi_where_north_on_derived_property() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_kiwi_where_north_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_north_on_derived_property(); + return base.Can_use_of_type_kiwi_where_north_on_derived_property(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_kiwi_where_south_on_derived_property() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_kiwi_where_south_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_south_on_derived_property(); + return base.Can_use_of_type_kiwi_where_south_on_derived_property(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Can_use_of_type_rose() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Can_use_of_type_rose(bool async) { - base.Can_use_of_type_rose(); + return base.Can_use_of_type_rose(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Discriminator_used_when_projection_over_derived_type() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Discriminator_used_when_projection_over_derived_type(bool async) { - base.Discriminator_used_when_projection_over_derived_type(); + return base.Discriminator_used_when_projection_over_derived_type(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Discriminator_used_when_projection_over_derived_type2() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Discriminator_used_when_projection_over_derived_type2(bool async) { - base.Discriminator_used_when_projection_over_derived_type2(); + return base.Discriminator_used_when_projection_over_derived_type2(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Discriminator_used_when_projection_over_of_type() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Discriminator_used_when_projection_over_of_type(bool async) { - base.Discriminator_used_when_projection_over_of_type(); + return base.Discriminator_used_when_projection_over_of_type(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Discriminator_with_cast_in_shadow_property() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Discriminator_with_cast_in_shadow_property(bool async) { - base.Discriminator_with_cast_in_shadow_property(); + return base.Discriminator_with_cast_in_shadow_property(async); } [ConditionalFact(Skip = "Issue#2266")] @@ -207,16 +208,16 @@ public override void Member_access_on_intermediate_type_works() base.Member_access_on_intermediate_type_works(); } - [ConditionalFact(Skip = "Issue#2266")] - public override void OfType_Union_OfType() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task OfType_Union_OfType(bool async) { - base.OfType_Union_OfType(); + return base.OfType_Union_OfType(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void OfType_Union_subquery() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task OfType_Union_subquery(bool async) { - base.OfType_Union_subquery(); + return base.OfType_Union_subquery(async); } [ConditionalFact(Skip = "Issue#2266")] @@ -225,22 +226,22 @@ public override void Setting_foreign_key_to_a_different_type_throws() base.Setting_foreign_key_to_a_different_type_throws(); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Subquery_OfType() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Subquery_OfType(bool async) { - base.Subquery_OfType(); + return base.Subquery_OfType(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Union_entity_equality() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Union_entity_equality(bool async) { - base.Union_entity_equality(); + return base.Union_entity_equality(async); } - [ConditionalFact(Skip = "Issue#2266")] - public override void Union_siblings_with_duplicate_property_in_subquery() + [ConditionalTheory(Skip = "Issue#2266")] + public override Task Union_siblings_with_duplicate_property_in_subquery(bool async) { - base.Union_siblings_with_duplicate_property_in_subquery(); + return base.Union_siblings_with_duplicate_property_in_subquery(async); } } } diff --git a/test/EFCore.Specification.Tests/Query/FiltersInheritanceQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/FiltersInheritanceQueryTestBase.cs index 2b20c20ecba..09eefb2d13e 100644 --- a/test/EFCore.Specification.Tests/Query/FiltersInheritanceQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/FiltersInheritanceQueryTestBase.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Xunit; // ReSharper disable StringStartsWithIsCultureSpecific diff --git a/test/EFCore.Specification.Tests/Query/InheritanceQueryFixtureBase.cs b/test/EFCore.Specification.Tests/Query/InheritanceQueryFixtureBase.cs index d93d2349253..53b6b22fb9c 100644 --- a/test/EFCore.Specification.Tests/Query/InheritanceQueryFixtureBase.cs +++ b/test/EFCore.Specification.Tests/Query/InheritanceQueryFixtureBase.cs @@ -1,17 +1,338 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; +using Microsoft.EntityFrameworkCore.TestUtilities; +using Xunit; namespace Microsoft.EntityFrameworkCore.Query { - public abstract class InheritanceQueryFixtureBase : SharedStoreFixtureBase + public abstract class InheritanceQueryFixtureBase : SharedStoreFixtureBase, IQueryFixtureBase { protected override string StoreName { get; } = "InheritanceTest"; protected virtual bool EnableFilters => false; protected virtual bool IsDiscriminatorMappingComplete => true; protected virtual bool HasDiscriminator => true; + public Func GetContextCreator() => () => CreateContext(); + + public ISetSource GetExpectedData() => new InheritanceData(); + + public IReadOnlyDictionary GetEntitySorters() + => new Dictionary> + { + { typeof(Animal), e => ((Animal)e)?.Species }, + { typeof(Bird), e => ((Bird)e)?.Species }, + { typeof(Kiwi), e => ((Kiwi)e)?.Species }, + { typeof(Eagle), e => ((Eagle)e)?.Species }, + { typeof(AnimalQuery), e => ((AnimalQuery)e)?.Name }, + { typeof(BirdQuery), e => ((BirdQuery)e)?.Name }, + { typeof(KiwiQuery), e => ((KiwiQuery)e)?.Name }, + { typeof(EagleQuery), e => ((EagleQuery)e)?.Name }, + { typeof(Plant), e => ((Plant)e)?.Species }, + { typeof(Flower), e => ((Flower)e)?.Species }, + { typeof(Daisy), e => ((Daisy)e)?.Species }, + { typeof(Rose), e => ((Rose)e)?.Species }, + { typeof(Country), e => ((Country)e)?.Id }, + { typeof(Drink), e => ((Drink)e)?.Id }, + { typeof(Coke), e => ((Coke)e)?.Id }, + { typeof(Lilt), e => ((Lilt)e)?.Id }, + { typeof(Tea), e => ((Tea)e)?.Id }, + }.ToDictionary(e => e.Key, e => (object)e.Value); + + public IReadOnlyDictionary GetEntityAsserters() + => new Dictionary> + { + { + typeof(Animal), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Animal)e; + var aa = (Animal)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + } + } + }, + { + typeof(Bird), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Bird)e; + var aa = (Bird)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + } + } + }, + { + typeof(Eagle), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Eagle)e; + var aa = (Eagle)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + Assert.Equal(ee.Group, aa.Group); + } + } + }, + { + typeof(Kiwi), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Kiwi)e; + var aa = (Kiwi)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + Assert.Equal(ee.FoundOn, aa.FoundOn); + } + } + }, + { + typeof(AnimalQuery), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (AnimalQuery)e; + var aa = (AnimalQuery)a; + + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + } + } + }, + { + typeof(BirdQuery), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (BirdQuery)e; + var aa = (BirdQuery)a; + + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + } + } + }, + { + typeof(EagleQuery), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (EagleQuery)e; + var aa = (EagleQuery)a; + + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + Assert.Equal(ee.Group, aa.Group); + } + } + }, + { + typeof(KiwiQuery), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (KiwiQuery)e; + var aa = (KiwiQuery)a; + + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.CountryId, aa.CountryId); + Assert.Equal(ee.IsFlightless, aa.IsFlightless); + Assert.Equal(ee.EagleId, aa.EagleId); + Assert.Equal(ee.FoundOn, aa.FoundOn); + } + } + }, + { + typeof(Plant), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Plant)e; + var aa = (Plant)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.Genus, aa.Genus); + } + } + }, + { + typeof(Flower), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Flower)e; + var aa = (Flower)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.Genus, aa.Genus); + } + } + }, + { + typeof(Daisy), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Daisy)e; + var aa = (Daisy)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.Genus, aa.Genus); + } + } + }, + { + typeof(Rose), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Rose)e; + var aa = (Rose)a; + + Assert.Equal(ee.Species, aa.Species); + Assert.Equal(ee.Name, aa.Name); + Assert.Equal(ee.Genus, aa.Genus); + Assert.Equal(ee.HasThorns, aa.HasThorns); + } + } + }, + { + typeof(Country), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Country)e; + var aa = (Country)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.Name, aa.Name); + } + } + }, + { + typeof(Drink), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Drink)e; + var aa = (Drink)a; + + Assert.Equal(ee.Id, aa.Id); + } + } + }, + { + typeof(Coke), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Coke)e; + var aa = (Coke)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.SugarGrams, aa.SugarGrams); + Assert.Equal(ee.CaffeineGrams, aa.CaffeineGrams); + Assert.Equal(ee.Carbonation, aa.Carbonation); + + } + } + }, + { + typeof(Lilt), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Lilt)e; + var aa = (Lilt)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.SugarGrams, aa.SugarGrams); + Assert.Equal(ee.Carbonation, aa.Carbonation); + + } + } + }, + { + typeof(Tea), (e, a) => + { + Assert.Equal(e == null, a == null); + + if (a != null) + { + var ee = (Tea)e; + var aa = (Tea)a; + + Assert.Equal(ee.Id, aa.Id); + Assert.Equal(ee.HasMilk, aa.HasMilk); + Assert.Equal(ee.CaffeineGrams, aa.CaffeineGrams); + } + } + }, + }.ToDictionary(e => e.Key, e => (object)e.Value); + protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context) { modelBuilder.Entity(); @@ -28,6 +349,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity(); modelBuilder.Entity(); + modelBuilder.Entity().Property(m => m.Id).ValueGeneratedNever(); + if (HasDiscriminator) { modelBuilder.Entity().HasDiscriminator("Discriminator").IsComplete(IsDiscriminatorMappingComplete); @@ -46,6 +369,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con modelBuilder.Entity(); } - protected override void Seed(InheritanceContext context) => InheritanceContext.SeedData(context); + protected override void Seed(InheritanceContext context) => InheritanceContext.Seed(context); + + public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder) + => base.AddOptions(builder); } } diff --git a/test/EFCore.Specification.Tests/Query/InheritanceQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/InheritanceQueryTestBase.cs index 551dddeadc3..b30dc493a12 100644 --- a/test/EFCore.Specification.Tests/Query/InheritanceQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/InheritanceQueryTestBase.cs @@ -3,9 +3,10 @@ using System.Linq; using System.Linq.Expressions; +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; @@ -14,373 +15,345 @@ // ReSharper disable StringEndsWithIsCultureSpecific namespace Microsoft.EntityFrameworkCore.Query { - public abstract class InheritanceQueryTestBase : IClassFixture + public abstract class InheritanceQueryTestBase : QueryTestBase where TFixture : InheritanceQueryFixtureBase, new() { - protected InheritanceQueryTestBase(TFixture fixture) => Fixture = fixture; - - protected TFixture Fixture { get; } - - [ConditionalFact] - public virtual void Can_query_when_shared_column() + protected InheritanceQueryTestBase(TFixture fixture) + : base(fixture) { - using var context = CreateContext(); - var coke = context.Set().Single(); - Assert.Equal(6, coke.SugarGrams); - Assert.Equal(4, coke.CaffeineGrams); - Assert.Equal(5, coke.Carbonation); - - var lilt = context.Set().Single(); - Assert.Equal(4, lilt.SugarGrams); - Assert.Equal(7, lilt.Carbonation); - - var tea = context.Set().Single(); - Assert.True(tea.HasMilk); - Assert.Equal(1, tea.CaffeineGrams); } - [ConditionalFact] - public virtual void Can_query_all_types_when_shared_column() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Can_query_when_shared_column(bool async) { - using var context = CreateContext(); - var drinks = context.Set().ToList(); - Assert.Equal(3, drinks.Count); + await AssertSingle( + async, + ss => ss.Set(), + entryCount: 1); - var coke = drinks.OfType().Single(); - Assert.Equal(6, coke.SugarGrams); - Assert.Equal(4, coke.CaffeineGrams); - Assert.Equal(5, coke.Carbonation); + await AssertSingle( + async, + ss => ss.Set(), + entryCount: 1); - var lilt = drinks.OfType().Single(); - Assert.Equal(4, lilt.SugarGrams); - Assert.Equal(7, lilt.Carbonation); - - var tea = drinks.OfType().Single(); - Assert.True(tea.HasMilk); - Assert.Equal(1, tea.CaffeineGrams); + await AssertSingle( + async, + ss => ss.Set(), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_animal() - { - using var context = CreateContext(); - var animals = context.Set().OfType().OrderBy(a => a.Species).ToList(); - Assert.Equal(2, animals.Count); - Assert.IsType(animals[0]); - Assert.IsType(animals[1]); - Assert.Equal(2, context.ChangeTracker.Entries().Count()); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_all_types_when_shared_column(bool async) + { + return AssertQuery( + async, + ss => ss.Set(), + entryCount: 3); } - [ConditionalFact] - public virtual void Can_use_is_kiwi() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_animal(bool async) { - using var context = CreateContext(); - var kiwis = context.Set().Where(a => a is Kiwi).ToList(); - - Assert.Single(kiwis); + return AssertQuery( + async, + ss => ss.Set().OfType().OrderBy(a => a.Species), + assertOrder: true, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_use_backwards_is_animal() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_is_kiwi(bool async) { - using var context = CreateContext(); - // ReSharper disable once IsExpressionAlwaysTrue - var kiwis = context.Set().Where(a => a is Animal).ToList(); - - Assert.Single(kiwis); + return AssertQuery( + async, + ss => ss.Set().Where(a => a is Kiwi), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_is_kiwi_with_other_predicate() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_backwards_is_animal(bool async) { - using var context = CreateContext(); - var animals = context.Set().Where(a => a is Kiwi && a.CountryId == 1).ToList(); - - Assert.Single(animals); + return AssertQuery( + async, + // ReSharper disable once IsExpressionAlwaysTrue + ss => ss.Set().Where(a => a is Animal), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_is_kiwi_in_projection() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_is_kiwi_with_other_predicate(bool async) { - using var context = CreateContext(); - var animals = context.Set().Select(a => a is Kiwi).ToList(); - - Assert.Equal(2, animals.Count); - Assert.Equal(1, animals.Count(a => a)); - Assert.Equal(1, animals.Count(a => !a)); + return AssertQuery( + async, + ss => ss.Set().Where(a => a is Kiwi && a.CountryId == 1), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_bird() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_is_kiwi_in_projection(bool async) { - using var context = CreateContext(); - var animals = context.Set().OfType().OrderBy(a => a.Species).ToList(); + return AssertQueryScalar( + async, + ss => ss.Set().Select(a => a is Kiwi)); + } - Assert.Equal(2, animals.Count); - Assert.IsType(animals[0]); - Assert.IsType(animals[1]); - Assert.Equal(2, context.ChangeTracker.Entries().Count()); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_bird(bool async) + { + return AssertQuery( + async, + ss => ss.Set().OfType().OrderBy(a => a.Species), + assertOrder: true, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_use_of_type_bird_predicate() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_bird_predicate(bool async) { - using var context = CreateContext(); - var animals - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .Where(a => a.CountryId == 1) .OfType() - .OrderBy(a => a.Species) - .ToList(); - - Assert.Single(animals); - Assert.IsType(animals[0]); - Assert.Single(context.ChangeTracker.Entries()); + .OrderBy(a => a.Species), + assertOrder: true, + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_bird_with_projection() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_bird_with_projection(bool async) { - using var context = CreateContext(); - var animals - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .OfType() - .Select( - b => new { b.EagleId }) - .ToList(); - - Assert.Equal(2, animals.Count); - Assert.Empty(context.ChangeTracker.Entries()); + .Select(b => new { b.EagleId })); } - [ConditionalFact] - public virtual void Can_use_of_type_bird_first() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_bird_first(bool async) { - using var context = CreateContext(); - var bird = context.Set().OfType().OrderBy(a => a.Species).First(); - - Assert.NotNull(bird); - Assert.IsType(bird); - Assert.Single(context.ChangeTracker.Entries()); + return AssertFirst( + async, + ss => ss.Set().OfType().OrderBy(a => a.Species), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_kiwi() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_kiwi(bool async) { - using var context = CreateContext(); - var animals = context.Set().OfType().ToList(); - - Assert.Single(animals); - Assert.IsType(animals[0]); - Assert.Single(context.ChangeTracker.Entries()); + return AssertQuery( + async, + ss => ss.Set().OfType(), + entryCount: 1); } - [ConditionalFact(Skip = "Issue#17364")] - public virtual void Can_use_backwards_of_type_animal() + [ConditionalTheory(Skip = "Issue#17364")] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_backwards_of_type_animal(bool async) { - using var context = CreateContext(); - var animals = context.Set().OfType().ToList(); - - Assert.Single(animals); - Assert.IsType(animals[0]); - Assert.Single(context.ChangeTracker.Entries()); + return AssertQuery( + async, + ss => ss.Set().OfType(), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_rose() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_rose(bool async) { - using var context = CreateContext(); - var plants = context.Set().OfType().ToList(); - - Assert.Single(plants); - Assert.IsType(plants[0]); - Assert.Single(context.ChangeTracker.Entries()); + return AssertQuery( + async, + ss => ss.Set().OfType(), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_query_all_animals() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_all_animals(bool async) { - using var context = CreateContext(); - var animals = context.Set().OrderBy(a => a.Species).ToList(); - - Assert.Equal(2, animals.Count); - Assert.IsType(animals[0]); - Assert.IsType(animals[1]); + return AssertQuery( + async, + ss => ss.Set().OrderBy(a => a.Species), + assertOrder: true, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_query_all_animal_views() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_all_animal_views(bool async) { - using var context = CreateContext(); - var animalQueries = context.Set().OrderBy(av => av.CountryId).ToList(); - - Assert.Equal(2, animalQueries.Count); - Assert.IsType(animalQueries[0]); - Assert.IsType(animalQueries[1]); + return AssertQuery( + async, + ss => ss.Set().OrderBy(av => av.CountryId), + assertOrder: true); } - [ConditionalFact] - public virtual void Can_query_all_plants() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_all_plants(bool async) { - using var context = CreateContext(); - var plants = context.Set().OrderBy(a => a.Species).ToList(); - - Assert.Equal(2, plants.Count); - Assert.IsType(plants[0]); - Assert.IsType(plants[1]); + return AssertQuery( + async, + ss => ss.Set().OrderBy(a => a.Species), + assertOrder: true, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_filter_all_animals() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_filter_all_animals(bool async) { - using var context = CreateContext(); - var animals - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .OrderBy(a => a.Species) - .Where(a => a.Name == "Great spotted kiwi") - .ToList(); - - Assert.Single(animals); - Assert.IsType(animals[0]); + .Where(a => a.Name == "Great spotted kiwi"), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_query_all_birds() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_all_birds(bool async) { - using var context = CreateContext(); - var birds = context.Set().OrderBy(a => a.Species).ToList(); - - Assert.Equal(2, birds.Count); - Assert.IsType(birds[0]); - Assert.IsType(birds[1]); + return AssertQuery( + async, + ss => ss.Set().OrderBy(a => a.Species), + assertOrder: true, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_query_just_kiwis() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_just_kiwis(bool async) { - using var context = CreateContext(); - var kiwi = context.Set().Single(); - - Assert.NotNull(kiwi); + return AssertSingle( + async, + ss => ss.Set(), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_query_just_roses() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_query_just_roses(bool async) { - using var context = CreateContext(); - var rose = context.Set().Single(); - - Assert.NotNull(rose); + return AssertSingle( + async, + ss => ss.Set(), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_include_animals() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_include_animals(bool async) { - using var context = CreateContext(); - var countries - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .OrderBy(c => c.Name) - .Include(c => c.Animals) - .ToList(); - - Assert.Equal(2, countries.Count); - Assert.IsType(countries[0].Animals[0]); - Assert.IsType(countries[1].Animals[0]); + .Include(c => c.Animals), + entryCount: 4, + elementAsserter: (e, a) => + { + AssertInclude(e, a, new ExpectedInclude(x => x.Animals)); + }); } - [ConditionalFact] - public virtual void Can_include_prey() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_include_prey(bool async) { - using var context = CreateContext(); - var eagle - = context.Set() - .Include(e => e.Prey) - .Single(); - - Assert.NotNull(eagle); - Assert.Equal(1, eagle.Prey.Count); + return AssertSingle( + async, + ss => ss.Set() + .Include(e => e.Prey), + asserter: (e, a) => + { + AssertInclude(e, a, new ExpectedInclude(x => x.Prey)); + }, + entryCount: 2); } - [ConditionalFact] - public virtual void Can_use_of_type_kiwi_where_south_on_derived_property() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_kiwi_where_south_on_derived_property(bool async) { - using var context = CreateContext(); - var animals - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .OfType() - .Where(x => x.FoundOn == Island.South) - .ToList(); - - Assert.Single(animals); - Assert.IsType(animals[0]); - Assert.Single(context.ChangeTracker.Entries()); + .Where(x => x.FoundOn == Island.South), + entryCount: 1); } - [ConditionalFact] - public virtual void Can_use_of_type_kiwi_where_north_on_derived_property() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Can_use_of_type_kiwi_where_north_on_derived_property(bool async) { - using var context = CreateContext(); - var animals - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .OfType() - .Where(x => x.FoundOn == Island.North) - .ToList(); - - Assert.Empty(animals); - Assert.Empty(context.ChangeTracker.Entries()); + .Where(x => x.FoundOn == Island.North)); } - [ConditionalFact] - public virtual void Discriminator_used_when_projection_over_derived_type() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Discriminator_used_when_projection_over_derived_type(bool async) { - using var context = CreateContext(); - var kiwis - = context.Set() - .Select(k => k.FoundOn) - .ToArray(); - - Assert.Single(kiwis); + return AssertQueryScalar( + async, + ss => ss.Set().Select(k => k.FoundOn)); } - [ConditionalFact] - public virtual void Discriminator_used_when_projection_over_derived_type2() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Discriminator_used_when_projection_over_derived_type2(bool async) { - using var context = CreateContext(); - var birds - = context.Set() - .Select( - b => new { b.IsFlightless, Discriminator = EF.Property(b, "Discriminator") }) - .ToArray(); - - Assert.Equal(2, birds.Length); + return AssertQuery( + async, + ss => ss.Set() + .Select(b => new { b.IsFlightless, Discriminator = EF.Property(b, "Discriminator") }), + ss => ss.Set() + .Select(b => new { b.IsFlightless, Discriminator = b.GetType().Name }), + elementSorter: e => (e.IsFlightless, e.Discriminator)); } - [ConditionalFact] - public virtual void Discriminator_with_cast_in_shadow_property() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Discriminator_with_cast_in_shadow_property(bool async) { - using var context = CreateContext(); - var predators - = context.Set() + return AssertQuery( + async, + ss => ss.Set() .Where(b => "Kiwi" == EF.Property(b, "Discriminator")) - .Select( - k => new { Predator = EF.Property((Bird)k, "EagleId") }) - .ToArray(); - - Assert.Single(predators); + .Select(k => new { Predator = EF.Property((Bird)k, "EagleId") }), + ss => ss.Set() + .Where(b => b is Kiwi) + .Select(k => new { Predator = ((Bird)k).EagleId }), + elementSorter: e => e.Predator); } - [ConditionalFact] - public virtual void Discriminator_used_when_projection_over_of_type() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Discriminator_used_when_projection_over_of_type(bool async) { - using var context = CreateContext(); - var birds - = context.Set() - .OfType() - .Select(k => k.FoundOn) - .ToArray(); - - Assert.Single(birds); + return AssertQueryScalar( + async, + ss => ss.Set().OfType().Select(k => k.FoundOn)); } [ConditionalFact] @@ -435,67 +408,66 @@ protected virtual void UseTransaction(DatabaseFacade facade, IDbContextTransacti { } - [ConditionalFact(Skip = "Issue#16298")] - public virtual void Union_siblings_with_duplicate_property_in_subquery() + [ConditionalTheory(Skip = "Issue#16298")] + [MemberData(nameof(IsAsyncData))] + public virtual Task Union_siblings_with_duplicate_property_in_subquery(bool async) { // Coke and Tea both have CaffeineGrams, which both need to be projected out on each side and so // requiring alias uniquification. They also have a different number of properties. - using var context = CreateContext(); - var cokes = context.Set(); - - var teas = context.Set(); - - var concat = cokes.Cast() - .Union(teas) - .Where(d => d.Id > 0) - .ToList(); - - Assert.Equal(2, concat.Count); + return AssertQuery( + async, + ss => ss.Set().Cast() + .Union(ss.Set()) + .Where(d => d.Id > 0), + entryCount: 2); } - [ConditionalFact(Skip = "Issue#16298")] - public virtual void OfType_Union_subquery() + [ConditionalTheory(Skip = "Issue#16298")] + [MemberData(nameof(IsAsyncData))] + public virtual Task OfType_Union_subquery(bool async) { - using var context = CreateContext(); - context.Set() - .OfType() - .Union( - context.Set() - .OfType()) - .Where(o => o.FoundOn == Island.North) - .ToList(); + return AssertQuery( + async, + ss => ss.Set() + .OfType() + .Union(ss.Set().OfType()) + .Where(o => o.FoundOn == Island.North)); } - [ConditionalFact(Skip = "Issue#16298")] - public virtual void OfType_Union_OfType() + [ConditionalTheory(Skip = "Issue#16298")] + [MemberData(nameof(IsAsyncData))] + public virtual Task OfType_Union_OfType(bool async) { - using var context = CreateContext(); - context.Set() - .OfType() - .Union(context.Set()) - .OfType() - .ToList(); + return AssertQuery( + async, + ss => ss.Set() + .OfType() + .Union(ss.Set()) + .OfType()); } - [ConditionalFact] - public virtual void Subquery_OfType() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Subquery_OfType(bool async) { - using var context = CreateContext(); - context.Set() - .Take(5) - .Distinct() // Causes pushdown - .OfType() - .ToList(); + return AssertQuery( + async, + ss => ss.Set() + .Take(5) + .Distinct() + .OfType(), + entryCount: 1); } - [ConditionalFact(Skip = "Issue#16298")] - public virtual void Union_entity_equality() + [ConditionalTheory(Skip = "Issue#16298")] + [MemberData(nameof(IsAsyncData))] + public virtual Task Union_entity_equality(bool async) { - using var context = CreateContext(); - context.Set() - .Union(context.Set().Cast()) - .Where(b => b == null) - .ToList(); + return AssertQuery( + async, + ss => ss.Set() + .Union(ss.Set().Cast()) + .Where(b => b == null)); } [ConditionalFact] @@ -524,15 +496,13 @@ public virtual void Setting_foreign_key_to_a_different_type_throws() } } - [ConditionalFact] - public virtual void Byte_enum_value_constant_used_in_projection() + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Byte_enum_value_constant_used_in_projection(bool async) { - using var context = CreateContext(); - var query = context.Set().Select(k => k.IsFlightless ? Island.North : Island.South); - var result = query.ToList(); - - Assert.Single(result); - Assert.Equal(Island.North, result[0]); + return AssertQueryScalar( + async, + ss => ss.Set().Select(k => k.IsFlightless ? Island.North : Island.South)); } [ConditionalFact] diff --git a/test/EFCore.Specification.Tests/TestModels/ComplexNavigationsModel/ComplexNavigationsContext.cs b/test/EFCore.Specification.Tests/TestModels/ComplexNavigationsModel/ComplexNavigationsContext.cs index 723d7bf5d47..ed5bf2cb951 100644 --- a/test/EFCore.Specification.Tests/TestModels/ComplexNavigationsModel/ComplexNavigationsContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/ComplexNavigationsModel/ComplexNavigationsContext.cs @@ -7,8 +7,6 @@ namespace Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel { public class ComplexNavigationsContext : PoolableDbContext { - public static readonly string StoreName = "ComplexNavigations"; - public ComplexNavigationsContext(DbContextOptions options) : base(options) { diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarContext.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarContext.cs index 00d99a3173f..538cc48691f 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarContext.cs @@ -7,8 +7,6 @@ namespace Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel { public class GearsOfWarContext : PoolableDbContext { - public static readonly string StoreName = "GearsOfWar"; - public GearsOfWarContext(DbContextOptions options) : base(options) { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/InheritanceContext.cs b/test/EFCore.Specification.Tests/TestModels/Inheritance/InheritanceContext.cs deleted file mode 100644 index 2163a3925c6..00000000000 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/InheritanceContext.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.EntityFrameworkCore.TestUtilities; - -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance -{ - public class InheritanceContext : PoolableDbContext - { - public InheritanceContext(DbContextOptions options) - : base(options) - { - } - - public static void SeedData(InheritanceContext context) - { - var kiwi = new Kiwi - { - Species = "Apteryx haastii", - Name = "Great spotted kiwi", - IsFlightless = true, - FoundOn = Island.South - }; - - var eagle = new Eagle - { - Species = "Aquila chrysaetos canadensis", - Name = "American golden eagle", - Group = EagleGroup.Booted - }; - - eagle.Prey.Add(kiwi); - - var rose = new Rose - { - Species = "Rosa canina", - Name = "Dog-rose", - HasThorns = true - }; - - var daisy = new Daisy { Species = "Bellis perennis", Name = "Common daisy" }; - - var nz = new Country { Id = 1, Name = "New Zealand" }; - - nz.Animals.Add(kiwi); - - var usa = new Country { Id = 2, Name = "USA" }; - - usa.Animals.Add(eagle); - - context.Set().Add(kiwi); - context.Set().Add(eagle); - context.Set().Add(nz); - context.Set().Add(usa); - context.Set().Add(rose); - context.Set().Add(daisy); - - context.AddRange( - new Tea { HasMilk = true, CaffeineGrams = 1 }, - new Lilt { SugarGrams = 4, Carbonation = 7 }, - new Coke - { - SugarGrams = 6, - CaffeineGrams = 4, - Carbonation = 5 - }); - - context.SaveChanges(); - } - } -} diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Animal.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Animal.cs similarity index 87% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Animal.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Animal.cs index 9f791a3a5a0..6e4d58da7c1 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Animal.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Animal.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public abstract class Animal { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Bird.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Bird.cs similarity index 87% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Bird.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Bird.cs index dd894a26769..58bbebd6c02 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Bird.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Bird.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public abstract class Bird : Animal { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Coke.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Coke.cs similarity index 84% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Coke.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Coke.cs index 6497f2f5679..bc2edafbf8e 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Coke.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Coke.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Coke : Drink, ISugary { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Country.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Country.cs similarity index 88% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Country.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Country.cs index 02e995d44a7..f932758fd48 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Country.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Country.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Country { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Daisy.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Daisy.cs similarity index 76% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Daisy.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Daisy.cs index 51e6e1372b1..45642901c31 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Daisy.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Daisy.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Daisy : Flower { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Drink.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Drink.cs similarity index 78% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Drink.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Drink.cs index b37ed37985f..e8f696c3c4e 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Drink.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Drink.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Drink { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Eagle.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Eagle.cs similarity index 90% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Eagle.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Eagle.cs index b2ca17b8de7..64b1b06c6d7 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Eagle.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Eagle.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Eagle : Bird { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Flower.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Flower.cs similarity index 76% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Flower.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Flower.cs index 8559b50de20..f0212bcdbf9 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Flower.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Flower.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public abstract class Flower : Plant { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/ISugary.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/ISugary.cs similarity index 78% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/ISugary.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/ISugary.cs index 80233baf5f5..b08c54f764a 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/ISugary.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/ISugary.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public interface ISugary { diff --git a/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceContext.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceContext.cs new file mode 100644 index 00000000000..976bed4caa1 --- /dev/null +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceContext.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel +{ + public class InheritanceContext : PoolableDbContext + { + public InheritanceContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Animals { get; set; } + public DbSet AnimalQueries { get; set; } + public DbSet Countries { get; set; } + public DbSet Drinks { get; set; } + public DbSet Plants { get; set; } + + public static void Seed(InheritanceContext context) + { + var animals = InheritanceData.CreateAnimals(); + var countries = InheritanceData.CreateCountries(); + var drinks = InheritanceData.CreateDrinks(); + var plants = InheritanceData.CreatePlants(); + + InheritanceData.WireUp(animals, countries); + + context.Animals.AddRange(animals); + context.Countries.AddRange(countries); + context.Drinks.AddRange(drinks); + context.Plants.AddRange(plants); + + context.SaveChanges(); + } + } +} diff --git a/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceData.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceData.cs new file mode 100644 index 00000000000..253b891459b --- /dev/null +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/InheritanceData.cs @@ -0,0 +1,180 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore.TestUtilities; + +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel +{ + public class InheritanceData : ISetSource + { + public IReadOnlyList Animals { get; } + public IReadOnlyList AnimalQueries { get; } + public IReadOnlyList Countries { get; } + public IReadOnlyList Drinks { get; } + public IReadOnlyList Plants { get; } + + public InheritanceData() + { + Animals = CreateAnimals(); + Countries = CreateCountries(); + Drinks = CreateDrinks(); + Plants = CreatePlants(); + + WireUp(Animals, Countries); + + AnimalQueries = Animals.Select(a => a is Eagle + ? (AnimalQuery)new EagleQuery { + Name = a.Name, + CountryId = a.CountryId, + EagleId = ((Bird)a).EagleId, + IsFlightless = ((Bird)a).IsFlightless, + Group = ((Eagle)a).Group, + } + : new KiwiQuery + { + Name = a.Name, + CountryId = a.CountryId, + EagleId = ((Bird)a).EagleId, + IsFlightless = ((Bird)a).IsFlightless, + FoundOn = ((Kiwi)a).FoundOn, + }).ToList().AsReadOnly(); + } + + public virtual IQueryable Set() + where TEntity : class + { + if (typeof(TEntity) == typeof(Animal)) + { + return (IQueryable)Animals.AsQueryable(); + } + + if (typeof(TEntity) == typeof(AnimalQuery)) + { + return (IQueryable)AnimalQueries.AsQueryable(); + } + + if (typeof(TEntity) == typeof(Bird)) + { + return (IQueryable)Animals.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(BirdQuery)) + { + return (IQueryable)AnimalQueries.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Eagle)) + { + return (IQueryable)Animals.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(EagleQuery)) + { + return (IQueryable)AnimalQueries.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Kiwi)) + { + return (IQueryable)Animals.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(KiwiQuery)) + { + return (IQueryable)AnimalQueries.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Country)) + { + return (IQueryable)Countries.AsQueryable(); + } + + if (typeof(TEntity) == typeof(Drink)) + { + return (IQueryable)Drinks.AsQueryable(); + } + + if (typeof(TEntity) == typeof(Coke)) + { + return (IQueryable)Drinks.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Lilt)) + { + return (IQueryable)Drinks.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Tea)) + { + return (IQueryable)Drinks.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Plant)) + { + return (IQueryable)Plants.AsQueryable(); + } + + if (typeof(TEntity) == typeof(Flower)) + { + return (IQueryable)Plants.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Daisy)) + { + return (IQueryable)Plants.OfType().AsQueryable(); + } + + if (typeof(TEntity) == typeof(Rose)) + { + return (IQueryable)Plants.OfType().AsQueryable(); + } + + throw new InvalidOperationException("Invalid entity type: " + typeof(TEntity)); + } + + public static IReadOnlyList CreateAnimals() + => new List + { + new Kiwi { Species = "Apteryx haastii", Name = "Great spotted kiwi", IsFlightless = true, FoundOn = Island.South }, + new Eagle { Species = "Aquila chrysaetos canadensis", Name = "American golden eagle", Group = EagleGroup.Booted }, + }; + + public static IReadOnlyList CreateCountries() + => new List + { + new Country { Id = 1, Name = "New Zealand" }, + new Country { Id = 2, Name = "USA" }, + }; + + public static IReadOnlyList CreateDrinks() + => new List + { + new Tea { Id = 1, HasMilk = true, CaffeineGrams = 1 }, + new Lilt { Id = 2, SugarGrams = 4, Carbonation = 7 }, + new Coke { Id = 3, SugarGrams = 6, CaffeineGrams = 4, Carbonation = 5 }, + }; + + public static IReadOnlyList CreatePlants() + => new List + { + new Rose { Genus = PlantGenus.Rose, Species = "Rosa canina", Name = "Dog-rose", HasThorns = true }, + new Daisy { Genus = PlantGenus.Daisy, Species = "Bellis perennis", Name = "Common daisy" }, + }; + + public static void WireUp( + IReadOnlyList animals, + IReadOnlyList countries) + { + ((Eagle)animals[1]).Prey.Add((Bird)animals[0]); + ((Bird)animals[0]).EagleId = animals[1].Species; + + countries[0].Animals.Add(animals[0]); + animals[0].CountryId = countries[0].Id; + + countries[1].Animals.Add(animals[1]); + animals[1].CountryId = countries[1].Id; + } + } +} diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Kiwi.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Kiwi.cs similarity index 86% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Kiwi.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Kiwi.cs index db3b7fb5278..9783a02135a 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Kiwi.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Kiwi.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Kiwi : Bird { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Lilt.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Lilt.cs similarity index 82% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Lilt.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Lilt.cs index 820d2ff3c8c..4f7b2adeed3 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Lilt.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Lilt.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Lilt : Drink, ISugary { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Plant.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Plant.cs similarity index 83% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Plant.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Plant.cs index 3efd3827482..9a481d3dfac 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Plant.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Plant.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public abstract class Plant { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/PlantGenus.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/PlantGenus.cs similarity index 77% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/PlantGenus.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/PlantGenus.cs index 90976687552..e4b6d28cd96 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/PlantGenus.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/PlantGenus.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public enum PlantGenus { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Rose.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Rose.cs similarity index 79% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Rose.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Rose.cs index 6d67625baa8..d446beecc1c 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Rose.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Rose.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Rose : Flower { diff --git a/test/EFCore.Specification.Tests/TestModels/Inheritance/Tea.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Tea.cs similarity index 81% rename from test/EFCore.Specification.Tests/TestModels/Inheritance/Tea.cs rename to test/EFCore.Specification.Tests/TestModels/InheritanceModel/Tea.cs index bc629a4186e..c8a583bdb13 100644 --- a/test/EFCore.Specification.Tests/TestModels/Inheritance/Tea.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceModel/Tea.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.EntityFrameworkCore.TestModels.Inheritance +namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceModel { public class Tea : Drink { diff --git a/test/EFCore.Specification.Tests/TestModels/InheritanceRelationships/InheritanceRelationshipsContext.cs b/test/EFCore.Specification.Tests/TestModels/InheritanceRelationships/InheritanceRelationshipsContext.cs index 9317c5f5d2d..4c7e4a3010b 100644 --- a/test/EFCore.Specification.Tests/TestModels/InheritanceRelationships/InheritanceRelationshipsContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/InheritanceRelationships/InheritanceRelationshipsContext.cs @@ -8,8 +8,6 @@ namespace Microsoft.EntityFrameworkCore.TestModels.InheritanceRelationships { public class InheritanceRelationshipsContext : PoolableDbContext { - public static readonly string StoreName = "InheritanceRelationships"; - public InheritanceRelationshipsContext(DbContextOptions options) : base(options) { diff --git a/test/EFCore.Specification.Tests/TestModels/ManyToManyModel/ManyToManyContext.cs b/test/EFCore.Specification.Tests/TestModels/ManyToManyModel/ManyToManyContext.cs index 5f145a3cbcc..bc5bed53698 100644 --- a/test/EFCore.Specification.Tests/TestModels/ManyToManyModel/ManyToManyContext.cs +++ b/test/EFCore.Specification.Tests/TestModels/ManyToManyModel/ManyToManyContext.cs @@ -7,8 +7,6 @@ namespace Microsoft.EntityFrameworkCore.TestModels.ManyToManyModel { public class ManyToManyContext : PoolableDbContext { - public static readonly string StoreName = "ManyToMany"; - public ManyToManyContext(DbContextOptions options) : base(options) { diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/FiltersInheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/FiltersInheritanceQuerySqlServerTest.cs index 029646b9089..d911fe4d3aa 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/FiltersInheritanceQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/FiltersInheritanceQuerySqlServerTest.cs @@ -20,7 +20,7 @@ public override void Can_use_of_type_animal() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1 ORDER BY [a].[Species]"); } @@ -31,7 +31,7 @@ public override void Can_use_is_kiwi() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[CountryId] = 1) AND ([a].[Discriminator] = N'Kiwi')"); } @@ -41,7 +41,7 @@ public override void Can_use_is_kiwi_with_other_predicate() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[CountryId] = 1) AND (([a].[Discriminator] = N'Kiwi') AND ([a].[CountryId] = 1))"); } @@ -54,7 +54,7 @@ public override void Can_use_is_kiwi_in_projection() WHEN [a].[Discriminator] = N'Kiwi' THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1"); } @@ -64,7 +64,7 @@ public override void Can_use_of_type_bird() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1 ORDER BY [a].[Species]"); } @@ -75,7 +75,7 @@ public override void Can_use_of_type_bird_predicate() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[CountryId] = 1) AND ([a].[CountryId] = 1) ORDER BY [a].[Species]"); } @@ -86,7 +86,7 @@ public override void Can_use_of_type_bird_with_projection() AssertSql( @"SELECT [a].[EagleId] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1"); } @@ -96,7 +96,7 @@ public override void Can_use_of_type_bird_first() AssertSql( @"SELECT TOP(1) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1 ORDER BY [a].[Species]"); } @@ -107,7 +107,7 @@ public override void Can_use_of_type_kiwi() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[CountryId] = 1) AND ([a].[Discriminator] = N'Kiwi')"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/IncompleteMappingInheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/IncompleteMappingInheritanceQuerySqlServerTest.cs index 18277ce7837..7c6cc3ac73a 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/IncompleteMappingInheritanceQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/IncompleteMappingInheritanceQuerySqlServerTest.cs @@ -1,9 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Xunit; using Xunit.Abstractions; @@ -41,21 +42,21 @@ public virtual void Common_property_shares_column() Assert.Equal("HasMilk", teaType.FindProperty("HasMilk").GetColumnName()); } - public override void Can_query_when_shared_column() + public override async Task Can_query_when_shared_column(bool async) { - base.Can_query_when_shared_column(); + await base.Can_query_when_shared_column(async); AssertSql( @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Coke'", // @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[LiltCO2], [d].[SugarGrams] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Lilt'", // @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[HasMilk] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Tea'"); } @@ -66,7 +67,7 @@ public override void FromSql_on_root() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] FROM ( - select * from ""Animal"" + select * from ""Animals"" ) AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi')"); } @@ -78,286 +79,286 @@ public override void FromSql_on_derived() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group] FROM ( - select * from ""Animal"" + select * from ""Animals"" ) AS [a] WHERE [a].[Discriminator] = N'Eagle'"); } - public override void Can_query_all_types_when_shared_column() + public override async Task Can_query_all_types_when_shared_column(bool async) { - base.Can_query_all_types_when_shared_column(); + await base.Can_query_all_types_when_shared_column(async); AssertSql( @"SELECT [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] IN (N'Drink', N'Coke', N'Lilt', N'Tea')"); } - public override void Can_use_of_type_animal() + public override async Task Can_use_of_type_animal(bool async) { - base.Can_use_of_type_animal(); + await base.Can_use_of_type_animal(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_use_is_kiwi() + public override async Task Can_use_is_kiwi(bool async) { - base.Can_use_is_kiwi(); + await base.Can_use_is_kiwi(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi')"); } - public override void Can_use_is_kiwi_with_other_predicate() + public override async Task Can_use_is_kiwi_with_other_predicate(bool async) { - base.Can_use_is_kiwi_with_other_predicate(); + await base.Can_use_is_kiwi_with_other_predicate(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND (([a].[Discriminator] = N'Kiwi') AND ([a].[CountryId] = 1))"); } - public override void Can_use_is_kiwi_in_projection() + public override async Task Can_use_is_kiwi_in_projection(bool async) { - base.Can_use_is_kiwi_in_projection(); + await base.Can_use_is_kiwi_in_projection(async); AssertSql( @"SELECT CASE WHEN [a].[Discriminator] = N'Kiwi' THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi')"); } - public override void Can_use_of_type_bird() + public override async Task Can_use_of_type_bird(bool async) { - base.Can_use_of_type_bird(); + await base.Can_use_of_type_bird(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_use_of_type_bird_predicate() + public override async Task Can_use_of_type_bird_predicate(bool async) { - base.Can_use_of_type_bird_predicate(); + await base.Can_use_of_type_bird_predicate(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[CountryId] = 1)) AND [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_use_of_type_bird_with_projection() + public override async Task Can_use_of_type_bird_with_projection(bool async) { - base.Can_use_of_type_bird_with_projection(); + await base.Can_use_of_type_bird_with_projection(async); AssertSql( @"SELECT [a].[EagleId] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND [a].[Discriminator] IN (N'Eagle', N'Kiwi')"); } - public override void Can_use_of_type_bird_first() + public override async Task Can_use_of_type_bird_first(bool async) { - base.Can_use_of_type_bird_first(); + await base.Can_use_of_type_bird_first(async); AssertSql( @"SELECT TOP(1) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_use_of_type_kiwi() + public override async Task Can_use_of_type_kiwi(bool async) { - base.Can_use_of_type_kiwi(); + await base.Can_use_of_type_kiwi(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi')"); } - public override void Can_use_of_type_rose() + public override async Task Can_use_of_type_rose(bool async) { - base.Can_use_of_type_rose(); + await base.Can_use_of_type_rose(async); AssertSql( @"SELECT [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] WHERE [p].[Genus] IN (1, 0) AND ([p].[Genus] = 0)"); } - public override void Can_query_all_animals() + public override async Task Can_query_all_animals(bool async) { - base.Can_query_all_animals(); + await base.Can_query_all_animals(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_query_all_animal_views() + public override async Task Can_query_all_animal_views(bool async) { - base.Can_query_all_animal_views(); + await base.Can_query_all_animal_views(async); AssertSql( @"SELECT [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] FROM ( - SELECT * FROM Animal + SELECT * FROM Animals ) AS [a] ORDER BY [a].[CountryId]"); } - public override void Can_query_all_plants() + public override async Task Can_query_all_plants(bool async) { - base.Can_query_all_plants(); + await base.Can_query_all_plants(async); AssertSql( @"SELECT [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] WHERE [p].[Genus] IN (1, 0) ORDER BY [p].[Species]"); } - public override void Can_filter_all_animals() + public override async Task Can_filter_all_animals(bool async) { - base.Can_filter_all_animals(); + await base.Can_filter_all_animals(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Name] = N'Great spotted kiwi') ORDER BY [a].[Species]"); } - public override void Can_query_all_birds() + public override async Task Can_query_all_birds(bool async) { - base.Can_query_all_birds(); + await base.Can_query_all_birds(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') ORDER BY [a].[Species]"); } - public override void Can_query_just_kiwis() + public override async Task Can_query_just_kiwis(bool async) { - base.Can_query_just_kiwis(); + await base.Can_query_just_kiwis(async); AssertSql( @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Can_query_just_roses() + public override async Task Can_query_just_roses(bool async) { - base.Can_query_just_roses(); + await base.Can_query_just_roses(async); AssertSql( @"SELECT TOP(2) [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] WHERE [p].[Genus] = 0" ); } - public override void Can_include_prey() + public override async Task Can_include_prey(bool async) { - base.Can_include_prey(); + await base.Can_include_prey(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t0].[Species], [t0].[CountryId], [t0].[Discriminator], [t0].[Name], [t0].[EagleId], [t0].[IsFlightless], [t0].[Group], [t0].[FoundOn] FROM ( SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Eagle' ) AS [t] LEFT JOIN ( SELECT [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn] - FROM [Animal] AS [a0] + FROM [Animals] AS [a0] WHERE [a0].[Discriminator] IN (N'Eagle', N'Kiwi') ) AS [t0] ON [t].[Species] = [t0].[EagleId] ORDER BY [t].[Species], [t0].[Species]"); } - public override void Can_include_animals() + public override async Task Can_include_animals(bool async) { - base.Can_include_animals(); + await base.Can_include_animals(async); AssertSql( @"SELECT [c].[Id], [c].[Name], [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn] -FROM [Country] AS [c] +FROM [Countries] AS [c] LEFT JOIN ( SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') ) AS [t] ON [c].[Id] = [t].[CountryId] ORDER BY [c].[Name], [c].[Id], [t].[Species]"); } - public override void Can_use_of_type_kiwi_where_north_on_derived_property() + public override async Task Can_use_of_type_kiwi_where_north_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_north_on_derived_property(); + await base.Can_use_of_type_kiwi_where_north_on_derived_property(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi')) AND ([a].[FoundOn] = CAST(0 AS tinyint))"); } - public override void Can_use_of_type_kiwi_where_south_on_derived_property() + public override async Task Can_use_of_type_kiwi_where_south_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_south_on_derived_property(); + await base.Can_use_of_type_kiwi_where_south_on_derived_property(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi')) AND ([a].[FoundOn] = CAST(1 AS tinyint))"); } - public override void Discriminator_used_when_projection_over_derived_type() + public override async Task Discriminator_used_when_projection_over_derived_type(bool async) { - base.Discriminator_used_when_projection_over_derived_type(); + await base.Discriminator_used_when_projection_over_derived_type(async); AssertSql( @"SELECT [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Discriminator_used_when_projection_over_derived_type2() + public override async Task Discriminator_used_when_projection_over_derived_type2(bool async) { - base.Discriminator_used_when_projection_over_derived_type2(); + await base.Discriminator_used_when_projection_over_derived_type2(async); AssertSql( @"SELECT [a].[IsFlightless], [a].[Discriminator] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi')"); } - public override void Discriminator_used_when_projection_over_of_type() + public override async Task Discriminator_used_when_projection_over_of_type(bool async) { - base.Discriminator_used_when_projection_over_of_type(); + await base.Discriminator_used_when_projection_over_of_type(async); AssertSql( @"SELECT [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi')"); } @@ -367,7 +368,7 @@ public override void Can_insert_update_delete() AssertSql( @"SELECT TOP(2) [c].[Id], [c].[Name] -FROM [Country] AS [c] +FROM [Countries] AS [c] WHERE [c].[Id] = 1", // @"@p0='Apteryx owenii' (Nullable = false) (Size = 100) @@ -379,96 +380,96 @@ FROM [Country] AS [c] @p6='0' (Size = 1) SET NOCOUNT ON; -INSERT INTO [Animal] ([Species], [CountryId], [Discriminator], [Name], [EagleId], [IsFlightless], [FoundOn]) +INSERT INTO [Animals] ([Species], [CountryId], [Discriminator], [Name], [EagleId], [IsFlightless], [FoundOn]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6);", // @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')", // @"@p1='Apteryx owenii' (Nullable = false) (Size = 100) @p0='Aquila chrysaetos canadensis' (Size = 100) SET NOCOUNT ON; -UPDATE [Animal] SET [EagleId] = @p0 +UPDATE [Animals] SET [EagleId] = @p0 WHERE [Species] = @p1; SELECT @@ROWCOUNT;", // @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')", // @"@p0='Apteryx owenii' (Nullable = false) (Size = 100) SET NOCOUNT ON; -DELETE FROM [Animal] +DELETE FROM [Animals] WHERE [Species] = @p0; SELECT @@ROWCOUNT;", // @"SELECT COUNT(*) -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')"); } - public override void Byte_enum_value_constant_used_in_projection() + public override async Task Byte_enum_value_constant_used_in_projection(bool async) { - base.Byte_enum_value_constant_used_in_projection(); + await base.Byte_enum_value_constant_used_in_projection(async); AssertSql( @"SELECT CASE WHEN [a].[IsFlightless] = CAST(1 AS bit) THEN CAST(0 AS tinyint) ELSE CAST(1 AS tinyint) END -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Union_siblings_with_duplicate_property_in_subquery() + public override async Task Union_siblings_with_duplicate_property_in_subquery(bool async) { - base.Union_siblings_with_duplicate_property_in_subquery(); + await base.Union_siblings_with_duplicate_property_in_subquery(async); AssertSql( @"SELECT [t].[Id], [t].[Discriminator], [t].[CaffeineGrams], [t].[CokeCO2], [t].[SugarGrams], [t].[Carbonation], [t].[SugarGrams0], [t].[CaffeineGrams0], [t].[HasMilk] FROM ( SELECT [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams], NULL AS [CaffeineGrams0], NULL AS [HasMilk], NULL AS [Carbonation], NULL AS [SugarGrams0] - FROM [Drink] AS [d] + FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Coke' UNION SELECT [d0].[Id], [d0].[Discriminator], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [SugarGrams], [d0].[CaffeineGrams] AS [CaffeineGrams0], [d0].[HasMilk], NULL AS [Carbonation], NULL AS [SugarGrams0] - FROM [Drink] AS [d0] + FROM [Drinks] AS [d0] WHERE [d0].[Discriminator] = N'Tea' ) AS [t] WHERE [t].[Id] > 0"); } - public override void OfType_Union_subquery() + public override async Task OfType_Union_subquery(bool async) { - base.OfType_Union_subquery(); + await base.OfType_Union_subquery(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[FoundOn] FROM ( SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi') UNION SELECT [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[FoundOn] - FROM [Animal] AS [a0] + FROM [Animals] AS [a0] WHERE [a0].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a0].[Discriminator] = N'Kiwi') ) AS [t] WHERE ([t].[FoundOn] = CAST(0 AS tinyint)) AND [t].[FoundOn] IS NOT NULL"); } - public override void OfType_Union_OfType() + public override async Task OfType_Union_OfType(bool async) { - base.OfType_Union_OfType(); + await base.OfType_Union_OfType(async); AssertSql(" "); } - public override void Subquery_OfType() + public override async Task Subquery_OfType(bool async) { - base.Subquery_OfType(); + await base.Subquery_OfType(async); AssertSql( @"@__p_0='5' @@ -476,25 +477,25 @@ public override void Subquery_OfType() SELECT DISTINCT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[FoundOn] FROM ( SELECT TOP(@__p_0) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') ) AS [t] WHERE [t].[Discriminator] = N'Kiwi'"); } - public override void Union_entity_equality() + public override async Task Union_entity_equality(bool async) { - base.Union_entity_equality(); + await base.Union_entity_equality(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn] FROM ( SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn], NULL AS [Group] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi' UNION SELECT [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], NULL AS [FoundOn], [a0].[Group] - FROM [Animal] AS [a0] + FROM [Animals] AS [a0] WHERE [a0].[Discriminator] = N'Eagle' ) AS [t] WHERE 0 = 1"); @@ -506,7 +507,7 @@ public override void Member_access_on_intermediate_type_works() AssertSql( @"SELECT [a].[Name] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi' ORDER BY [a].[Name]"); } @@ -517,9 +518,9 @@ public override void Casting_to_base_type_joining_with_query_type_works() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] INNER JOIN ( - Select * from ""Animal"" + Select * from ""Animals"" ) AS [a0] ON [a].[Name] = [a0].[Name] WHERE [a].[Discriminator] = N'Eagle'"); } diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceQuerySqlServerTest.cs index 4b4a38d18df..aea867ae87d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/InheritanceQuerySqlServerTest.cs @@ -1,9 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading.Tasks; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; -using Microsoft.EntityFrameworkCore.TestModels.Inheritance; +using Microsoft.EntityFrameworkCore.TestModels.InheritanceModel; using Xunit; using Xunit.Abstractions; @@ -40,21 +41,21 @@ public virtual void Common_property_shares_column() Assert.Equal("HasMilk", teaType.FindProperty("HasMilk").GetColumnName()); } - public override void Can_query_when_shared_column() + public override async Task Can_query_when_shared_column(bool async) { - base.Can_query_when_shared_column(); + await base.Can_query_when_shared_column(async); AssertSql( @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Coke'", // @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[LiltCO2], [d].[SugarGrams] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Lilt'", // @"SELECT TOP(2) [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[HasMilk] -FROM [Drink] AS [d] +FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Tea'"); } @@ -63,7 +64,7 @@ public override void FromSql_on_root() base.FromSql_on_root(); AssertSql( - @"select * from ""Animal"""); + @"select * from ""Animals"""); } public override void FromSql_on_derived() @@ -73,268 +74,268 @@ public override void FromSql_on_derived() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group] FROM ( - select * from ""Animal"" + select * from ""Animals"" ) AS [a] WHERE [a].[Discriminator] = N'Eagle'"); } - public override void Can_query_all_types_when_shared_column() + public override async Task Can_query_all_types_when_shared_column(bool async) { - base.Can_query_all_types_when_shared_column(); + await base.Can_query_all_types_when_shared_column(async); AssertSql( @"SELECT [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams], [d].[LiltCO2], [d].[HasMilk] -FROM [Drink] AS [d]"); +FROM [Drinks] AS [d]"); } - public override void Can_use_of_type_animal() + public override async Task Can_use_of_type_animal(bool async) { - base.Can_use_of_type_animal(); + await base.Can_use_of_type_animal(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] ORDER BY [a].[Species]"); } - public override void Can_use_is_kiwi() + public override async Task Can_use_is_kiwi(bool async) { - base.Can_use_is_kiwi(); + await base.Can_use_is_kiwi(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Can_use_is_kiwi_with_other_predicate() + public override async Task Can_use_is_kiwi_with_other_predicate(bool async) { - base.Can_use_is_kiwi_with_other_predicate(); + await base.Can_use_is_kiwi_with_other_predicate(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[CountryId] = 1)"); } - public override void Can_use_is_kiwi_in_projection() + public override async Task Can_use_is_kiwi_in_projection(bool async) { - base.Can_use_is_kiwi_in_projection(); + await base.Can_use_is_kiwi_in_projection(async); AssertSql( @"SELECT CASE WHEN [a].[Discriminator] = N'Kiwi' THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END -FROM [Animal] AS [a]"); +FROM [Animals] AS [a]"); } - public override void Can_use_of_type_bird() + public override async Task Can_use_of_type_bird(bool async) { - base.Can_use_of_type_bird(); + await base.Can_use_of_type_bird(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] ORDER BY [a].[Species]"); } - public override void Can_use_of_type_bird_predicate() + public override async Task Can_use_of_type_bird_predicate(bool async) { - base.Can_use_of_type_bird_predicate(); + await base.Can_use_of_type_bird_predicate(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[CountryId] = 1 ORDER BY [a].[Species]"); } - public override void Can_use_of_type_bird_with_projection() + public override async Task Can_use_of_type_bird_with_projection(bool async) { - base.Can_use_of_type_bird_with_projection(); + await base.Can_use_of_type_bird_with_projection(async); AssertSql( @"SELECT [a].[EagleId] -FROM [Animal] AS [a]"); +FROM [Animals] AS [a]"); } - public override void Can_use_of_type_bird_first() + public override async Task Can_use_of_type_bird_first(bool async) { - base.Can_use_of_type_bird_first(); + await base.Can_use_of_type_bird_first(async); AssertSql( @"SELECT TOP(1) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] ORDER BY [a].[Species]"); } - public override void Can_use_of_type_kiwi() + public override async Task Can_use_of_type_kiwi(bool async) { - base.Can_use_of_type_kiwi(); + await base.Can_use_of_type_kiwi(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Can_use_of_type_rose() + public override async Task Can_use_of_type_rose(bool async) { - base.Can_use_of_type_rose(); + await base.Can_use_of_type_rose(async); AssertSql( @"SELECT [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] WHERE [p].[Genus] = 0"); } - public override void Can_query_all_animals() + public override async Task Can_query_all_animals(bool async) { - base.Can_query_all_animals(); + await base.Can_query_all_animals(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] ORDER BY [a].[Species]"); } - public override void Can_query_all_animal_views() + public override async Task Can_query_all_animal_views(bool async) { - base.Can_query_all_animal_views(); + await base.Can_query_all_animal_views(async); AssertSql( @"SELECT [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] FROM ( - SELECT * FROM Animal + SELECT * FROM Animals ) AS [a] ORDER BY [a].[CountryId]"); } - public override void Can_query_all_plants() + public override async Task Can_query_all_plants(bool async) { - base.Can_query_all_plants(); + await base.Can_query_all_plants(async); AssertSql( @"SELECT [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] ORDER BY [p].[Species]"); } - public override void Can_filter_all_animals() + public override async Task Can_filter_all_animals(bool async) { - base.Can_filter_all_animals(); + await base.Can_filter_all_animals(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Name] = N'Great spotted kiwi' ORDER BY [a].[Species]"); } - public override void Can_query_all_birds() + public override async Task Can_query_all_birds(bool async) { - base.Can_query_all_birds(); + await base.Can_query_all_birds(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] ORDER BY [a].[Species]"); } - public override void Can_query_just_kiwis() + public override async Task Can_query_just_kiwis(bool async) { - base.Can_query_just_kiwis(); + await base.Can_query_just_kiwis(async); AssertSql( @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Can_query_just_roses() + public override async Task Can_query_just_roses(bool async) { - base.Can_query_just_roses(); + await base.Can_query_just_roses(async); AssertSql( @"SELECT TOP(2) [p].[Species], [p].[CountryId], [p].[Genus], [p].[Name], [p].[HasThorns] -FROM [Plant] AS [p] +FROM [Plants] AS [p] WHERE [p].[Genus] = 0" ); } - public override void Can_include_prey() + public override async Task Can_include_prey(bool async) { - base.Can_include_prey(); + await base.Can_include_prey(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn] FROM ( SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Eagle' ) AS [t] -LEFT JOIN [Animal] AS [a0] ON [t].[Species] = [a0].[EagleId] +LEFT JOIN [Animals] AS [a0] ON [t].[Species] = [a0].[EagleId] ORDER BY [t].[Species], [a0].[Species]"); } - public override void Can_include_animals() + public override async Task Can_include_animals(bool async) { - base.Can_include_animals(); + await base.Can_include_animals(async); AssertSql( @"SELECT [c].[Id], [c].[Name], [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] -FROM [Country] AS [c] -LEFT JOIN [Animal] AS [a] ON [c].[Id] = [a].[CountryId] +FROM [Countries] AS [c] +LEFT JOIN [Animals] AS [a] ON [c].[Id] = [a].[CountryId] ORDER BY [c].[Name], [c].[Id], [a].[Species]"); } - public override void Can_use_of_type_kiwi_where_north_on_derived_property() + public override async Task Can_use_of_type_kiwi_where_north_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_north_on_derived_property(); + await base.Can_use_of_type_kiwi_where_north_on_derived_property(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[FoundOn] = CAST(0 AS tinyint))"); } - public override void Can_use_of_type_kiwi_where_south_on_derived_property() + public override async Task Can_use_of_type_kiwi_where_south_on_derived_property(bool async) { - base.Can_use_of_type_kiwi_where_south_on_derived_property(); + await base.Can_use_of_type_kiwi_where_south_on_derived_property(async); AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[FoundOn] = CAST(1 AS tinyint))"); } - public override void Discriminator_used_when_projection_over_derived_type() + public override async Task Discriminator_used_when_projection_over_derived_type(bool async) { - base.Discriminator_used_when_projection_over_derived_type(); + await base.Discriminator_used_when_projection_over_derived_type(async); AssertSql( @"SELECT [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Discriminator_used_when_projection_over_derived_type2() + public override async Task Discriminator_used_when_projection_over_derived_type2(bool async) { - base.Discriminator_used_when_projection_over_derived_type2(); + await base.Discriminator_used_when_projection_over_derived_type2(async); AssertSql( @"SELECT [a].[IsFlightless], [a].[Discriminator] -FROM [Animal] AS [a]"); +FROM [Animals] AS [a]"); } - public override void Discriminator_used_when_projection_over_of_type() + public override async Task Discriminator_used_when_projection_over_of_type(bool async) { - base.Discriminator_used_when_projection_over_of_type(); + await base.Discriminator_used_when_projection_over_of_type(async); AssertSql( @"SELECT [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } @@ -344,7 +345,7 @@ public override void Can_insert_update_delete() AssertSql( @"SELECT TOP(2) [c].[Id], [c].[Name] -FROM [Country] AS [c] +FROM [Countries] AS [c] WHERE [c].[Id] = 1", // @"@p0='Apteryx owenii' (Nullable = false) (Size = 100) @@ -356,96 +357,96 @@ FROM [Country] AS [c] @p6='0' (Size = 1) SET NOCOUNT ON; -INSERT INTO [Animal] ([Species], [CountryId], [Discriminator], [Name], [EagleId], [IsFlightless], [FoundOn]) +INSERT INTO [Animals] ([Species], [CountryId], [Discriminator], [Name], [EagleId], [IsFlightless], [FoundOn]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6);", // @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')", // @"@p1='Apteryx owenii' (Nullable = false) (Size = 100) @p0='Aquila chrysaetos canadensis' (Size = 100) SET NOCOUNT ON; -UPDATE [Animal] SET [EagleId] = @p0 +UPDATE [Animals] SET [EagleId] = @p0 WHERE [Species] = @p1; SELECT @@ROWCOUNT;", // @"SELECT TOP(2) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')", // @"@p0='Apteryx owenii' (Nullable = false) (Size = 100) SET NOCOUNT ON; -DELETE FROM [Animal] +DELETE FROM [Animals] WHERE [Species] = @p0; SELECT @@ROWCOUNT;", // @"SELECT COUNT(*) -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE ([a].[Discriminator] = N'Kiwi') AND ([a].[Species] LIKE N'%owenii')"); } - public override void Byte_enum_value_constant_used_in_projection() + public override async Task Byte_enum_value_constant_used_in_projection(bool async) { - base.Byte_enum_value_constant_used_in_projection(); + await base.Byte_enum_value_constant_used_in_projection(async); AssertSql( @"SELECT CASE WHEN [a].[IsFlightless] = CAST(1 AS bit) THEN CAST(0 AS tinyint) ELSE CAST(1 AS tinyint) END -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi'"); } - public override void Union_siblings_with_duplicate_property_in_subquery() + public override async Task Union_siblings_with_duplicate_property_in_subquery(bool async) { - base.Union_siblings_with_duplicate_property_in_subquery(); + await base.Union_siblings_with_duplicate_property_in_subquery(async); AssertSql( @"SELECT [t].[Id], [t].[Discriminator], [t].[CaffeineGrams], [t].[CokeCO2], [t].[SugarGrams], [t].[Carbonation], [t].[SugarGrams0], [t].[CaffeineGrams0], [t].[HasMilk] FROM ( SELECT [d].[Id], [d].[Discriminator], [d].[CaffeineGrams], [d].[CokeCO2], [d].[SugarGrams], NULL AS [CaffeineGrams0], NULL AS [HasMilk], NULL AS [Carbonation], NULL AS [SugarGrams0] - FROM [Drink] AS [d] + FROM [Drinks] AS [d] WHERE [d].[Discriminator] = N'Coke' UNION SELECT [d0].[Id], [d0].[Discriminator], NULL AS [CaffeineGrams], NULL AS [CokeCO2], NULL AS [SugarGrams], [d0].[CaffeineGrams] AS [CaffeineGrams0], [d0].[HasMilk], NULL AS [Carbonation], NULL AS [SugarGrams0] - FROM [Drink] AS [d0] + FROM [Drinks] AS [d0] WHERE [d0].[Discriminator] = N'Tea' ) AS [t] WHERE [t].[Id] > 0"); } - public override void OfType_Union_subquery() + public override async Task OfType_Union_subquery(bool async) { - base.OfType_Union_subquery(); + await base.OfType_Union_subquery(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[FoundOn] FROM ( SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a].[Discriminator] = N'Kiwi') UNION SELECT [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[FoundOn] - FROM [Animal] AS [a0] + FROM [Animals] AS [a0] WHERE [a0].[Discriminator] IN (N'Eagle', N'Kiwi') AND ([a0].[Discriminator] = N'Kiwi') ) AS [t] WHERE ([t].[FoundOn] = CAST(0 AS tinyint)) AND [t].[FoundOn] IS NOT NULL"); } - public override void OfType_Union_OfType() + public override async Task OfType_Union_OfType(bool async) { - base.OfType_Union_OfType(); + await base.OfType_Union_OfType(async); AssertSql(" "); } - public override void Subquery_OfType() + public override async Task Subquery_OfType(bool async) { - base.Subquery_OfType(); + await base.Subquery_OfType(async); AssertSql( @"@__p_0='5' @@ -453,24 +454,24 @@ public override void Subquery_OfType() SELECT DISTINCT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[FoundOn] FROM ( SELECT TOP(@__p_0) [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a].[FoundOn] - FROM [Animal] AS [a] + FROM [Animals] AS [a] ) AS [t] WHERE [t].[Discriminator] = N'Kiwi'"); } - public override void Union_entity_equality() + public override async Task Union_entity_equality(bool async) { - base.Union_entity_equality(); + await base.Union_entity_equality(async); AssertSql( @"SELECT [t].[Species], [t].[CountryId], [t].[Discriminator], [t].[Name], [t].[EagleId], [t].[IsFlightless], [t].[Group], [t].[FoundOn] FROM ( SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[FoundOn], NULL AS [Group] - FROM [Animal] AS [a] + FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi' UNION SELECT [a0].[Species], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], NULL AS [FoundOn], [a0].[Group] - FROM [Animal] AS [a0] + FROM [Animals] AS [a0] WHERE [a0].[Discriminator] = N'Eagle' ) AS [t] WHERE 0 = 1"); @@ -482,7 +483,7 @@ public override void Member_access_on_intermediate_type_works() AssertSql( @"SELECT [a].[Name] -FROM [Animal] AS [a] +FROM [Animals] AS [a] WHERE [a].[Discriminator] = N'Kiwi' ORDER BY [a].[Name]"); } @@ -493,9 +494,9 @@ public override void Casting_to_base_type_joining_with_query_type_works() AssertSql( @"SELECT [a].[Species], [a].[CountryId], [a].[Discriminator], [a].[Name], [a].[EagleId], [a].[IsFlightless], [a].[Group], [a0].[CountryId], [a0].[Discriminator], [a0].[Name], [a0].[EagleId], [a0].[IsFlightless], [a0].[Group], [a0].[FoundOn] -FROM [Animal] AS [a] +FROM [Animals] AS [a] INNER JOIN ( - Select * from ""Animal"" + Select * from ""Animals"" ) AS [a0] ON [a].[Name] = [a0].[Name] WHERE [a].[Discriminator] = N'Eagle'"); }