Esempio n. 1
0
            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());
            }
Esempio n. 2
0
            public void DoesNotCreateContextIfNoPreviousVersion()
            {
                var underTest = new RollbackMigrationAction(_migratorFactory.Object);

                underTest.Migrate(_request, _result);

                _migratorFactory.Verify(m => m.CreateDbContext(It.IsAny <string>()), Times.Never);
            }
Esempio n. 3
0
            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);
            }
Esempio n. 4
0
            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);
            }
Esempio n. 5
0
            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);
            }
Esempio n. 6
0
            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);
            }
Esempio n. 7
0
            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);
            }
Esempio n. 8
0
            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);
            }
Esempio n. 9
0
            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"));
            }
Esempio n. 10
0
            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);
            }