Skip to content

Commit

Permalink
Add test for member access over conditional
Browse files Browse the repository at this point in the history
i.e. for issue dotnet#34589
  • Loading branch information
ranma42 committed Dec 28, 2024
1 parent 85c1c35 commit 5effb26
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,16 @@ from t2 in ss.Set<CogTag>()
AssertEqual(e.t2, e.t2);
});

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Conditional_Navigation_With_Member_Access(bool async)
=> AssertQuery(
async,
ss => ss.Set<Gear>()
.Where(g => (g.AssignedCity != null ? g.AssignedCity : g.CityOfBirth).Name != "Ephyra")
.Select(g => new { g.Nickname }),
elementSorter: e => e.Nickname);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Singleton_Navigation_With_Member_Access(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,23 @@ CROSS JOIN [Tags] AS [t0]
""");
}

public override async Task Conditional_Navigation_With_Member_Access(bool async)
{
await base.Conditional_Navigation_With_Member_Access(async);

AssertSql(
"""
SELECT [g].[Nickname]
FROM [Gears] AS [g]
LEFT JOIN [Cities] AS [c] ON [g].[AssignedCityName] = [c].[Name]
INNER JOIN [Cities] AS [c0] ON [g].[CityOfBirthName] = [c0].[Name]
WHERE CASE
WHEN [c].[Name] IS NOT NULL THEN [c].[Name]
ELSE [c0].[Name]
END <> N'Ephyra'
""");
}

public override async Task Select_Singleton_Navigation_With_Member_Access(bool async)
{
await base.Select_Singleton_Navigation_With_Member_Access(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,29 @@ FROM [Officers] AS [o0]
""");
}

public override async Task Conditional_Navigation_With_Member_Access(bool async)
{
await base.Conditional_Navigation_With_Member_Access(async);

AssertSql(
"""
SELECT [u].[Nickname]
FROM (
SELECT [g].[Nickname], [g].[AssignedCityName], [g].[CityOfBirthName]
FROM [Gears] AS [g]
UNION ALL
SELECT [o].[Nickname], [o].[AssignedCityName], [o].[CityOfBirthName]
FROM [Officers] AS [o]
) AS [u]
LEFT JOIN [Cities] AS [c] ON [u].[AssignedCityName] = [c].[Name]
INNER JOIN [Cities] AS [c0] ON [u].[CityOfBirthName] = [c0].[Name]
WHERE CASE
WHEN [c].[Name] IS NOT NULL THEN [c].[Name]
ELSE [c0].[Name]
END <> N'Ephyra'
""");
}

public override async Task Select_Singleton_Navigation_With_Member_Access(bool async)
{
await base.Select_Singleton_Navigation_With_Member_Access(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,23 @@ FROM [Gears] AS [g0]
""");
}

public override async Task Conditional_Navigation_With_Member_Access(bool async)
{
await base.Conditional_Navigation_With_Member_Access(async);

AssertSql(
"""
SELECT [g].[Nickname]
FROM [Gears] AS [g]
LEFT JOIN [Cities] AS [c] ON [g].[AssignedCityName] = [c].[Name]
INNER JOIN [Cities] AS [c0] ON [g].[CityOfBirthName] = [c0].[Name]
WHERE CASE
WHEN [c].[Name] IS NOT NULL THEN [c].[Name]
ELSE [c0].[Name]
END <> N'Ephyra'
""");
}

public override async Task Select_Singleton_Navigation_With_Member_Access(bool async)
{
await base.Select_Singleton_Navigation_With_Member_Access(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,23 @@ LEFT JOIN (
""");
}

public override async Task Conditional_Navigation_With_Member_Access(bool async)
{
await base.Conditional_Navigation_With_Member_Access(async);

AssertSql(
"""
SELECT [g].[Nickname]
FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g]
LEFT JOIN [Cities] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [c] ON [g].[AssignedCityName] = [c].[Name]
INNER JOIN [Cities] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [c0] ON [g].[CityOfBirthName] = [c0].[Name]
WHERE CASE
WHEN [c].[Name] IS NOT NULL THEN [c].[Name]
ELSE [c0].[Name]
END <> N'Ephyra'
""");
}

public override async Task Select_Singleton_Navigation_With_Member_Access(bool async)
{
await base.Select_Singleton_Navigation_With_Member_Access(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7859,6 +7859,23 @@ CROSS JOIN "Tags" AS "t0"
""");
}

public override async Task Conditional_Navigation_With_Member_Access(bool async)
{
await base.Conditional_Navigation_With_Member_Access(async);

AssertSql(
"""
SELECT "g"."Nickname"
FROM "Gears" AS "g"
LEFT JOIN "Cities" AS "c" ON "g"."AssignedCityName" = "c"."Name"
INNER JOIN "Cities" AS "c0" ON "g"."CityOfBirthName" = "c0"."Name"
WHERE CASE
WHEN "c"."Name" IS NOT NULL THEN "c"."Name"
ELSE "c0"."Name"
END <> 'Ephyra'
""");
}

public override async Task Complex_GroupBy_after_set_operator_using_result_selector(bool async)
{
await base.Complex_GroupBy_after_set_operator_using_result_selector(async);
Expand Down

0 comments on commit 5effb26

Please sign in to comment.