vendredi 8 janvier 2016

Unit testing EF6 with Sqlite, how do I create tables in the in-memory db?

I have several questions regarding this, but the main one is, is there a way to use Sqlite with EF6 for unit testing? I need to be able to create the drop and create tables on the fly so the entire db is flushed before every test.

I've so far found numerous (outdated) articles that go on about the workarounds needed for sqlite to work with EF6, but since sqlite is now supported with EF6, How do I do that?

I have data layer that has all the entities and DbContext. I'm accessing this with my api layer with sql server connection string and it all works.

I've just now added a unit test project, and have installed System.Data.Sqlite 1.0.99.0 and System.Data.SQLite.EF6 1.0.99.0, along with Entity Framework.

Now, what I cannot figure out, is, how do I Create a database and tables in this unit test project? A step by step guide (or a link to one posted elsewhere) would be greatly appreciated.

My webconfig connection string is like so:

<add name="dbContext" connectionString="Data Source=:memory:" providerName="System.Data.SqlClient" />

So, to sum up, I need to create the tables at startup, and then flush all tables after each test (or just drop/recreate)

Aucun commentaire:

Enregistrer un commentaire