Пример #1
0
        public void RemoveVersionTableShouldBehaveAsExpected()
        {
            var runnerContext = new Mock <IRunnerContext>();
            var processor     = new Mock <IMigrationProcessor>();
            var runner        = new Mock <IMigrationRunner>();

            runner.SetupGet(r => r.Processor).Returns(processor.Object);
            runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object);

            var conventions = new MigrationRunnerConventions();
            var asm         = Assembly.GetExecutingAssembly();
            var loader      = new VersionLoader(runner.Object, asm, ConventionSets.NoSchemaName, conventions, runnerContext.Object);

            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();
        }
Пример #2
0
        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();
        }
Пример #3
0
        public async Task <MVersionCollection> GetAllVersionsAsync()
        {
            Versions = await VersionLoader.GetVersionMetadatasAsync()
                       .ConfigureAwait(false);

            return(Versions);
        }
Пример #4
0
        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();
        }
Пример #5
0
        public void UpdateVersionShouldExecuteInsertDataExpression()
        {
            var runnerContext = new Mock <IRunnerContext>();
            var processor     = new Mock <IMigrationProcessor>();
            var runner        = new Mock <IMigrationRunner>();

            runner.SetupGet(r => r.Processor).Returns(processor.Object);
            runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object);

            var conventions = new MigrationRunnerConventions();
            var asm         = Assembly.GetExecutingAssembly();
            var loader      = new VersionLoader(runner.Object, asm, ConventionSets.NoSchemaName, conventions, runnerContext.Object);

            processor.Setup(p => p.Process(It.Is <InsertDataExpression>(expression =>
                                                                        expression.SchemaName == loader.VersionTableMetaData.SchemaName &&
                                                                        expression.TableName == loader.VersionTableMetaData.TableName &&
                                                                        expression.Rows.Any(
                                                                            definition =>
                                                                            definition.Any(
                                                                                pair =>
                                                                                pair.Key == loader.VersionTableMetaData.ColumnName && pair.Value.Equals(1L))))))
            .Verifiable();

            loader.UpdateVersionInfo(1);

            processor.VerifyAll();
        }
Пример #6
0
 void OnLocalVersionLoadFinish(VersionLoader loader)
 {
     localVersionLoader.OnLoadFinishHandler -= OnLocalVersionLoadFinish;
     bool same = localVersionLoader.version.Equals(serverVersionLoader.version);
     if (OnCheckVersionFinish != null) {
         OnCheckVersionFinish(same);
     }
 }
Пример #7
0
    void OnLocalVersionLoadFinish(VersionLoader loader)
    {
        localVersionLoader.OnLoadFinishHandler -= OnLocalVersionLoadFinish;
        bool same = localVersionLoader.version.Equals(serverVersionLoader.version);

        if (OnCheckVersionFinish != null)
        {
            OnCheckVersionFinish(same);
        }
    }
Пример #8
0
        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>();
        }
Пример #9
0
        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>();
        }
Пример #10
0
        public void CanLoadDefaultVersionTableMetaData()
        {
            var runnerContext = new Mock <IRunnerContext>();

            var runner = new Mock <IMigrationRunner>();

            runner.SetupGet(r => r.Processor.Options).Returns(new ProcessorOptions());
            runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object);

            var conventions = new MigrationRunnerConventions();
            var asm         = "s".GetType().Assembly;
            var loader      = new VersionLoader(runner.Object, asm, ConventionSets.NoSchemaName, conventions, runnerContext.Object);

            var versionTableMetaData = loader.GetVersionTableMetaData();

            versionTableMetaData.ShouldBeOfType <DefaultVersionTableMetaData>();
        }
Пример #11
0
        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());
        }
Пример #12
0
        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());
        }
Пример #13
0
        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());
        }
Пример #14
0
        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 ProcessorOptions());
            runner.SetupGet(r => r.RunnerContext).Returns(runnerContext.Object);

            var conventions = new MigrationRunnerConventions();
            var asm         = Assembly.GetExecutingAssembly();
            var loader      = new VersionLoader(runner.Object, asm, ConventionSets.NoSchemaName, conventions, runnerContext.Object);

            var versionTableMetaData = loader.GetVersionTableMetaData();

            versionTableMetaData.ApplicationContext.ShouldBe(applicationContext);
        }
Пример #15
0
        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 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);
        }
Пример #17
0
        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();
            }
        }
Пример #18
0
 void OnServerVersionLoadFinish(VersionLoader loader)
 {
     serverVersionLoader.OnLoadFinishHandler -= OnServerVersionLoadFinish;
     StartLocalVersionLoad();
 }
Пример #19
0
 void OnServerVersionLoadFinish(VersionLoader loader)
 {
     serverVersionLoader.OnLoadFinishHandler -= OnServerVersionLoadFinish;
     StartDownloadBunle();
 }
Пример #20
0
 void OnServerVersionLoadFinish(VersionLoader loader)
 {
     serverVersionLoader.OnLoadFinishHandler -= OnServerVersionLoadFinish;
     StartLocalVersionLoad ();
 }
Пример #21
0
 void OnServerVersionLoadFinish(VersionLoader loader)
 {
     serverVersionLoader.OnLoadFinishHandler -= OnServerVersionLoadFinish;
     StartDownloadBunle ();
 }
Пример #22
0
 public MVersionCollection GetAllVersions()
 {
     Versions = VersionLoader.GetVersionMetadatas();
     return(Versions);
 }