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 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 DefaultBehaviorIsToNotLoadNestedNamespaces() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Integration.Migrations.Nested", null); loader.LoadNestedNamespaces.ShouldBe(false); }
public void CanFindMigrationsInNamespace() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass1", null); var migrationList = loader.LoadMigrations(); migrationList.Select(x => x.Value.Migration.GetType()).ShouldNotContain(typeof(VersionedMigration)); migrationList.Count().ShouldBeGreaterThan(0); }
public void CanFindMigrationsInAssembly() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader( conventions, asm, "FluentMigrator.Tests.Integration.Migrations.Interleaved.Pass1", null); SortedList<long, IMigrationInfo> migrationList = loader.LoadMigrations(); //if this works, there will be at least one migration class because i've included on in this code file var en = migrationList.GetEnumerator(); int count = 0; while (en.MoveNext()) count++; count.ShouldBeGreaterThan(0); }
public MigrationRunner( [NotNull] IAssemblyCollection assemblies, [NotNull] IRunnerContext runnerContext, [NotNull] IMigrationProcessor processor, [CanBeNull] IVersionTableMetaData versionTableMetaData, [CanBeNull] IMigrationRunnerConventions migrationRunnerConventions, [CanBeNull] IConventionSet conventionSet, [CanBeNull] IMigrationScopeManager migrationScopeHandler = null) { _migrationAssemblies = assemblies; _logger = new AnnouncerFluentMigratorLogger(runnerContext.Announcer); _stopWatch = runnerContext.StopWatch; _processorOptions = new ProcessorOptions(runnerContext); Processor = processor; RunnerContext = runnerContext; var migrationRunnerConventionsAccessor = new AssemblySourceMigrationRunnerConventionsAccessor( serviceProvider: null, new AssemblySource(() => assemblies)); Conventions = migrationRunnerConventions ?? migrationRunnerConventionsAccessor.MigrationRunnerConventions; var convSet = conventionSet ?? new DefaultConventionSet(runnerContext); _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor); _migrationValidator = new MigrationValidator(_logger, 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 Lazy <IVersionLoader>( () => new ConnectionlessVersionLoader( this, _migrationAssemblies, convSet, Conventions, runnerContext, versionTableMetaData)); } else { _versionLoader = new Lazy <IVersionLoader>( () => new VersionLoader(this, _migrationAssemblies, convSet, Conventions, runnerContext, versionTableMetaData)); } }
public void FindsMigrationsInNestedNamespaceWhenLoadNestedNamespacesEnabled() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Integration.Migrations.Nested", true, null); List<Type> expected = new List<Type> { typeof(Integration.Migrations.Nested.NotGrouped), typeof(Integration.Migrations.Nested.Group1.FromGroup1), typeof(Integration.Migrations.Nested.Group1.AnotherFromGroup1), typeof(Integration.Migrations.Nested.Group2.FromGroup2), }; var migrationList = loader.LoadMigrations(); List<Type> actual = migrationList.Select(m => m.Value.Migration.GetType()).ToList(); CollectionAssert.AreEquivalent(expected, actual); }
public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor) { _migrationAssembly = assembly; _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, _migrationAssembly, Conventions); MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, 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; 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 DoesFindMigrationsThatHaveMatchingTags() { var asm = Assembly.GetExecutingAssembly(); var migrationType = typeof(TaggedMigraion); var tagsToMatch = new[] { "UK", "Production" }; var conventionsMock = new Mock<IMigrationConventions>(); conventionsMock.SetupGet(m => m.GetMigrationInfo).Returns(DefaultMigrationConventions.GetMigrationInfoFor); conventionsMock.SetupGet(m => m.TypeIsMigration).Returns(t => true); conventionsMock.SetupGet(m => m.TypeHasTags).Returns(t => migrationType == t); conventionsMock.SetupGet(m => m.TypeHasMatchingTags).Returns((type, tags) => (migrationType == type && tagsToMatch == tags)); var loader = new DefaultMigrationInformationLoader(conventionsMock.Object, asm, migrationType.Namespace, tagsToMatch); var expected = new List<Type> { typeof(UntaggedMigration), migrationType }; var actual = loader.LoadMigrations().Select(m => m.Value.Migration.GetType()).ToList(); CollectionAssert.AreEquivalent(expected, actual); }
public void ShouldThrowExceptionIfDuplicateVersionNumbersAreLoaded() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var migrationLoader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Unit.DuplicateVersionNumbers", null); Assert.Throws<DuplicateMigrationException>(() => migrationLoader.LoadMigrations()); }
public void ShouldHandleTransactionlessMigrations() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Unit.DoesHandleTransactionLessMigrations", null); var list = loader.LoadMigrations().ToList(); list.Count().ShouldBe(2); list[0].Value.Migration.GetType().ShouldBe(typeof(DoesHandleTransactionLessMigrations.MigrationThatIsTransactionLess)); list[0].Value.TransactionBehavior.ShouldBe(TransactionBehavior.None); list[0].Value.Version.ShouldBe(1); list[1].Value.Migration.GetType().ShouldBe(typeof(DoesHandleTransactionLessMigrations.MigrationThatIsNotTransactionLess)); list[1].Value.TransactionBehavior.ShouldBe(TransactionBehavior.Default); list[1].Value.Version.ShouldBe(2); }
public void HandlesNotFindingMigrations() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Unit.EmptyNamespace", null); var list = loader.LoadMigrations(); Assert.That(list, Is.Not.Null); Assert.That(list.Count(), Is.EqualTo(0)); }
public void HandlesMigrationThatDoesNotInheritFromMigrationBaseClass() { var conventions = new MigrationConventions(); var asm = Assembly.GetExecutingAssembly(); var loader = new DefaultMigrationInformationLoader(conventions, asm, "FluentMigrator.Tests.Unit.DoesNotInheritFromBaseClass", null); Assert.That(loader.LoadMigrations().Count(), Is.EqualTo(1)); }