示例#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()
        {
            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);
        }