EnsureClean your database - JonPSmith/EfCore.TestSupport GitHub Wiki
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
}