开发者

How can I unit test my FluentMigrator migrations?

开发者 https://www.devze.com 2023-04-01 22:34 出处:网络
The general advice is I should always test my database migrations, but how to do it seems to be a well kept secret ;)

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:

  1. Migrate database to N-1.
  2. Save some data.
  3. Migrate database to N.
  4. Read data and verify it's not lost.
  5. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消