Simplified Unit Testing with the Entity Framework Core InMemory Provider
summary
Advocates using the EF Core InMemory provider to replace mocks so tests new up a real DbContext, seed six customers, and assert behavior; one demo has 12 controller tests with 11 failing until each test uses a unique database name via Guid.NewGuid().ToString() and calls database.EnsureCreated then database.EnsureDeleted to clean up. A reusable NorthwindTestBase centralizes context setup. Beware limitations: the in‑memory store is not relational so referential constraints aren’t enforced and these are closer to lightweight integration tests than provider‑specific integration tests.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 1:07The typical approach
- 2:25The simplified approach
- 4:09In-memory provider demo
- 7:23Web API testing demo
- 9:40Using a test base class
- 11:05Limitations and concerns
- 13:11Resources and summary
related talks
33mNo More SQLite - How to Write Tests With EF Core Using TestContainers
54m.NET Testing Best Practices
01h 10mModern Data Applications with Entity Framework 7
52mxUnit Expanded – Better Testing With xUnit
46mUnit-Testing With Ease
01h 00mGetting the best out of Entity Framework Core
01h 04mClean Testing - Clean Architecture with .NET Core
44mEF Core database model first - take it to the next level with Power Tools CLI
