c# - EF 6.1 how to swap migration configurations for testing? -


i trying use integration testing using ef 6.1 , run problem migration configuration settings used dont need them. , cant figure out how swap them out testing. here test class:

[testclass] public class sxseasonconvertertests {     public void recreatedatabasefortesting()     {         database.setinitializer(new testdatabaseseedinginitializer());         using (var context = new basenflcontext("nflcontextintegrationtests"))         {             context.database.initialize(true);         }     }      public sxseasonconvertertests()     {         recreatedatabasefortesting();     } } 

here initializer class:

public class testdatabaseseedinginitializer : dropcreatedatabasealways<basenflcontext> {     protected override void seed(basenflcontext context)     {         //add teams         context.teams.add(new team { code = "arz", name = "arizona cardinals" });         context.teams.add(new team { code = "atl", name = "atlanta falcons" });         ...     } } 

however when try run test, error automaticmigrations disabled. when looked further found uses code on initialize:

internal sealed class nflconfiguration : dbmigrationsconfiguration<basenflcontext> {     public nflconfiguration()     {         automaticmigrationsenabled = false;         automaticmigrationdatalossallowed = false;     } } 

this code there production. when doing testing how can swap migration configurations , set automaticmigrationsenabled = true;?

i used test ef stuff using special unittesting database , executed tests in transactionscope rolled @ end of test. way, no data stored in database.

i wasn't fast, suited our purpose.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -