Skip to content

Commit 68c6c6e

Browse files
CopilotPhenX
andauthored
Address code review feedback: explicit private modifiers, helper method, remove duplicate test
Agent-Logs-Url: https://github.com/EFNext/EntityFrameworkCore.Projectables/sessions/a64490fa-46e4-49f0-8bf9-d507f70ef85d Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
1 parent 0d80766 commit 68c6c6e

2 files changed

Lines changed: 14 additions & 33 deletions

File tree

tests/EntityFrameworkCore.Projectables.VendorTests/EFCoreBulkExtensionsCompatibilityTests.cs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace EntityFrameworkCore.Projectables.VendorTests;
1919
/// </summary>
2020
public class EFCoreBulkExtensionsCompatibilityTests : IDisposable
2121
{
22-
readonly TestDbContext _context;
22+
private readonly TestDbContext _context;
2323

2424
public EFCoreBulkExtensionsCompatibilityTests()
2525
{
@@ -59,20 +59,6 @@ public void GetDbContext_WithProjectablesEnabled_ReturnsCorrectContext()
5959
Assert.Same(_context, dbContext);
6060
}
6161

62-
[Fact]
63-
public void GetDbContext_WithProjectableProperty_DoesNotThrow()
64-
{
65-
// Arrange – entity with a [Projectable] property so that CustomQueryCompiler is
66-
// exercised with actual projectable expression expansion.
67-
var query = _context.Set<Order>().Where(o => o.IsCompleted);
68-
69-
// Act
70-
var exception = Record.Exception(() => BatchUtil.GetDbContext(query));
71-
72-
// Assert
73-
Assert.Null(exception);
74-
}
75-
7662
[Fact]
7763
public async Task BatchDeleteAsync_WithProjectablesEnabled_DoesNotThrowTargetException()
7864
{
@@ -87,16 +73,11 @@ public async Task BatchDeleteAsync_WithProjectablesEnabled_DoesNotThrowTargetExc
8773
() => query.BatchDeleteAsync(TestContext.Current.CancellationToken));
8874
#pragma warning restore CS0618
8975

90-
// Assert – a TargetException means the reflection-based DbContext discovery
91-
// inside EFCore.BulkExtensions failed. All other exceptions (e.g. SQL syntax
92-
// differences on SQLite) are acceptable because they come from actual SQL
93-
// execution, not from the broken reflection chain.
94-
Assert.False(
95-
exception is System.Reflection.TargetException,
96-
$"BatchDeleteAsync threw TargetException: {exception?.Message}");
97-
Assert.False(
98-
exception?.Message?.Contains("Non-static method requires a target") == true,
99-
$"BatchDeleteAsync threw 'Non-static method requires a target': {exception?.Message}");
76+
// A TargetException means the reflection-based DbContext discovery inside
77+
// EFCore.BulkExtensions failed. Other exceptions (e.g. SQL syntax differences
78+
// on SQLite) are acceptable because they come from actual SQL execution, not
79+
// from the broken reflection chain.
80+
AssertNoTargetException(exception, "BatchDeleteAsync");
10081
}
10182

10283
[Fact]
@@ -113,12 +94,12 @@ public async Task BatchUpdateAsync_WithProjectablesEnabled_DoesNotThrowTargetExc
11394
cancellationToken: TestContext.Current.CancellationToken));
11495
#pragma warning restore CS0618
11596

116-
// Assert – same as above: only TargetException is a regression.
117-
Assert.False(
118-
exception is System.Reflection.TargetException,
119-
$"BatchUpdateAsync threw TargetException: {exception?.Message}");
120-
Assert.False(
121-
exception?.Message?.Contains("Non-static method requires a target") == true,
122-
$"BatchUpdateAsync threw 'Non-static method requires a target': {exception?.Message}");
97+
AssertNoTargetException(exception, "BatchUpdateAsync");
12398
}
99+
100+
private static void AssertNoTargetException(Exception? exception, string operationName)
101+
=> Assert.False(
102+
exception is System.Reflection.TargetException,
103+
$"{operationName} threw TargetException (\"Non-static method requires a target\"). " +
104+
$"This indicates that CustomQueryCompiler's _queryContextFactory shadow field is missing.");
124105
}

tests/EntityFrameworkCore.Projectables.VendorTests/TestContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TestDbContext : DbContext
2424
{
2525
// Keep the connection open for the lifetime of the context so the in-memory
2626
// SQLite database is not destroyed between operations.
27-
readonly SqliteConnection _connection;
27+
private readonly SqliteConnection _connection;
2828

2929
public TestDbContext()
3030
{

0 commit comments

Comments
 (0)