Skip to content

Commit

Permalink
Add regression test for issue#15340
Browse files Browse the repository at this point in the history
Resolves #15340
  • Loading branch information
smitpatel committed Sep 21, 2019
1 parent 91a1926 commit d3bdb77
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7677,6 +7677,25 @@ public virtual Task Nullable_bool_comparison_is_translated_to_server(bool isAsyn
lhs => lhs.Select(lh => new { IsEradicated = lh.Eradicated == true }));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Accessing_property_of_optional_navigation_in_child_projection_works(bool isAsync)
{
return AssertQuery<CogTag>(
isAsync,
ts => ts.OrderBy(e => e.Note).Select(
t => new
{
Items = t.Gear != null
? t.Gear.Weapons.Select(w => new { w.Owner.Nickname }).ToList()
: null
}),
assertOrder: true,
elementAsserter: (e,a) => CollectionAsserter<dynamic>(
ee => ee.Nickname,
(ee, aa) => Assert.Equal(ee.Nickname, aa.Nickname))(e.Items, a.Items));
}

protected GearsOfWarContext CreateContext() => Fixture.CreateContext();

protected virtual void ClearLog()
Expand Down
5 changes: 5 additions & 0 deletions test/EFCore.Specification.Tests/Query/QueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,11 @@ public static Action<dynamic, dynamic> CollectionAsserter<TElement>(
{
return (e, a) =>
{
if (e == null && a == null)
{
return;
}
var actual = elementSorter != null
? ((IEnumerable<TElement>)a).OrderBy(elementSorter).ToList()
: ((IEnumerable<TElement>)a).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7170,6 +7170,33 @@ FROM [Factions] AS [f]
WHERE [f].[Discriminator] = N'LocustHorde'");
}

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

AssertSql(
@"SELECT CASE
WHEN [t0].[Nickname] IS NOT NULL THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END, [t].[Id], [t2].[Nickname], [t2].[Id]
FROM [Tags] AS [t]
LEFT JOIN (
SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOrBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank]
FROM [Gears] AS [g]
WHERE [g].[Discriminator] IN (N'Gear', N'Officer')
) AS [t0] ON (([t].[GearNickName] = [t0].[Nickname]) AND [t].[GearNickName] IS NOT NULL) AND (([t].[GearSquadId] = [t0].[SquadId]) AND [t].[GearSquadId] IS NOT NULL)
LEFT JOIN (
SELECT [t1].[Nickname], [w].[Id], [w].[OwnerFullName]
FROM [Weapons] AS [w]
LEFT JOIN (
SELECT [g0].[Nickname], [g0].[SquadId], [g0].[AssignedCityName], [g0].[CityOrBirthName], [g0].[Discriminator], [g0].[FullName], [g0].[HasSoulPatch], [g0].[LeaderNickname], [g0].[LeaderSquadId], [g0].[Rank]
FROM [Gears] AS [g0]
WHERE [g0].[Discriminator] IN (N'Gear', N'Officer')
) AS [t1] ON [w].[OwnerFullName] = [t1].[FullName]
) AS [t2] ON [t0].[FullName] = [t2].[OwnerFullName]
ORDER BY [t].[Note], [t].[Id], [t2].[Id]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Expand Down

0 comments on commit d3bdb77

Please sign in to comment.