mardi 23 juin 2020

How to implement database seeding for testing with Entity Framework

I need to implement testing for some applications, but I'm not sure what would be the best and cleanest way to implement the tests in a way that it is easily maintainable. The scenario is as follows:

I have multiple applications, including a MVC .Net Framework project, and multiple Azure functions, one implemented with .Net Framework cause some dependencies need it, but most of them in .Net Core. All those applications uses EntityFramework to operate a MSSQL database, and I need to find a way to seed an in memory or temporary database with default configuration data and some pre-made records before testing.

One solution I thought of is to make a Class Library project that seeds the database, and every testing project can reference that project, and when something needs to be added to the seed you just have to edit that project. But I don't know if this is the best solution, because I have .Net Framework and .Net Core apps, so probably I need at least 2 implementations of each method for each of the EntityFramework versions, and I'm not sure if in this way my seeder class needs to know the DB schema or I can implement code based on DBContext class for example.

Would this be a good solution? Is there any other standard way of implementing something like this?

Aucun commentaire:

Enregistrer un commentaire