Skip to content

Commit

Permalink
Adding tests for #15832 - Non-constant property name in EF.Property (…
Browse files Browse the repository at this point in the history
…and indexer property)

Resolves #15832
  • Loading branch information
maumar committed May 6, 2021
1 parent 47d09eb commit 78435ee
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions test/EFCore.Cosmos.FunctionalTests/Query/OwnedQueryCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2487,5 +2487,17 @@ public virtual Task Filter_with_property_compared_to_null_wrapped_in_explicit_co
ss => ss.Set<Customer>().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<Customer>().Where(c => EF.Property<string>(c, id) == "ALFKI"),
entryCount: 1);
}
}
}
11 changes: 11 additions & 0 deletions test/EFCore.Specification.Tests/Query/OwnedQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedPerson>().Where(p => (int)p.PersonAddress[zipCode] == 38654));
}

protected virtual DbContext CreateContext()
=> Fixture.CreateContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 78435ee

Please sign in to comment.