public void TestFailedMigrationBroadcast()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            MigrationTask2 task = new MigrationTask2();

            task.ForceFail = true;
            process.MigrationStarted +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationStarted);
            process.MigrationSuccessful +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationSuccessful);
            process.MigrationFailed +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationFailed);

            try
            {
                process.ApplyPatch(context, task, true);
            }
            catch (MigrationException me)
            {
                Assert.IsTrue(started, "'started' should be true");
                Assert.IsFalse(succeeded, "'succeeded' should be false");
                Assert.IsTrue(failed, "'failed' should be true");
                throw me;
            }
        }
        public void DoMigrationsFromLevelOne()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            //process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.CodeBase);
            process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.Location);
            process.DoMigrations(1, context);

            Assert.IsFalse(context.HasExecuted(new MigrationTask1().Name), "MigrationTask1 was not supposed to be run");
            Assert.IsTrue(context.HasExecuted(new MigrationTask2().Name), "MigrationTask2 was supposed to be run");
        }
        public void DoMigrationsFromLevelOneHundred()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            //process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.CodeBase);
            process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.Location);
            int count = process.DoMigrations(100, context);

            Assert.IsTrue(0 == count, "No migration tasks were supposed to be run on an up-to-date system");
            Assert.IsFalse(context.HasExecuted(new MigrationTask1().Name), "MigrationTask1 was not supposed to be run");
            Assert.IsFalse(context.HasExecuted(new MigrationTask2().Name), "MigrationTask2 was not supposed to be run");
        }
        public void DoMigrationsFromLevelOneHundredReadOnly()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            //process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.CodeBase);
            process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.Location);
            process.ReadOnly = true;
            int count = process.DoMigrations(100, context);

            Assert.AreEqual(0, count, "No migration tasks were supposed to be run on an up-to-date system in readonly mode");
            Assert.AreEqual(0, context.ExecutionLog.Count, "The execution log should not have recorded anything in readonly mode");
        }
 public void AddNullMigrationTaskSource()
 {
     MigrationProcess process = new MigrationProcess();
     process.AddMigrationTaskSource(null);
 }
        public void ValidateTasksTwoSameLevels()
        {
            IList<IMigrationTask> migrations = new List<IMigrationTask>();
            MigrationTask1 task1 = new MigrationTask1();
            task1.Level = 1;
            MigrationTask2 task2 = new MigrationTask2();
            task2.Level = 1;

            migrations.Add(task1);
            migrations.Add(task2);

            try
            {
                MigrationProcess process = new MigrationProcess();
                process.ValidateTasks(migrations);
            }
            catch (MigrationException me)
            {
                Assert.AreEqual(me.Message, "Migration task '" + task2.Name + " ["
                    + typeof(MigrationTask2).FullName + "]' has a conflicting patch level with '"
                    + task1.Name + " [" + typeof(MigrationTask1).FullName
                    + "]'; both are configured for patch level 1");
                throw me;
            }
        }
        public void ValidateTasksSuccessful()
        {
            IList<IMigrationTask> migrations = new List<IMigrationTask>();
            MigrationTask1 task1 = new MigrationTask1();
            MigrationTask2 task2 = new MigrationTask2();

            migrations.Add(task1);
            migrations.Add(task2);

            try
            {
                MigrationProcess process = new MigrationProcess();
                process.ValidateTasks(migrations);
            }
            catch (MigrationException)
            {
                Assert.Fail("We should not have got an exception");
            }
        }
        public void ValidateTasksNoLevelSet()
        {
            IList<IMigrationTask> migrations = new List<IMigrationTask>();
            MigrationTask1 task = new MigrationTask1();
            task.Level = null;
            migrations.Add(task);

            try
            {
                MigrationProcess process = new MigrationProcess();
                process.ValidateTasks(migrations);
            }
            catch (MigrationException me)
            {
                Assert.AreEqual(me.Message, "Migration task '" + task.Name + " ["
                    + typeof(MigrationTask1).FullName + "]' does not have a patch level defined.");
                throw me;
            }
        }
        public void DoMigrationsFromLevelOneReadOnly()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            //process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.CodeBase);
            process.AddPatchResourceAssembly(typeof(MigrationTask1).Assembly.Location);
            process.ReadOnly = true;

            int count = -1;

            try
            {
                count = process.DoMigrations(1, context);
            }
            catch (MigrationException me)
            {
                Assert.AreEqual(-1, count, "No migration tasks were supposed to be run in readonly mode");
                Assert.AreEqual(0, context.ExecutionLog.Count, "The execution log should not have recorded anything in readonly mode");
                throw me;
            }
        }
        public void TestNoBroadcast()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            MigrationTask1 task = new MigrationTask1();

            process.MigrationStarted +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationStarted);
            process.MigrationSuccessful +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationSuccessful);
            process.MigrationFailed +=
                new MigrationProcess.MigrationStatusEventHandler(process_MigrationFailed);
            process.ApplyPatch(context, task, false);

            Assert.IsFalse(started, "'started' should be false");
            Assert.IsFalse(succeeded, "'succeeded' should be false");
            Assert.IsFalse(failed, "'failed' should be false");
        }
        public void TestNoListeners()
        {
            TestMigrationContext context = new TestMigrationContext();
            MigrationProcess process = new MigrationProcess();
            MigrationTask1 task = new MigrationTask1();

            process.ApplyPatch(context, task, true);

            Assert.IsFalse(started, "'started' should be false");
            Assert.IsFalse(succeeded, "'succeeded' should be false");
            Assert.IsFalse(failed, "'failed' should be false");
        }