如何对我的FluentMigrator迁移进行单元测试?

Tho*_*yde 5 unit-testing fluent-migrator

一般的建议是我应该总是测试我的数据库迁移,但是如何做到这似乎是一个保密的秘密;)

我选择的框架是FluentMigration.

我想我想做的是:

  1. 将数据库迁移到N-1.
  2. 保存一些数据.
  3. 将数据库迁移到N.
  4. 读取数据并确认它没有丢失.
  5. 验证其他相关更改

但我无法弄清楚如何从我的单元测试中运行迁移.

Ric*_*nks 2

要在集成测试中启动迁移,只需使用 Process.Start 执行 migrate.exe 命令

例如

var migrator = System.Diagnostics.Process.Start("migrator.exe", "/connection \"Data Source=db\\db.sqlite;Version=3;\" /db sqlite /target your.migrations.dll");
migrator.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

如果您使用 MSTest,则必须确保将 migrator.exe 作为部署项包含在内,或者在启动进程时指定 .exe 所在位置的路径。