示例#1
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);
            }
示例#2
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);
            }
                public void CallsUpdate(DbAuthType authType)
                {
                    TestConstants.ConfigureRequest(Request, authType);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    Migrator.Verify(m => m.Update(), Times.Once);
                }
示例#4
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);
            }
                public void AddsMessage(DbAuthType authType)
                {
                    TestConstants.ConfigureRequest(Request, authType);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    Assert.Contains("EF Plugin: There were no model changes found so no migrations applied",
                                    Result.InfoMessages);
                }
                public void RetrievesLastMigration(DbAuthType authType, string connString)
                {
                    TestConstants.ConfigureRequest(Request, authType);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    MigratorFactory.Verify(m => m.CreateMigrator(connString), Times.Once);
                    Migrator.Verify(m => m.GetLocalMigrations(), Times.Once);
                }
                public void AddsExecutionMessages(DbAuthType authType)
                {
                    TestConstants.ConfigureRequest(Request, authType);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    Assert.Contains($"EF Plugin: Successfully executed EF migration up to '{lastMigration}'", Result.InfoMessages);
                    Assert.Contains("EF Plugin: Added record to migration mapping history", Result.InfoMessages);
                }
                public void EnsuresMigrationRecordExistsForNewVersion(DbAuthType authType, string connString)
                {
                    TestConstants.ConfigureRequest(Request, authType);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    MigratorFactory.Verify(m => m.CreateDbContext(connString), Times.Once);
                    Repo.Verify(m => m.AddOrUpdate(TestConstants.VerAlias, lastMigration), Times.Once);
                    Context.Verify(m => m.SaveChanges());
                }
示例#9
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);
            }
示例#10
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);
            }
                public void MovesMigrationForward(DbAuthType authType, string connString)
                {
                    TestConstants.ConfigureRequest(Request, authType);
                    MigratorFactory.Setup(m => m.CreateMigrator(connString)).Returns(Migrator.Object);

                    var underTest = new UpdateMigrationAction(MigratorFactory.Object);

                    underTest.Migrate(Request, Result);

                    MigratorFactory.Verify(m => m.CreateDbContext(connString), Times.Once);
                    MigratorFactory.Verify(m => m.CreateMigrationRepository(Context.Object), Times.Once);
                    Repo.Verify(m => m.Copy(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
                    Repo.Verify(m => m.Copy(TestConstants.PreviousVersion, TestConstants.VerAlias), Times.Once);
                    Migrator.Verify(m => m.GetLocalMigrations(), Times.Once);
                }
示例#12
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"));
            }
示例#13
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);
            }