public void VerifyStepExecutedAndStepExecutingAreRaised()
        {
            var            metadata = new StepMetadataStub(new MigrationMetadata(1, null, null));
            IMigrationStep step     = FakeMigrationStep(metadata);

            IMigrationStep[] steps = { step };
            var batch = new MigrationBatch(steps, Enumerable.Empty <IMigrationMetadata>(), A.Fake <IVersioning>(), A.Fake <IRuntimeConfiguration>());

            Assert.AreSame(metadata, batch.Steps[0], "The batch should expose the metadata of the step."); // this is tested to allow for the undocumented feature test below

            int countExecutingEvent = 0;
            int countExecutedEvent  = 0;

            batch.StepExecuting += (sender, args) =>
            {
                // note: the following assertion tests an undocumented feature
                Assert.AreSame(metadata, args.Metadata, "The event should carry the same metadata that is in the ScheduleMigrations collection.");
                countExecutingEvent++;
            };
            batch.StepExecuted += (sender, args) =>
            {
                // note: the following assertion tests an undocumented feature
                Assert.AreSame(metadata, args.Metadata, "The event should carry the same metadata that is in the ScheduleMigrations collection.");
                countExecutedEvent++;
            };

            batch.Execute();

            Assert.IsTrue(batch.IsExecuted);
            Assert.AreEqual(steps.Length, countExecutingEvent);
            Assert.AreEqual(steps.Length, countExecutedEvent);
        }
        private static IMigrationStep FakeMigrationStep(IMigrationStepMetadata metadata)
        {
            IMigrationStep step = A.Fake <IMigrationStep>();

            A.CallTo(() => step.Metadata).Returns(metadata);
            A.CallTo(() => step.Report(A <IMigrationContext> ._)).Returns(A.Fake <IMigrationReport>());
            return(step);
        }
示例#3
0
        private void ExecuteStep(IMigrationStep step)
        {
            OnStepExecuting(new MigrationEventArgs(step.Metadata));

            step.Execute(_configuration, _versioning);

            OnStepExecuted(new MigrationEventArgs(step.Metadata));
        }
示例#4
0
        private void ExecuteStep(IMigrationStep step)
        {
            OnStepExecuting(new MigrationEventArgs(step.Metadata, step.Direction));

            step.Execute(_versioning);

            OnStepExecuted(new MigrationEventArgs(step.Metadata, step.Direction));
        }
示例#5
0
        public void Execute(ICommandContext context)
        {
            ILogger            logger         = context.Container.Resolve <ILogger>();
            IRuntime           runtime        = context.Container.Resolve <IRuntime>();
            IEnumerable <Type> migrationSteps = GetType().Assembly.FindTypes <IMigrationStep>();

            string parentPath = Directory.GetParent(runtime.WorkingDirectory).FullName;
            string basePath   = Path.Combine(parentPath, "Rocket.old");

            basePath = Path.GetFullPath(basePath);

            if (!Directory.Exists(basePath))
            {
                context.User.SendMessage($"Migration failed: Path \"{basePath}\" does not exist.", Color.Red);
                return;
            }

            string targetStep = context.Parameters.Get <string>(0, null);

            foreach (Type migrationStep in migrationSteps)
            {
                IMigrationStep step = (IMigrationStep)Activator.CreateInstance(migrationStep);

                if (targetStep != null && !step.Name.Equals(targetStep, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                logger.LogInformation($"Executing migration step \"{step.Name}\".");

                if (Debugger.IsAttached)
                {
                    step.Migrate(context.Container, basePath);
                }
                else
                {
                    try
                    {
                        step.Migrate(context.Container, basePath);
                    }
                    catch (Exception e)
                    {
                        logger.LogError($"Failed at migration step \"{step.Name}\": ", e);
                        logger.LogWarning($"Use \"{context.CommandPrefix}{Name} {step.Name}\" to retry.");
                    }
                }
            }

            logger.LogInformation("Legacy migration done.", Color.DarkGreen);
        }
示例#6
0
        public void VerifyValidationErrorsResultInException()
        {
            IMigrationStep step = MockRepository.GenerateStub <IMigrationStep>();

            step.Expect(s => s.Metadata).Return(new Metadata1());
            IMigrationReport erroneousReport = CreateMigrationReport();

            erroneousReport.Expect(r => r.Error).Return("Some test failure...");
            step.Expect(s => s.Report(null)).IgnoreArguments().Return(erroneousReport);
            IMigrationStep[] steps = new[]
            {
                step,
            };
            IVersioning    versioning = MockRepository.GenerateStub <IVersioning>();
            MigrationBatch batch      = new MigrationBatch(steps, Enumerable.Empty <IMigrationMetadata>(), versioning, new MigrationOptions());

            batch.Execute();
            Assert.IsTrue(batch.IsExecuted);
        }
示例#7
0
        public void VerifyStepExecutedAndStepExecutingAreRaised()
        {
            IMigrationStep step     = MockRepository.GenerateStub <IMigrationStep>();
            var            metadata = new Metadata1();

            step.Expect(s => s.Metadata).Return(metadata);
            step.Expect(s => s.Report(null)).IgnoreArguments().Return(CreateMigrationReport());
            IMigrationStep[] steps = new[]
            {
                step,
            };
            IVersioning versioning = MockRepository.GenerateStub <IVersioning>();
            var         batch      = new MigrationBatch(steps, Enumerable.Empty <IMigrationMetadata>(), versioning, new MigrationOptions());

            Assert.AreSame(metadata, batch.ScheduledMigrations[0], "The batch should expose the metadata of the step."); // this is tested to allow for the undocumented feature test below
            int countExecutingEvent = 0;
            int countExecutedEvent  = 0;

            batch.StepExecuting += (sender, args) =>
            {
                // note: the following assertion tests an undocumented feature
                Assert.AreSame(metadata, args.Metadata, "The event should carry the same metadata that is in the ScheduleMigrations collection.");
                countExecutingEvent++;
            };
            batch.StepExecuted += (sender, args) =>
            {
                // note: the following assertion tests an undocumented feature
                Assert.AreSame(metadata, args.Metadata, "The event should carry the same metadata that is in the ScheduleMigrations collection.");
                countExecutedEvent++;
            };

            batch.Execute();

            Assert.IsTrue(batch.IsExecuted);
            Assert.AreEqual(steps.Length, countExecutingEvent);
            Assert.AreEqual(steps.Length, countExecutedEvent);
        }
示例#8
0
 public MigrationItem(Version version, IMigrationStep step)
 {
     Version = version;
     Step    = step;
 }
示例#9
0
        private void ExecuteStep(IMigrationStep step)
        {
            OnStepExecuting(new MigrationEventArgs(step.Metadata));

            step.Execute(_configuration, _versioning);

            OnStepExecuted(new MigrationEventArgs(step.Metadata));
        }