Beispiel #1
0
        public void Should_Return_Runable_Plugins_In_Reverse_Order_When_Rolling_Back()
        {
            IJob job = new Job(DTO.JobData);
            var errorPlugin = new TestPlugin(true,false,false);
            var hasFailed = false;

            job[job.Count - 1].Clear();
            job[job.Count - 1].Add(errorPlugin); //Error plugin added to the end

            job.JobExecuteFailed += (sender, eventArgs) => hasFailed = true;

            foreach (IPlugin plugin in job.GetAllPlugins())
            {
                plugin.BeginExecute();
            }

            Timing.WaitUntil(() => hasFailed, 2000);

            IList<IPlugin> plugins = job.GetRunablePlugins().ToList();

            Assert.AreEqual(JobCommand.Rollback, job.CurrentCommand);
            Assert.AreEqual(plugins.First(), errorPlugin);
            Assert.AreEqual(1, plugins.Count);

            foreach (var list in plugins)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins2 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(7, plugins2.Count);

            foreach (IPlugin list in plugins2)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins3 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(1, plugins3.Count);

            foreach (IPlugin list in plugins3)
            {
                list.BeginRollback();
            }

            IList<IPlugin> plugins4 = job.GetRunablePlugins().ToList();

            Assert.AreEqual(2, plugins4.Count);

            Assert.IsTrue(hasFailed);
        }