Inheritance: IMigrationBatch
Example #1
0
        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);
        }
        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);
        }
Example #3
0
        /// <summary>
        /// Alters the database schema by applying the specified migration. Versioning is unaffected by this operation and any timestamp information on the <paramref name="migration"/> is disregarded.
        /// </summary>
        public void Alter(IMigration migration)
        {
            if (migration is IReversibleMigration)
            {
                Log.Info(LogCategory.General, "Migrations used to modify the database schema directly cannot be reversed.");
            }

            var migrationMetadata = new MigrationMetadata(0, "Bypass", "This migration is being executed without affecting the versioning.");
            var stepMetadata = new MigrationStepMetadata(MigrationDirection.Up, false, new[] { migrationMetadata });
            var batch = new MigrationBatch(new[]
            {
                new MigrationStep(migration, stepMetadata)
            }, Enumerable.Empty<IMigrationMetadata>(), new NoVersioning(), Configuration);
            batch.Execute();
        }
Example #4
0
        public void VerifyValidationErrorsResultInException()
        {
            string errors;
            string warnings;
            var validator = A.Fake<IValidator>();
            A.CallTo(() => validator.Validate(A<IEnumerable<IMigrationReporter>>._, out errors, out warnings)).AssignsOutAndRefParameters("Some test failure...", null);

            IMigrationStep[] steps = { FakeMigrationStep(new StepMetadataStub(new MigrationMetadata(1, null, null))) };
            var configuration = A.Fake<IRuntimeConfiguration>();
            A.CallTo(() => configuration.Validator).Returns(validator);
            MigrationBatch batch = new MigrationBatch(steps, Enumerable.Empty<IMigrationMetadata>(), A.Fake<IVersioning>(), configuration);

            batch.Execute();
            Assert.IsTrue(batch.IsExecuted);
        }
        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);
        }
Example #6
0
 public void VerifyCallingExecuteTwiceThrows()
 {
     var batch = new MigrationBatch(Enumerable.Empty<IMigrationStep>(), Enumerable.Empty<IMigrationMetadata>(), A.Fake<IVersioning>(), A.Fake<IRuntimeConfiguration>());
     batch.Execute();
     batch.Execute();
 }
 public void VerifyCallingExecuteTwiceThrows()
 {
     var batch = new MigrationBatch(Enumerable.Empty<IMigrationStep>(), Enumerable.Empty<IMigrationMetadata>(), MockRepository.GenerateStub<IVersioning>(), new MigrationOptions());
     batch.Execute();
     batch.Execute();
 }