The general advice is I should always test my database migrations, but how to do it seems to be a well kept secret ;)
My chosen framework is FluentMigration.
What I think I want to do is:
- Migrate database to N-1.
- Save some data.
- Migrate database to N.
- Read data and verify it's not lost.
- Verify other relevant changes
But I can't figure out how to run the mig开发者_高级运维rations from my unit tests.
To kick off the migration in your integration tests just shell out to the migrate.exe command using Process.Start
For example
var migrator = System.Diagnostics.Process.Start("migrator.exe", "/connection \"Data Source=db\\db.sqlite;Version=3;\" /db sqlite /target your.migrations.dll");
migrator.WaitForExit();
If you're using MSTest you'll have to make sure that migrator.exe is included as a deployment item, or that you specify a path to where the .exe lives when you start the process.
精彩评论