0

I have a few tests to test the patching functionality. I am using this custom factory https://github.com/aspnet/Docs/blob/master/aspnetcore/test/integration-tests/samples/2.x/IntegrationTestsSample/tests/RazorPagesProject.Tests/CustomWebApplicationFactory.cs

For each test, I want to create new database or at-least clear and seed data again. Because other tests are messing up with data.

1 Answer 1

1

You can use

 db.Database.EnsureDeleted();

This ensures that the database for the context does not exist. If it does not exist, no action is taken. If it does exist then the database is deleted.

Sign up to request clarification or add additional context in comments.

4 Comments

yeah I saw that somewhere, but not sure where exactly to use that.
In the factory mentioned above on line 44 - right before EnsureCreated()
yeah but that only runs once in the scope, when I run all tests in one file, it's under single scope, so test share the context and hence same data
Use IClassFixture<T> - See here...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.