Skip to content

Commit

Permalink
Adding tests for #15641 - GroupBy FK_Id.HasValue on Sql Server genera…
Browse files Browse the repository at this point in the history
…tes invalid sql

The issue has been fixed earlier.

Resolves #15641
  • Loading branch information
maumar committed Jan 25, 2020
1 parent 9cd8445 commit 6fd1862
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7548,6 +7548,28 @@ public virtual Task Projecting_required_string_column_compared_to_null_parameter
ss => ss.Set<Gear>().Select(g => g.Nickname == nullParameter));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Group_by_nullable_property_HasValue_and_project_the_grouping_key(bool async)
{
return AssertQueryScalar(
async,
ss => ss.Set<Weapon>()
.GroupBy(w => w.SynergyWithId.HasValue)
.Select(g => g.Key));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Group_by_nullable_property_and_project_the_grouping_key_HasValue(bool async)
{
return AssertQueryScalar(
async,
ss => ss.Set<Weapon>()
.GroupBy(w => w.SynergyWithId)
.Select(g => g.Key.HasValue));
}

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

protected virtual void ClearLog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7527,6 +7527,35 @@ FROM [Gears] AS [g]
WHERE [g].[Discriminator] IN (N'Gear', N'Officer')");
}

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

AssertSql(
@"SELECT CASE
WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
FROM [Weapons] AS [w]
GROUP BY CASE
WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END");
}

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

AssertSql(
@"SELECT CASE
WHEN [w].[SynergyWithId] IS NOT NULL THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
FROM [Weapons] AS [w]
GROUP BY [w].[SynergyWithId]");
}

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

0 comments on commit 6fd1862

Please sign in to comment.