public void SetsDataSource(DbAuthType authType)
        {
            var request    = BuildRequest(authType);
            var connString = request.GetConnectionString();

            Assert.Equal(DataSource, new SqlConnectionStringBuilder(connString).DataSource);
        }
Пример #2
0
        public static PersistenceMigratorRequest BuildRequest(DbAuthType authType)
        {
            var request = new PersistenceMigratorRequest();

            ConfigureRequest(request, authType);
            return(request);
        }
        public void SetsInitialCatalog(DbAuthType authType)
        {
            var request    = BuildRequest(authType);
            var connString = request.GetConnectionString();

            Assert.Equal(InitialCatalog, new SqlConnectionStringBuilder(connString).InitialCatalog);
        }
        public void SetsApplicationName(DbAuthType authType)
        {
            var request    = BuildRequest(authType);
            var connString = request.GetConnectionString();

            Assert.Equal($"{AppAlias}-{VerAlias}", new SqlConnectionStringBuilder(connString).ApplicationName);
        }
Пример #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);
            }
Пример #6
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);
            }
                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);
                }
Пример #8
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);
            }
Пример #9
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 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 SetsSecurityFields(DbAuthType authType, bool integratedSecurity, string userId, string password)
        {
            var request    = BuildRequest(authType);
            var connString = request.GetConnectionString();

            var b = new SqlConnectionStringBuilder(connString);

            Assert.Equal(integratedSecurity, b.IntegratedSecurity);
            Assert.Equal(userId, b.UserID);
            Assert.Equal(password, b.Password);
        }
                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 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());
                }
Пример #15
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);
            }
Пример #16
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);
            }
 private PersistenceMigratorRequest BuildRequest(DbAuthType authType)
 {
     return(new PersistenceMigratorRequest
     {
         Application = new NameAlias {
             Alias = AppAlias
         },
         Version = new VersionInfo {
             Alias = VerAlias
         },
         ConnectionInformation = new ConnectionInformation {
             AuthenticationType = authType, Server = DataSource, DatabaseName = InitialCatalog, Password = Password, Username = UserId, Type = DbType.SqlServer
         }
     });
 }
                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);
                }
Пример #19
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"));
            }
Пример #20
0
 public static void ConfigureRequest(PersistenceMigratorRequest request, DbAuthType authType)
 {
     request.Application = new NameAlias {
         Alias = AppAlias
     };
     request.Version = new VersionInfo {
         Alias = VerAlias
     };
     request.ConnectionInformation = new ConnectionInformation
     {
         AuthenticationType = authType,
         DatabaseName       = DbName,
         Server             = ServerName,
         Username           = Username,
         Password           = Password,
     };
     request.PreviousVersion = new VersionInfo {
         Alias = PreviousVersion
     };
 }
Пример #21
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);
            }