Skip to content

Commit

Permalink
Improve coalesce-related tests
Browse files Browse the repository at this point in the history
This change aims at ensuring that the expressions within the queries being
tested cannot be trivially optimized away.

Base on the suggestion by @maumar in
dotnet#33938 (comment)
  • Loading branch information
ranma42 committed Jun 16, 2024
1 parent 0fe066c commit 8590af8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public virtual Task Where_not_equal_with_coalesce(bool async)
public virtual Task Where_equal_with_coalesce_both_sides(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<NullSemanticsEntity1>().Where(e => (e.NullableStringA ?? e.NullableStringB) == (e.StringA ?? e.StringB))
ss => ss.Set<NullSemanticsEntity1>().Where(e => (e.NullableStringA ?? e.NullableStringB) == (e.NullableStringC ?? e.StringA))
.Select(e => e.Id));

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1793,21 +1793,21 @@ from g2 in grouping.DefaultIfEmpty()
public virtual Task Coalesce_operator_in_predicate(bool async)
=> AssertQuery(
async,
ss => ss.Set<Weapon>().Where(w => (bool?)w.IsAutomatic ?? false));
ss => ss.Set<CogTag>().Where(x => (bool?)x.Gear.HasSoulPatch ?? false));
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Coalesce_operator_in_predicate_with_other_conditions(bool async)
=> AssertQuery(
async,
ss => ss.Set<Weapon>().Where(w => w.AmmunitionType == AmmunitionType.Cartridge && ((bool?)w.IsAutomatic ?? false)));
ss => ss.Set<CogTag>().Where(x => x.Note != "K.I.A." && ((bool?)x.Gear.HasSoulPatch ?? false)));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Coalesce_operator_in_projection_with_other_conditions(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<Weapon>().Select(w => w.AmmunitionType == AmmunitionType.Cartridge && ((bool?)w.IsAutomatic ?? false)));
ss => ss.Set<CogTag>().Select(x => x.Note != "K.I.A." && ((bool?)x.Gear.HasSoulPatch ?? false)));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,7 @@ public virtual Task Filter_coalesce_operator(bool async)
=> AssertQuery(
async,
ss => ss.Set<Customer>()
.Where(c => (c.CompanyName ?? c.ContactName) == "The Big Cheese"));
.Where(c => (c.ContactName ?? c.CompanyName) == "Liz Nixon"));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
Expand Down

0 comments on commit 8590af8

Please sign in to comment.