I would like to implement some sort of test environment for ASP.Net projects. I am trying to implement this as an alternative to mocking the entity framework.
Here is what I am trying to achieve :
- Two
DBContext
classes are used, one for development, one for tests. - These two
DBContext
classes will generate 2 databases throughEnable-Migration
/Update-Migration
. Again, one for development, one for tests. - Adding a new migration must be applied to both the development environment and the test environment.
Basically, the development database and test database must be identical. Therefore, my goal is to find a way so that we only have to run each type of command once to control both environments :
Enable-Migrations
creates two migration configuration classes.Add-Migration
can be applied to the two environments.Update-database
applies the migrations on both environments.
Here is my attempt first attempt at the context classes :
namespace Project.DAL
{
public class Context : DbContext
{
public Context(string connectionString) : base(connectionString) { }
public Context() : base() { }
public DbSet<User> Users { get; set; }
public DbSet<Team> Teams { get; set; }
public DbSet<Pool> Pools { get; set; }
public DbSet<Match> Matches { get; set; }
public DbSet<Invitation> Invitations { get; set; }
}
public class Dev : Context
{
public Dev() : base("project_dev") { }
}
public class Test : Context
{
public Test() : base("project_test") { }
}
}
How would you guys approach this? I am coming from the Ruby On Rails framework, which has a development/test environment similar to what I am looking for.
This is with the code-first approach. So ideally, if one were to create a new project, he designs his models and applies migrations to populate/create two databases representing your development and test environments.