imGreg
imGreg

Reputation: 900

Reconstruct Database after Unit Test with EF6

I want to delete the existing database and recreate it before or after the test are done. Is this even possible ?

I do see some properties in the context obj for deleting and createifnotexist but i am not sure how and where to put it.

Upvotes: 0

Views: 120

Answers (2)

user32826
user32826

Reputation:

Create a database initialiser which always drops and creates the database, populating it with seed data each time. Use that initialiser only in your unit test class.

Or better still, don't unit test EF, you don't gain anything. Mock your EF back end and only test your own code.

Upvotes: 1

Batavia
Batavia

Reputation: 2497

if you store you database as a file (mdb) you can just restore the original file.

otherwhite you could write the code that creates and populates it in you testinitialize method

look here http://msdn.microsoft.com/en-us/data/jj591621.aspx for a place to get started

Upvotes: 0

Related Questions