public void DeleteVersionShouldExecuteDeleteDataExpression() { var processor = new Mock<IMigrationProcessor>(); var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor).Returns(processor.Object); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); Func<IDataDefinition, bool> predicate = definition => { if (definition is ExplicitDataDefinition) { IDataValue kvp = ((ExplicitDataDefinition)definition).Data.First(); return kvp.ColumnName == loader.VersionTableMetaData.ColumnName && kvp.Value.Equals(1L); } else { return false; } }; processor.Setup(p => p.Process(It.Is<DeleteDataExpression>(expression => expression.SchemaName == loader.VersionTableMetaData.SchemaName && expression.TableName == loader.VersionTableMetaData.TableName && expression.Rows.All(predicate)))).Verifiable(); loader.DeleteVersion(1); processor.VerifyAll(); }
public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssemblies = assemblies; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; ApplicationContext = runnerContext.ApplicationContext; TransactionPerSession = runnerContext.TransactionPerSession; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) { Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; } _migrationScopeHandler = new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_announcer, Conventions); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions); if (runnerContext.NoConnection) { VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version); } else { VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions); } }
public void DeleteVersionShouldExecuteDeleteDataExpression() { var processor = new Mock<IMigrationProcessor>(); var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor).Returns(processor.Object); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); processor.Setup(p => p.Process(It.Is<DeleteDataExpression>(expression => expression.SchemaName == loader.VersionTableMetaData.SchemaName && expression.TableName == loader.VersionTableMetaData.TableName && expression.Rows.All( definition => definition.All( pair => pair.Key == loader.VersionTableMetaData.ColumnName && pair.Value.Equals(1L)))))) .Verifiable(); loader.DeleteVersion(1); processor.VerifyAll(); }
public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssemblies = assemblies; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; RunnerContext = runnerContext; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; _migrationScopeHandler = new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_announcer, Conventions); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions); if (runnerContext.NoConnection){ VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version); } else{ VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions); } }
public void CanLoadCustomVersionTableMetaData() { var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor.Options).Returns(new TestMigrationProcessorOptions()); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); var versionTableMetaData = loader.GetVersionTableMetaData(); versionTableMetaData.ShouldBeOfType<TestVersionTableMetaData>(); }
public void CanLoadDefaultVersionTableMetaData() { var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r=>r.Processor.Options).Returns(new TestMigrationProcessorOptions()); var conventions = new MigrationConventions(); var asm = "s".GetType().Assembly; var loader = new VersionLoader(runner.Object, asm, conventions); var versionTableMetaData = loader.GetVersionTableMetaData(); versionTableMetaData.ShouldBeOfType<DefaultVersionTableMetaData>(); }
public void CanSetupApplicationContext() { var applicationContext = "Test context"; var runnerContext = new Mock<IRunnerContext>(); runnerContext.SetupGet(r => r.ApplicationContext).Returns(applicationContext); var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor.Options).Returns(new TestMigrationProcessorOptions()); runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); var versionTableMetaData = loader.GetVersionTableMetaData(); versionTableMetaData.ApplicationContext.ShouldBe(applicationContext); }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssembly = assembly; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions); MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
public MigrationRunner(ICollection<MigrationAssemblyInfo> assemblyInfos, IRunnerContext runnerContext, IMigrationProcessor processor, bool loadNestedNamespaces) { _migrationAssemblies = assemblyInfos; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; ApplicationContext = runnerContext.ApplicationContext; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; VersionLoader = new VersionLoader(this, assemblyInfos, Conventions); MigrationLoader = new MigrationLoader(Conventions, assemblyInfos, loadNestedNamespaces , runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssembly = assembly; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) { Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; } VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions); MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssembly = assembly; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); ProcessWorkingDirectory(runnerContext); ProcessAutoReverse(runnerContext); VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions); MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssembly = assembly; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; ApplicationContext = runnerContext.ApplicationContext; TransactionPerSession = runnerContext.TransactionPerSession; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; _migrationScopeHandler = new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_announcer, Conventions); VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
public MigrationRunner( IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData, IMigrationRunnerConventions migrationRunnerConventions, IConventionSet conventionSet) { _migrationAssemblies = assemblies; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; RunnerContext = runnerContext; SilentlyFail = false; CaughtExceptions = null; Conventions = migrationRunnerConventions ?? GetMigrationRunnerConventions(runnerContext); var convSet = conventionSet ?? new DefaultConventionSet(runnerContext); _migrationScopeHandler = new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_announcer, convSet); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions); if (runnerContext.NoConnection) { VersionLoader = new ConnectionlessVersionLoader( this, _migrationAssemblies, convSet, Conventions, runnerContext.StartVersion, runnerContext.Version, versionTableMetaData); } else { VersionLoader = new VersionLoader(this, _migrationAssemblies, convSet, Conventions, versionTableMetaData); } }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData = null) { _migrationAssembly = assembly; _announcer = runnerContext.Announcer; Processor = processor; _stopWatch = runnerContext.StopWatch; ApplicationContext = runnerContext.ApplicationContext; TransactionPerSession = runnerContext.TransactionPerSession; SilentlyFail = false; CaughtExceptions = null; Conventions = new MigrationConventions(); if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory)) { Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory; } _migrationScopeHandler = new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_announcer, Conventions); VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions, versionTableMetaData); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags); ProfileLoader = new ProfileLoader(runnerContext, this, Conventions); }
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 RemoveVersionTableShouldNotRemoveSchemaIfItDidNotOwnTheSchema() { var processor = new Mock<IMigrationProcessor>(); var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor).Returns(processor.Object); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); ((TestVersionTableMetaData) loader.VersionTableMetaData).OwnsSchema = false; processor.Setup(p => p.Process(It.Is<DeleteTableExpression>(expression => expression.SchemaName == loader.VersionTableMetaData.SchemaName && expression.TableName == loader.VersionTableMetaData.TableName))) .Verifiable(); loader.RemoveVersionTable(); processor.Verify(p => p.Process(It.IsAny<DeleteSchemaExpression>()), Times.Never()); }
public void RemoveVersionTableShouldBehaveAsExpected() { var processor = new Mock<IMigrationProcessor>(); var runner = new Mock<IMigrationRunner>(); runner.SetupGet(r => r.Processor).Returns(processor.Object); var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new VersionLoader(runner.Object, asm, conventions); processor.Setup(p => p.Process(It.Is<DeleteTableExpression>(expression => expression.SchemaName == loader.VersionTableMetaData.SchemaName && expression.TableName == loader.VersionTableMetaData.TableName))) .Verifiable(); processor.Setup(p => p.Process(It.Is<DeleteSchemaExpression>(expression => expression.SchemaName == loader.VersionTableMetaData.SchemaName))) .Verifiable(); loader.RemoveVersionTable(); processor.VerifyAll(); }
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()); }