First, try to run some unit tests with EF 4.1 code. I have my live db (SQL Server) and my unit test DB (Sql CE). After struggling (and losing) with EF, Sql CE 4.0 and transaction support, I decided that the easiest way to run my test was as follows:
- Create db
- Run test
- Delete Db
- Rinse and repeat
I have the functions [Setup] and [TearDown]:
[SetUp] public void Init() { System.Data.Entity.Database.SetInitializer(new MyTestContextInitializer()); _dbContext = ContainerFactory.Container.GetInstance<IContext>(); _testConnection = _dbContext.ConnectionString; } [TearDown] public void Cleanup() { _dbContext.Dispose(); System.Data.Entity.Database.Delete(_testConnection); }
The problem is that System.Data.Entity.Database.SetInitializer does not call MyTestContextInitializer after the first test.
Therefore, the second test fails:
System.Data.EntityException: The underlying provider could not open Open.
----> System.Data.SqlServerCe.SqlCeException: Database file not found. Check database path
TIA for any pointers
nunit entity-framework sql-server-ce-4
ozczecho
source share