Exemple #1
0
        public void TestCronTriggerObjectWithListenerNames()
        {
            CronTriggerObject trigger = new CronTriggerObject();

            String[] names = new String[] { "test1", "test2" };
            trigger.TriggerListenerNames = (names);
            ArrayList result = new ArrayList(trigger.TriggerListenerNames);

            Assert.AreEqual(names, result);
        }
        private async Task DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob)
        {
            TestObject      tb         = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();

            jobDetail0.JobType    = typeof(IJob);
            jobDetail0.ObjectName = "myJob0";
            IDictionary jobData = new Hashtable();

            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = jobData;
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();

            trigger0.ObjectName           = "myTrigger0";
            trigger0.JobDetail            = jobDetail0;
            trigger0.CronExpressionString = "0/1 * * * * ?";
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.ObjectName = "myJob1";
            if (prototypeJob)
            {
                StaticListableObjectFactory objectFactory = new StaticListableObjectFactory();
                objectFactory.AddObject("task", task1);
                mijdfb.TargetObjectName = "task";
                mijdfb.ObjectFactory    = objectFactory;
            }
            else
            {
                mijdfb.TargetObject = task1;
            }
            mijdfb.TargetMethod = "doSomething";
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = "myTrigger1";
            trigger1.JobDetail      = jobDetail1;
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = A.Fake <IScheduler>();

            A.CallTo(() => scheduler.Context).Returns(new SchedulerContext());
            A.CallTo(() => scheduler.GetTrigger(A <TriggerKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(null));
            A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <IJobDetail>(null));

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = null;
            IDictionary schedulerContext = new Hashtable();

            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = schedulerContext;
            if (explicitJobDetail)
            {
                schedulerFactoryObject.JobDetails = new IJobDetail[] { jobDetail0 };
            }
            schedulerFactoryObject.Triggers = new ITrigger[] { trigger0, trigger1 };
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                await schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            A.CallTo(() => scheduler.ScheduleJob(trigger0, A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.ScheduleJob(trigger1, A <CancellationToken> ._)).MustHaveHappened();

            A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened();

            A.CallTo(() => scheduler.Start(A <CancellationToken> ._)).MustHaveHappened();
            A.CallTo(() => scheduler.Shutdown(false, A <CancellationToken> ._)).MustHaveHappened();
        }
        private async Task DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite)
        {
            TestObject      tb         = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();

            jobDetail0.JobType    = typeof(IJob);
            jobDetail0.ObjectName = "myJob0";
            IDictionary jobData = new Hashtable();

            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = jobData;
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();

            trigger0.ObjectName           = "myTrigger0";
            trigger0.JobDetail            = jobDetail0;
            trigger0.CronExpressionString = "0/1 * * * * ?";
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.ObjectName   = "myJob1";
            mijdfb.TargetObject = task1;
            mijdfb.TargetMethod = "doSomething";
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = "myTrigger1";
            trigger1.JobDetail      = jobDetail1;
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = A.Fake <IScheduler>();

            A.CallTo(() => scheduler.Context).Returns(new SchedulerContext());
            A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._, A <CancellationToken> ._)).Returns(Task.FromResult <IJobDetail>(null));
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(null));
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), A <CancellationToken> ._)).Returns(Task.FromResult <ITrigger>(new SimpleTriggerImpl()));
            if (overwrite)
            {
                await scheduler.AddJob(jobDetail1, true);

                A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1, A <CancellationToken> ._)).Returns(DateTime.UtcNow);
            }

            A.CallTo(() => scheduler.ScheduleJob(trigger0, A <CancellationToken> ._)).Throws(new ObjectAlreadyExistsException(""));

            if (overwrite)
            {
                A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0, A <CancellationToken> ._)).Returns(DateTime.UtcNow);
            }

            await scheduler.Start();

            await scheduler.Shutdown(false);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = null;
            IDictionary schedulerContext = new Hashtable();

            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = schedulerContext;
            schedulerFactoryObject.Triggers = new ITrigger[] { trigger0, trigger1 };
            if (overwrite)
            {
                schedulerFactoryObject.OverwriteExistingJobs = true;
            }
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                await schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            A.CallTo(() => scheduler.AddJob(jobDetail0, true, true, A <CancellationToken> ._)).MustHaveHappened();
        }
 public void SetUp()
 {
     cronTrigger            = new CronTriggerObject();
     cronTrigger.ObjectName = TRIGGER_NAME;
     Trigger = cronTrigger;
 }
 public void SetUp()
 {
     cronTrigger = new CronTriggerObject();
     cronTrigger.ObjectName = TRIGGER_NAME;
     Trigger = cronTrigger;
 }
        private void DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob)
        {
            TestObject      tb         = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();

            jobDetail0.JobType    = typeof(IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();

            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();

            trigger0.ObjectName           = ("myTrigger0");
            trigger0.JobDetail            = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.ObjectName = ("myJob1");
            if (prototypeJob)
            {
                StaticListableObjectFactory objectFactory = new StaticListableObjectFactory();
                objectFactory.AddObject("task", task1);
                mijdfb.TargetObjectName = ("task");
                mijdfb.ObjectFactory    = objectFactory;
            }
            else
            {
                mijdfb.TargetObject = (task1);
            }
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = ("myTrigger1");
            trigger1.JobDetail      = (jobDetail1);
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = MockRepository.GenerateMock <IScheduler>();

            scheduler.Stub(x => x.Context).Return(new SchedulerContext());

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();

            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            if (explicitJobDetail)
            {
                schedulerFactoryObject.JobDetails = (new IJobDetail[] { jobDetail0 });
            }
            schedulerFactoryObject.Triggers = (new ITrigger[] { trigger0, trigger1 });
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.ScheduleJob(trigger0));
            scheduler.AssertWasCalled(x => x.ScheduleJob(trigger1));

            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true));

            scheduler.AssertWasCalled(x => x.Start());
            scheduler.AssertWasCalled(x => x.Shutdown(false));
        }
        private void DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite)
        {
            TestObject      tb         = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();

            jobDetail0.JobType    = typeof(IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();

            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();

            trigger0.ObjectName           = ("myTrigger0");
            trigger0.JobDetail            = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.ObjectName   = ("myJob1");
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            IJobDetail jobDetail1 = (IJobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = ("myTrigger1");
            trigger1.JobDetail      = (jobDetail1);
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = MockRepository.GenerateMock <IScheduler>();

            scheduler.Stub(x => x.Context).Return(new SchedulerContext());
            scheduler.Stub(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup))).Return(new SimpleTriggerImpl());
            if (overwrite)
            {
                scheduler.AddJob(jobDetail1, true);
                scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1)).Return(DateTime.UtcNow);
            }

            scheduler.Stub(x => x.ScheduleJob(trigger0)).Throw(new ObjectAlreadyExistsException(""));

            if (overwrite)
            {
                scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0)).Return(DateTime.UtcNow);
            }

            scheduler.Start();
            scheduler.Shutdown(false);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();

            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            schedulerFactoryObject.Triggers = (new ITrigger[] { trigger0, trigger1 });
            if (overwrite)
            {
                schedulerFactoryObject.OverwriteExistingJobs = (true);
            }
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
        }
        private void DoTestSchedulerFactoryObjectWithExistingJobsAndRaceCondition(bool overwrite)
        {
            TestObject tb = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();
            jobDetail0.JobType = typeof (IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();
            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();
            trigger0.ObjectName = ("myTrigger0");
            trigger0.JobDetail = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            mijdfb.ObjectName = ("myJob1");
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();
            trigger1.ObjectName = ("myTrigger1");
            trigger1.JobDetail = (jobDetail1);
            trigger1.StartDelay = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = MockRepository.GenerateMock<IScheduler>();
            scheduler.Stub(x => x.Context).Return(new SchedulerContext());
            #if QUARTZ_2_0
            scheduler.Stub(x => x.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup))).Return(new SimpleTrigger());
            #else
            scheduler.Stub(x => x.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger());
            #endif
            if (overwrite)
            {
                scheduler.AddJob(jobDetail1, true);
            #if QUARTZ_2_0
                scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1)).Return(DateTime.UtcNow);
            #else
                scheduler.Stub(x => x.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return(DateTime.UtcNow);
            #endif
            }

            scheduler.Stub(x => x.ScheduleJob(trigger0)).Throw(new ObjectAlreadyExistsException(""));

            if (overwrite)
            {
            #if QUARTZ_2_0
                scheduler.Stub(x => x.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0)).Return(DateTime.UtcNow);
            #else
                scheduler.Stub(x => x.RescheduleJob("myTrigger0", SchedulerConstants.DefaultGroup, trigger0)).Return(DateTime.UtcNow);
            #endif
            }

            scheduler.Start();
            scheduler.Shutdown(false);

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();
            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1});
            if (overwrite)
            {
                schedulerFactoryObject.OverwriteExistingJobs = (true);
            }
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
        }
        private void DoTestSchedulerFactoryObject(bool explicitJobDetail, bool prototypeJob)
        {
            TestObject tb = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();
            jobDetail0.JobType = typeof (IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();
            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();
            trigger0.ObjectName = ("myTrigger0");
            trigger0.JobDetail = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            mijdfb.ObjectName = ("myJob1");
            if (prototypeJob)
            {
                StaticListableObjectFactory objectFactory = new StaticListableObjectFactory();
                objectFactory.AddObject("task", task1);
                mijdfb.TargetObjectName = ("task");
                mijdfb.ObjectFactory = objectFactory;
            }
            else
            {
                mijdfb.TargetObject = (task1);
            }
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();
            trigger1.ObjectName = ("myTrigger1");
            trigger1.JobDetail = (jobDetail1);
            trigger1.StartDelay = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = MockRepository.GenerateMock<IScheduler>();

            scheduler.Stub(x => x.Context).Return(new SchedulerContext());

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);
            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();
            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            if (explicitJobDetail)
            {
                schedulerFactoryObject.JobDetails = (new JobDetail[] {jobDetail0});
            }
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1});
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            scheduler.AssertWasCalled(x => x.ScheduleJob(trigger0));
            scheduler.AssertWasCalled(x => x.ScheduleJob(trigger1));

            scheduler.AssertWasCalled(x => x.AddJob(jobDetail0, true));
            scheduler.AssertWasCalled(x => x.AddJob(jobDetail1, true));

            scheduler.AssertWasCalled(x => x.Start());
            scheduler.AssertWasCalled(x => x.Shutdown(false));
        }
 public void TestCronTriggerObjectWithListenerNames()
 {
     CronTriggerObject trigger = new CronTriggerObject();
     String[] names = new String[] {"test1", "test2"};
     trigger.TriggerListenerNames = (names);
     ArrayList result = new ArrayList(trigger.TriggerListenerNames);
     Assert.AreEqual(names, result);
 }
