public void SetUp() { MigrationTestHelper.Clear(); _versionsFromDatabase = new List <long> { 0 }; var provider = new Mock <IDataProvider>(); provider.Setup(x => x.DatabaseKind).Returns(DatabaseKind.Oracle); var database = new Mock <IDatabase>(); database.Setup(x => x.Provider).Returns(provider.Object); _dataClient = new Mock <IDataClient>(); _dataClient.Setup(p => p.TableExists(VersionRepository.VERSION_TABLE_NAME)).Returns(true); _dataClient.Setup(x => x.Database).Returns(database.Object); _versionRepository = new Mock <IVersionRepository>(); _versionRepository.Setup(x => x.GetCurrentVersion()).Returns(() => _versionsFromDatabase.Last()); _versionRepository.Setup(x => x.GetAppliedMigrations()).Returns(() => _versionsFromDatabase); _versionRepository.Setup(x => x.InsertVersion(It.IsAny <MigrationInfo>())) .Callback <MigrationInfo>(m => _versionsFromDatabase.Add(m.Version)); _versionRepository.Setup(x => x.RemoveVersion(It.IsAny <MigrationInfo>())) .Callback <MigrationInfo>(m => _versionsFromDatabase.Remove(m.Version)); _runner = new Runner(_dataClient.Object, Assembly.GetExecutingAssembly()); _runner.VersionRepository = _versionRepository.Object; }
public void Negative_target_version_means_last_version() { _runner.Run(-1); long maxVersion = VersionHelper.GetVersion(MigrationTestHelper.GetMigrations().Last()); Assert.AreEqual(maxVersion, MigrationTestHelper.ExecutedMigrationsUp.Last().Version); }
public void Should_run_old_migrations_going_up() { SetVersion(6); _versionsFromDatabase.RemoveAt(2); _runner.Run(6); Assert.AreEqual(1, MigrationTestHelper.ExecutedMigrationsUp.Count); Assert.IsTrue(MigrationTestHelper.ExecutedMigrationsUp.Any(x => x.Version == 2)); MigrationTestHelper.Clear(); }
public void Should_run_old_migrations_going_down() { SetVersion(7); _versionsFromDatabase.RemoveAt(5); _versionRepository.Setup(x => x.EnsureSchemaVersionTable(It.IsAny <List <MigrationInfo> >())) .Callback <List <MigrationInfo> >(list => list.RemoveRange(5, 1)); _runner.Run(5); Assert.AreEqual(1, MigrationTestHelper.ExecutedMigrationsUp.Count); Assert.IsTrue(MigrationTestHelper.ExecutedMigrationsUp.Any(x => x.Version == 5)); MigrationTestHelper.Clear(); }
public void Go_up_and_down_twice() { _runner.Run(6); Assert.AreEqual(6, MigrationTestHelper.ExecutedMigrationsUp.Count); Assert.AreEqual(typeof(Migration6), MigrationTestHelper.ExecutedMigrationsUp.Last().GetType()); MigrationTestHelper.Clear(); _runner.Run(0); Assert.AreEqual(6, MigrationTestHelper.ExecutedMigrationsDown.Count); Assert.AreEqual(typeof(Migration1), MigrationTestHelper.ExecutedMigrationsDown.Last().GetType()); MigrationTestHelper.Clear(); _runner.Run(3); Assert.AreEqual(3, MigrationTestHelper.ExecutedMigrationsUp.Count); Assert.AreEqual(typeof(Migration3), MigrationTestHelper.ExecutedMigrationsUp.Last().GetType()); }
public void Should_expose_the_last_version_number() { var expectedLastVersion = VersionHelper.GetVersion(MigrationTestHelper.GetMigrations().Last()); Assert.AreEqual(expectedLastVersion, _runner.LastVersionNumber); }
public override void Down() { MigrationTestHelper.RegisterDown(this); }
public override void Up() { MigrationTestHelper.RegisterUp(this); }