|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Verify.EntityFramework extends the [Verify](https://github.com/VerifyTests/Verify) snapshot testing framework to support Entity Framework testing. It provides utilities for snapshot testing EF operations including change tracking, query execution, and SQL recording. |
| 8 | + |
| 9 | +The repository contains two main packages: |
| 10 | +- **Verify.EntityFramework** - For EF Core (modern) |
| 11 | +- **Verify.EntityFrameworkClassic** - For EF 6 (legacy) |
| 12 | + |
| 13 | +## Build Commands |
| 14 | + |
| 15 | +```bash |
| 16 | +# Build the solution |
| 17 | +dotnet build src |
| 18 | + |
| 19 | +# Run tests (excludes integration tests by default) |
| 20 | +dotnet test src |
| 21 | + |
| 22 | +# Run a specific test |
| 23 | +dotnet test src --filter "FullyQualifiedName~CoreTests.Added" |
| 24 | + |
| 25 | +# Run tests in a specific project |
| 26 | +dotnet test src/Verify.EntityFramework.Tests |
| 27 | +``` |
| 28 | + |
| 29 | +## Project Structure |
| 30 | + |
| 31 | +``` |
| 32 | +src/ |
| 33 | +├── Verify.EntityFramework/ # EF Core library |
| 34 | +│ ├── VerifyEntityFramework.cs # Main public API |
| 35 | +│ ├── Converters/ # JSON converters for EF objects |
| 36 | +│ │ ├── QueryableConverter.cs # Converts IQueryable to SQL + results |
| 37 | +│ │ ├── TrackerConverter.cs # Converts ChangeTracker state |
| 38 | +│ │ └── LogEntryConverter.cs # Recorded SQL entries |
| 39 | +│ ├── LogCommandInterceptor.cs # DbCommandInterceptor for SQL recording |
| 40 | +│ └── MissingOrder/ # Detects missing ORDER BY clauses |
| 41 | +│ |
| 42 | +├── Verify.EntityFramework.Tests/ # EF Core tests |
| 43 | +├── Verify.EntityFrameworkClassic/ # EF 6 library |
| 44 | +└── Verify.EntityFrameworkClassic.Tests/ |
| 45 | +``` |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +### Module Initialization Pattern |
| 50 | +Tests use `[ModuleInitializer]` to call `VerifyEntityFramework.Initialize(model)` once at assembly load, passing an `IModel` from a DbContext. This caches navigation property information for later use. |
| 51 | + |
| 52 | +### Key Extension Points |
| 53 | + |
| 54 | +1. **Converters** - Custom JSON converters inherit from `WriteOnlyJsonConverter<T>` and are registered globally via `VerifierSettings.RegisterFileConverter()` or added to `DefaultContractResolver.Converters`. |
| 55 | + |
| 56 | +2. **Recording System** - `LogCommandInterceptor` implements `DbCommandInterceptor` to capture SQL operations. Enable via `builder.EnableRecording()` on `DbContextOptionsBuilder`. |
| 57 | + |
| 58 | +3. **Queryable Verification** - When verifying an `IQueryable`, generates both a `.txt` file (query results) and a `.sql` file (the SQL query). |
| 59 | + |
| 60 | +### Main API Methods (VerifyEntityFramework.cs) |
| 61 | + |
| 62 | +- `Initialize(IModel)` - Required setup, caches model metadata |
| 63 | +- `AllData()` - DbContext extension to enumerate all database entities |
| 64 | +- `IgnoreNavigationProperties()` - Exclude EF navigation properties from serialization |
| 65 | +- `EnableRecording()` - Enable SQL command recording on DbContextOptionsBuilder |
| 66 | +- `DisableRecording()` - Stop recording for a specific context instance |
| 67 | +- `ThrowForMissingOrderBy()` - Enforce ORDER BY clauses in queries |
| 68 | +- `ScrubInlineEfDateTimes()` - Sanitize DateTime values in SQL |
| 69 | + |
| 70 | +## Testing Conventions |
| 71 | + |
| 72 | +- Uses NUnit with `[Parallelizable(ParallelScope.All)]` |
| 73 | +- Snapshot files follow pattern: `TestClass.TestMethod.verified.txt` |
| 74 | +- Async tests use `await Verify(...)` pattern |
| 75 | +- Tests create in-memory SQLite databases or use SQL Server LocalDB |
| 76 | + |
| 77 | +## Dependencies |
| 78 | + |
| 79 | +- .NET 10.0 SDK (preview features enabled) |
| 80 | +- C# language version: preview |
| 81 | +- Key packages: Verify, Microsoft.EntityFrameworkCore, NUnit |
0 commit comments