I use continuous integration with TeamCity, NUnit and Git. I recently migrated (pardon pun) from FluentMigrator to Entity Framework Migrations. First of all, I did this to take advantage of the functionality of forests.
Nevertheless, you can potentially check some changes in the initial control without first changing the changes in the migrations (imagine a scenario in which the application was not executed before committing and clicking on the commit). I use a pre-tested business commit process , so I would like to detect this problem in the pre-testing , and not wait until migrate.exe is called (which would be too late in my workflow and break the "green repository").
My question is how to create a unit / integration test to determine when the migration model does not match the context model, so can I complete the assembly before trying to migrate it? Please note that I expect it to not match the database and would prefer not to access the database from the test.
I tried this approach:
[Test] public void CheckWhetherEntityFrameworkMigrationsContextIsUpToDate() { Assert.DoesNotThrow(() => { CallDatabase(); }); } private void CallDatabase() { using (var ctx = new MyContext("SERVER=(local);DATABASE=MyDatabase;Integrated Security=True;")) { var tenant = (from t in ctx.Tenant select t).FirstOrDefault(); } }
But this will always fail if there are pending migrations (and not only if the migration model is not synchronized with the context model, which I do after that).
Update
I added the EntityFramework project to the EntityFramework project in this project. I hope they consider creating this method.
source share