public void VersionDescriptionMigrationOnlyRunOnceEvenIfExistenceChecksReturnFalse() { var conventions = new MigrationConventions(); var processor = new Mock <IMigrationProcessor>(); var runner = new Mock <IMigrationRunner>(); var asm = Assembly.GetExecutingAssembly(); runner.SetupGet(r => r.Processor).Returns(processor.Object); processor.Setup(p => p.ColumnExists(new TestVersionTableMetaData().SchemaName, TestVersionTableMetaData.TABLENAME, "AppliedOn")).Returns(false); var loader = new VersionLoader(runner.Object, asm, conventions); loader.LoadVersionInfo(); runner.Verify(r => r.Up(loader.VersionDescriptionMigration), Times.Once()); }
public void VersionSchemaMigrationOnlyRunOnceEvenIfExistenceChecksReturnFalse() { var conventions = new MigrationConventions(); var processor = new Mock <IMigrationProcessor>(); var runner = new Mock <IMigrationRunner>(); var asm = Assembly.GetExecutingAssembly(); runner.SetupGet(r => r.Processor).Returns(processor.Object); processor.Setup(p => p.SchemaExists(It.IsAny <string>())).Returns(false); var loader = new VersionLoader(runner.Object, asm, conventions); loader.LoadVersionInfo(); runner.Verify(r => r.Up(loader.VersionSchemaMigration), Times.Once()); }
public void VersionUniqueMigrationOnlyRunOnceEvenIfExistenceChecksReturnFalse() { var runnerContext = new Mock <IRunnerContext>(); var conventions = new MigrationRunnerConventions(); var processor = new Mock <IMigrationProcessor>(); var runner = new Mock <IMigrationRunner>(); var asm = Assembly.GetExecutingAssembly(); runner.SetupGet(r => r.Processor).Returns(processor.Object); runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object); processor.Setup(p => p.ColumnExists(new TestVersionTableMetaData().SchemaName, TestVersionTableMetaData.TABLE_NAME, TestVersionTableMetaData.APPLIED_ON_COLUMN_NAME)).Returns(false); var loader = new VersionLoader(runner.Object, asm, ConventionSets.NoSchemaName, conventions, runnerContext.Object); loader.LoadVersionInfo(); runner.Verify(r => r.Up(loader.VersionUniqueMigration), Times.Once()); }
public new void MigrateUp(long targetVersion, bool useAutomaticTransactionManagement) { VersionLoader.LoadVersionInfo(); var validationVersionLoader = VersionLoader as ValidatingVersionLoader; if (validationVersionLoader == null) { throw new ArgumentException( string.Format("Class of type {0} is required, {1} given", typeof(ValidatingVersionLoader).FullName, VersionLoader.GetType().FullName ) ); } var storedMigrationInfos = validationVersionLoader.StoredMigrationInfos; var availableMigrations = MigrationLoader.LoadMigrations().ToList().ToDictionary(x => x.Key, x => x.Value); FilterAndValidateMigrations(storedMigrationInfos, availableMigrations); ValidateEnvironmentAttributeUsage(availableMigrations); base.MigrateUp(targetVersion, useAutomaticTransactionManagement); }
public void CheskForNotAppliedMigrations() { this.Initialize(); try { var versionLoader = new VersionLoader(this.Runner, this.Runner.MigrationAssemblies, ((MigrationRunner)this.Runner).Conventions); versionLoader.LoadVersionInfo(); var migrationsToRun = (from m in this.Runner.MigrationLoader.LoadMigrations() where !versionLoader.VersionInfo.HasAppliedMigration(m.Key) select m).ToList(); if (migrationsToRun.Any()) { var text = $"Необходимо выполнить миграции:{Environment.NewLine}"; text = migrationsToRun.Aggregate(text, (current, keyValuePair) => current + $"{keyValuePair.Value.GetName()}{Environment.NewLine}"); throw new Exception(text); } } finally { this.Runner.Processor.Dispose(); } }