Exemple #11
0
        private void DoTestSchedulerFactoryObjectWithExistingJobs(bool overwrite)
        {
            TestObject      tb         = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();

            jobDetail0.JobType    = typeof(IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();

            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();

            trigger0.ObjectName           = ("myTrigger0");
            trigger0.JobDetail            = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();

            mijdfb.ObjectName   = ("myJob1");
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail)mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();

            trigger1.ObjectName     = ("myTrigger1");
            trigger1.JobDetail      = (jobDetail1);
            trigger1.StartDelay     = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = (IScheduler)mockery.CreateMock(typeof(IScheduler));

            Expect.Call(scheduler.Context).Return(new SchedulerContext());
            Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger());
            if (overwrite)
            {
                scheduler.AddJob(jobDetail1, true);
                LastCall.IgnoreArguments();
                Expect.Call(scheduler.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return(
                    DateTime.UtcNow);
            }
            else
            {
                Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null);
            }
            scheduler.AddJob(jobDetail0, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);

            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();

            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            schedulerFactoryObject.Triggers = (new Trigger[] { trigger0, trigger1 });
            if (overwrite)
            {
                schedulerFactoryObject.OverwriteExistingJobs = (true);
            }
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }
        private void DoTestSchedulerFactoryObjectWithExistingJobs(bool overwrite)
        {
            TestObject tb = new TestObject("tb", 99);
            JobDetailObject jobDetail0 = new JobDetailObject();
            jobDetail0.JobType = typeof (IJob);
            jobDetail0.ObjectName = ("myJob0");
            IDictionary jobData = new Hashtable();
            jobData.Add("testObject", tb);
            jobDetail0.JobDataAsMap = (jobData);
            jobDetail0.AfterPropertiesSet();
            Assert.AreEqual(tb, jobDetail0.JobDataMap.Get("testObject"));

            CronTriggerObject trigger0 = new CronTriggerObject();
            trigger0.ObjectName = ("myTrigger0");
            trigger0.JobDetail = (jobDetail0);
            trigger0.CronExpressionString = ("0/1 * * * * ?");
            trigger0.AfterPropertiesSet();

            TestMethodInvokingTask task1 = new TestMethodInvokingTask();
            MethodInvokingJobDetailFactoryObject mijdfb = new MethodInvokingJobDetailFactoryObject();
            mijdfb.ObjectName = ("myJob1");
            mijdfb.TargetObject = (task1);
            mijdfb.TargetMethod = ("doSomething");
            mijdfb.AfterPropertiesSet();
            JobDetail jobDetail1 = (JobDetail) mijdfb.GetObject();

            SimpleTriggerObject trigger1 = new SimpleTriggerObject();
            trigger1.ObjectName = ("myTrigger1");
            trigger1.JobDetail = (jobDetail1);
            trigger1.StartDelay = TimeSpan.FromMilliseconds(0);
            trigger1.RepeatInterval = TimeSpan.FromMilliseconds(20);
            trigger1.AfterPropertiesSet();

            IScheduler scheduler = (IScheduler) mockery.CreateMock(typeof (IScheduler));
            Expect.Call(scheduler.Context).Return(new SchedulerContext());
            Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(new SimpleTrigger());
            if (overwrite)
            {
                scheduler.AddJob(jobDetail1, true);
                LastCall.IgnoreArguments();
                Expect.Call(scheduler.RescheduleJob("myTrigger1", SchedulerConstants.DefaultGroup, trigger1)).Return(
                    DateTime.UtcNow);
            }
            else
            {
                Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null);
            }
            scheduler.AddJob(jobDetail0, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow);
            scheduler.Start();
            scheduler.Shutdown(false);

            mockery.ReplayAll();

            SchedulerFactoryObject schedulerFactoryObject = new TestSchedulerFactoryObject(scheduler);
            schedulerFactoryObject.JobFactory = (null);
            IDictionary schedulerContext = new Hashtable();
            schedulerContext.Add("otherTestObject", tb);
            schedulerFactoryObject.SchedulerContextAsMap = (schedulerContext);
            schedulerFactoryObject.Triggers = (new Trigger[] {trigger0, trigger1});
            if (overwrite)
            {
                schedulerFactoryObject.OverwriteExistingJobs = (true);
            }
            try
            {
                schedulerFactoryObject.AfterPropertiesSet();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            mockery.VerifyAll();
        }