I'm attempting to write unit/integration tests for my ASP.NET Web API project and struggling to run each test in isolation. Allow me to explain.
I have a *.testsettings file with deployment settings configured. Before each test run, an empty *.mdf file is deployed to the test location. Since I'm using Entity Framework Code First, I can use a database initializer to push my schema to the database and seed a particular table with 2 rows. This works great.
The problem I'm facing is that the various tests for all of my ApiControllers' actions can step on each other's toes if they execute in the wrong order. For example, if I run the GET test before the POST test then GET returns 2 objects with if they are run in the reverse order then GET returns 3 objects.
What I think I need to do is drop, recreate and reseed my database before every test. Is this a good idea or is there are better way? If this is the best I can do, I would I go about resetting my database before each test.