Skip to content

Commit 2ce7698

Browse files
Copilotcincuranet
andcommitted
Add tests for conditional IQueryable null checks
Added two new tests that verify the fix handles cases where an IQueryable variable could legitimately be null: - Where_Queryable_conditional_null_check_with_Contains: Tests `ids != null && ids.Contains(...)` - Where_Queryable_conditional_null_check_with_Contains_negated: Tests `ids == null || !ids.Contains(...)` Both tests use a someFlag parameter to conditionally assign the IQueryable, ensuring null checks work correctly when the variable could be null. Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
1 parent 089643f commit 2ce7698

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/EFCore.Specification.Tests/Query/NorthwindWhereQueryTestBase.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,36 @@ public virtual Task Where_Queryable_null_check_with_Contains(bool async)
14591459
},
14601460
assertEmpty: true);
14611461

1462+
[ConditionalTheory]
1463+
[InlineData(true, true)]
1464+
[InlineData(true, false)]
1465+
[InlineData(false, true)]
1466+
[InlineData(false, false)]
1467+
public virtual Task Where_Queryable_conditional_null_check_with_Contains(bool async, bool someFlag)
1468+
=> AssertQuery(
1469+
async,
1470+
ss =>
1471+
{
1472+
var ids = someFlag ? ss.Set<Customer>().Select(c => c.CustomerID) : null;
1473+
return ss.Set<Customer>().Where(c => ids != null && ids.Contains(c.CustomerID));
1474+
},
1475+
assertEmpty: !someFlag);
1476+
1477+
[ConditionalTheory]
1478+
[InlineData(true, true)]
1479+
[InlineData(true, false)]
1480+
[InlineData(false, true)]
1481+
[InlineData(false, false)]
1482+
public virtual Task Where_Queryable_conditional_null_check_with_Contains_negated(bool async, bool someFlag)
1483+
=> AssertQuery(
1484+
async,
1485+
ss =>
1486+
{
1487+
var ids = someFlag ? ss.Set<Customer>().Select(c => c.CustomerID) : null;
1488+
return ss.Set<Customer>().Where(c => ids == null || !ids.Contains(c.CustomerID));
1489+
},
1490+
assertEmpty: someFlag);
1491+
14621492
[ConditionalTheory, MemberData(nameof(IsAsyncData))]
14631493
public virtual Task Where_collection_navigation_ToList_Count(bool async)
14641494
=> AssertQuery(

0 commit comments

Comments
 (0)