Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TINY] Adding tests for #15641 - GroupBy FK_Id.HasValue on Sql Server generates invalid sql #19700

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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