From 78435ee1aa6f3cec09838f0e89f018dc5fe674be Mon Sep 17 00:00:00 2001 From: maumar Date: Wed, 5 May 2021 16:05:37 -0700 Subject: [PATCH] Adding tests for #15832 - Non-constant property name in EF.Property (and indexer property) Resolves #15832 --- .../Query/NorthwindWhereQueryCosmosTest.cs | 10 ++++++++++ .../Query/OwnedQueryCosmosTest.cs | 10 ++++++++++ .../Query/NorthwindWhereQueryTestBase.cs | 12 ++++++++++++ .../Query/OwnedQueryTestBase.cs | 11 +++++++++++ .../Query/NorthwindWhereQuerySqlServerTest.cs | 10 ++++++++++ .../Query/OwnedQuerySqlServerTest.cs | 16 ++++++++++++++++ 6 files changed, 69 insertions(+) diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs index 4a118d3ad3e..fcd15e0cf10 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindWhereQueryCosmosTest.cs @@ -2178,6 +2178,16 @@ public override Task Where_equals_method_string_with_ignore_case(bool async) return AssertTranslationFailed(() => base.Where_equals_method_string_with_ignore_case(async)); } + public override async Task Filter_with_EF_Property_using_closure_for_property_name(bool async) + { + await base.Filter_with_EF_Property_using_closure_for_property_name(async); + + AssertSql( + @"SELECT c +FROM root c +WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""CustomerID""] = 'ALFKI'))"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs index 3a5e0e66bcf..f4b82e29ecf 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs @@ -490,6 +490,16 @@ public override async Task Projecting_collection_correlated_with_keyless_entity_ AssertSql(" "); } + public override async Task Filter_on_indexer_using_closure(bool async) + { + await base.Filter_on_indexer_using_closure(async); + + AssertSql( + @"SELECT c +FROM root c +WHERE (c[""Discriminator""] IN (""OwnedPerson"", ""Branch"", ""LeafB"", ""LeafA"") AND (c["PersonAddress"]["ZipCode"] = 38654))"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs index b5c030dd50b..29024501c36 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs @@ -2487,5 +2487,17 @@ public virtual Task Filter_with_property_compared_to_null_wrapped_in_explicit_co ss => ss.Set().Where(c => (object)c.Region == null), entryCount: 60); } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Filter_with_EF_Property_using_closure_for_property_name(bool async) + { + var id = "CustomerID"; + + return AssertQuery( + async, + ss => ss.Set().Where(c => EF.Property(c, id) == "ALFKI"), + entryCount: 1); + } } } diff --git a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs index e17d8ba3702..f3fb12b8769 100644 --- a/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs @@ -882,6 +882,17 @@ public virtual Task Projecting_collection_correlated_with_keyless_entity_after_n }); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task Filter_on_indexer_using_closure(bool async) + { + var zipCode = "ZipCode"; + + return AssertQuery( + async, + ss => ss.Set().Where(p => (int)p.PersonAddress[zipCode] == 38654)); + } + protected virtual DbContext CreateContext() => Fixture.CreateContext(); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs index 9f0981c4d23..adf6ec3d111 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/NorthwindWhereQuerySqlServerTest.cs @@ -2248,6 +2248,16 @@ FROM [Customers] AS [c] WHERE ([c].[Region] <> N'WA') AND [c].[Region] IS NOT NULL"); } + public override async Task Filter_with_EF_Property_using_closure_for_property_name(bool async) + { + await base.Filter_with_EF_Property_using_closure_for_property_name(async); + + AssertSql( + @"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] +FROM [Customers] AS [c] +WHERE [c].[CustomerID] = N'ALFKI'"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs index 291a4db7ac2..5f68d79b59d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/OwnedQuerySqlServerTest.cs @@ -1165,6 +1165,22 @@ LEFT JOIN [Planet] AS [p] ON ([b].[Throned_Value] <> [p].[Id]) OR [b].[Throned_V ORDER BY [f].[Id], [b].[Id], [p].[Id]"); } + public override async Task Filter_on_indexer_using_closure(bool async) + { + await base.Filter_on_indexer_using_closure(async); + + AssertSql( + @"SELECT [o].[Id], [o].[Discriminator], [o].[Name], [t].[ClientId], [t].[Id], [t].[OrderDate], [t].[OrderClientId], [t].[OrderId], [t].[Id0], [t].[Detail], [o].[PersonAddress_AddressLine], [o].[PersonAddress_PlaceType], [o].[PersonAddress_ZipCode], [o].[PersonAddress_Country_Name], [o].[PersonAddress_Country_PlanetId], [o].[BranchAddress_BranchName], [o].[BranchAddress_PlaceType], [o].[BranchAddress_Country_Name], [o].[BranchAddress_Country_PlanetId], [o].[LeafBAddress_LeafBType], [o].[LeafBAddress_PlaceType], [o].[LeafBAddress_Country_Name], [o].[LeafBAddress_Country_PlanetId], [o].[LeafAAddress_LeafType], [o].[LeafAAddress_PlaceType], [o].[LeafAAddress_Country_Name], [o].[LeafAAddress_Country_PlanetId] +FROM [OwnedPerson] AS [o] +LEFT JOIN ( + SELECT [o0].[ClientId], [o0].[Id], [o0].[OrderDate], [o1].[OrderClientId], [o1].[OrderId], [o1].[Id] AS [Id0], [o1].[Detail] + FROM [Order] AS [o0] + LEFT JOIN [OrderDetail] AS [o1] ON ([o0].[ClientId] = [o1].[OrderClientId]) AND ([o0].[Id] = [o1].[OrderId]) +) AS [t] ON [o].[Id] = [t].[ClientId] +WHERE [o].[PersonAddress_ZipCode] = 38654 +ORDER BY [o].[Id], [t].[ClientId], [t].[Id], [t].[OrderClientId], [t].[OrderId], [t].[Id0]"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);