بنقرة واحدة
testing
// Implementation details for EF Core test infrastructure. Use when changing test fixtures, SQL baseline assertions, test helpers, the test class hierarchy, or when adding new tests.
// Implementation details for EF Core test infrastructure. Use when changing test fixtures, SQL baseline assertions, test helpers, the test class hierarchy, or when adding new tests.
| name | testing |
| description | Implementation details for EF Core test infrastructure. Use when changing test fixtures, SQL baseline assertions, test helpers, the test class hierarchy, or when adding new tests. |
| user-invocable | false |
test/EFCore.Tests/, test/EFCore.Relational.Tests/, test/EFCore.{Provider}.Tests/)Isolated logic tests. Build models via *TestHelpers.Instance.CreateConventionBuilder(), resolve services from CreateContextServices(). No database needed.
Define WHAT to test (LINQ queries, expected results). Can't be run directly — provider tests override to verify HOW (generated SQL).
test/EFCore.Specification.Tests/test/EFCore.Relational.Specification.Tests/test/EFCore.{Provider}.FunctionalTests/)Concrete provider tests inheriting specification tests. Most include SQL baseline assertions.
QueryTestBase<TFixture> # Core
└─ NorthwindWhereQueryTestBase<TFixture> # Specification
└─ NorthwindWhereQueryRelationalTestBase<TFixture> # Relational specification
└─ NorthwindWhereQuerySqlServerTest # Provider (asserts SQL)
Provider override pattern:
public override async Task Where_simple(bool async)
{
await base.Where_simple(async); // runs LINQ + asserts results
AssertSql("""..."""); // asserts provider-specific SQL
}
TestHelpers (abstract) # EFCore.Specification.Tests
├─ InMemoryTestHelpers # non-relational
└─ RelationalTestHelpers (abstract) # EFCore.Relational.Specification.Tests
├─ SqlServerTestHelpers
└─ SqliteTestHelpers
Key methods: CreateConventionBuilder(), CreateContextServices(model), CreateOptions()
Many tests share one database. Creates TestStore + pooled DbContextFactory in InitializeAsync(). Seeds data once. Use for read-heavy tests (e.g., Northwind query tests).
Each test gets a fresh model/store. Call InitializeAsync<TContext>(onModelCreating, seed, ...) per test. Use for tests needing unique schemas.
TestSqlLoggerFactory captures SQL. AssertSql("""...""") compares against expected. Set EF_TEST_REWRITE_BASELINES=1 to auto-rewrite baselines via Roslyn.
EFCore.Specification.Tests (core) or EFCore.Relational.Specification.Tests (relational)EFCore.{Provider}.FunctionalTests) that inherits the base with provider-appropriate assertions.EFCore.{Provider}.TestsEF_TEST_REWRITE_BASELINES=1 to capture initial baselines--no-build) to ensure code changes are picked up| Pitfall | Solution |
|---|---|
| Baseline mismatch (SQL or compiled model) | Re-run with EF_TEST_REWRITE_BASELINES=1 |
Check_all_tests_overridden fails | Override the new test in every inheriting provider class |
| SQL Server feature missing at lower compat level | Gate with [SqlServerCondition(...)] |
Run ApiChief in the EF Core repo to emit baselines, summaries, deltas, review files, or breaking-change checks. Use when refreshing `*.baseline.json`, preparing API review artifacts, or validating API changes.
Implementation details for the EF Core Azure Cosmos DB provider. Use when changing Cosmos-specific code.
Create custom GitHub Copilot agents. Use when asked to create, scaffold, or configure a custom agent, declarative agent, or @-invokable chat participant for GitHub Copilot.
Create new Agent Skills for GitHub Copilot. Use when asked to create, scaffold, or add a skill. Generates SKILL.md with frontmatter, directory structure, and optional resources.
Implementation details for EF Core migrations. Use when changing MigrationsSqlGenerator, model diffing, migration operations, HistoryRepository, the Migrator or related classes.
Implementation details for EF Core LINQ query translation, SQL generation, and bulk operations (ExecuteUpdate/ExecuteDelete). Use when changing expression visitors, SqlExpressions, QuerySqlGenerator, ShaperProcessingExpressionVisitor, UpdateExpression, DeleteExpression, or related classes.