public void RunMigrations(List<ModuleDescriptor> descriptors, IVersionChecker versionChecker = null)
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var assemblyLoader = container.Resolve<IAssemblyLoader>();

                if (versionChecker == null)
                {
                    var mock = new Mock<IVersionChecker>();
                    mock
                        .Setup(vc => vc.VersionExists(It.IsAny<string>(), It.IsAny<long>()))
                        .Returns<string, long>((s, l) => false);
                    versionChecker = mock.Object;
                }

                var configuration = new Mock<IConfiguration>();
                configuration
                    .Setup(c => c.Database)
                    .Returns(() => new DatabaseConfigurationElement
                    {
                        ConnectionString = connectionString
                    });

                var migrationRunner = new DefaultMigrationRunner(assemblyLoader, configuration.Object, versionChecker);
                migrationRunner.MigrateStructure(descriptors);
            }
        }
Beispiel #2
0
        private static void Migrate()
        {
            ICmsConfigurationLoader configurationLoader = new CmsConfigurationLoader();
            ICmsConfiguration cmsConfiguration = configurationLoader.LoadCmsConfiguration();

            var builder = ApplicationContext.InitializeContainer(null, cmsConfiguration);
            builder.RegisterInstance(cmsConfiguration)
                    .As<IConfiguration>()
                    .As<IWebConfiguration>()
                    .As<ICmsConfiguration>()
                    .SingleInstance();
            ContextScopeProvider.RegisterTypes(builder);
            ApplicationContext.LoadAssemblies();

            IVersionChecker versionChecker = new VersionCheckerStub();
            DefaultMigrationRunner runner = new DefaultMigrationRunner(new DefaultAssemblyLoader(), cmsConfiguration, versionChecker);
            runner.MigrateStructure(descriptors.Cast<ModuleDescriptor>().ToList());
        }