-
Couldn't load subscription status.
- Fork 57
EnsureClean your database
Jon P Smith edited this page Nov 20, 2024
·
4 revisions
The EfCore.TestSupport library has a extension method called EnsureClean which used EF Core's internal code to provide fast way to "clean" a database. In version 9.0.0 that internal code changed and it wasn't easy to fix it, mainly because I have dementia (see this link for what happens to me).
My solution is keep the EnsureClean method, but now it runs EnsureDeleted, then EnsureCreated which provides you a new, empty database. I did this so that if you were using EnsureClean, then it will still work. Below is an example of using EnsureClean.
[Fact]
public void TestSqlServerEnsureClean()
{
//SETUP
//ATTEMPT
var options = this.CreateUniqueClassOptions<EfCoreContext>();
using var context = new EfCoreContext(options)
context.Database.EnsureClean();
//... left of test left out
}- Testing against a PostgreSQL db
- Changes in EfCore.TestSupport 5
- Testing with production data
- Using an in-memory database (old)