public void AddMessageIfNoPreviousVersion() { var underTest = new RollbackMigrationAction(_migratorFactory.Object); underTest.Migrate(_request, _result); Assert.Equal("EF Plugin: There were no previous model migrations so nothing needed to rollback.", _result.InfoMessages.Single()); }
public void DoesNotCreateContextIfNoPreviousVersion() { var underTest = new RollbackMigrationAction(_migratorFactory.Object); underTest.Migrate(_request, _result); _migratorFactory.Verify(m => m.CreateDbContext(It.IsAny <string>()), Times.Never); }
public void AddsExecutingMessage(DbAuthType authType) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); underTest.Migrate(_request, _result); Assert.Contains("EF Plugin: Executing rollback", _result.InfoMessages); }
public void EnsuresCurrentVersionDoesNotExist(DbAuthType authType) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); underTest.Migrate(_request, _result); _repo.Verify(m => m.EnsureDoesNotExist(TestConstants.VerAlias), Times.Once); }
public void RetrievesPreviousVersion(DbAuthType authType) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); underTest.Migrate(_request, _result); _repo.Verify(m => m.GetTargetMigration(TestConstants.PreviousVersion), Times.Once); }
public void DisposesContext(DbAuthType authType) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); underTest.Migrate(_request, _result); _context.Verify(m => m.Dispose(), Times.Once); }
public void AddsMessageMigrationComplete(DbAuthType authType) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); const string targetMigration = "target"; _repo.Setup(m => m.GetTargetMigration(TestConstants.PreviousVersion)).Returns(targetMigration); underTest.Migrate(_request, _result); Assert.Contains($"EF Plugin: Rolled back schema to migration target '{targetMigration}'", _result.InfoMessages); }
public void CreatesAndCallsMigrator(DbAuthType authType, string connString) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); const string targetMigration = "target"; _repo.Setup(m => m.GetTargetMigration(TestConstants.PreviousVersion)).Returns(targetMigration); underTest.Migrate(_request, _result); _migratorFactory.Verify(m => m.CreateMigrator(connString), Times.Once); _migrator.Verify(m => m.Update(targetMigration), Times.Once); }
public void SavesChangesAndAddsMessage(DbAuthType authType, bool existed, int existedCnt) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); const string targetMigration = "target"; _repo.Setup(m => m.GetTargetMigration(TestConstants.PreviousVersion)).Returns(targetMigration); _repo.Setup(m => m.EnsureDoesNotExist(TestConstants.VerAlias)).Returns(existed); underTest.Migrate(_request, _result); _context.Verify(m => m.SaveChanges(), Times.Exactly(existedCnt)); Assert.Equal(existed, _result.InfoMessages.Contains($"EF Plugin: removed '{targetMigration}' from migration mapping history")); }
public void CreatesContextBeforeRepo(DbAuthType authType, string connString) { var underTest = new RollbackMigrationAction(_migratorFactory.Object); TestConstants.ConfigureRequest(_request, authType); var contextCreated = false; var contextCreatedBeforeRepo = false; _migratorFactory.Setup(m => m.CreateDbContext(It.IsAny <string>())) .Callback(() => contextCreated = true); _migratorFactory.Setup(m => m.CreateMigrationRepository(It.IsAny <IMigrationVersionContext>())) .Callback(() => contextCreatedBeforeRepo = contextCreated) .Returns(_repo.Object); underTest.Migrate(_request, _result); _migratorFactory.Verify(m => m.CreateDbContext(connString), Times.Once); Assert.True(contextCreatedBeforeRepo); }