Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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 = (IScheduler)mockery.CreateMock(typeof(IScheduler));

            Expect.Call(scheduler.Context).Return(new SchedulerContext());
            Expect.Call(scheduler.GetJobDetail("myJob0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetJobDetail("myJob1", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger0", SchedulerConstants.DefaultGroup)).Return(null);
            Expect.Call(scheduler.GetTrigger("myTrigger1", SchedulerConstants.DefaultGroup)).Return(null);

            scheduler.AddJob(jobDetail0, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger0)).Return(DateTime.UtcNow);
            scheduler.AddJob(jobDetail1, true);
            LastCall.IgnoreArguments();
            Expect.Call(scheduler.ScheduleJob(trigger1)).Return(DateTime.UtcNow);
            scheduler.Start();
            LastCall.IgnoreArguments();
            scheduler.Shutdown(false);
            LastCall.IgnoreArguments();


            mockery.ReplayAll();

            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();
            }

            mockery.VerifyAll();
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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 = A.Fake <IScheduler>();

            A.CallTo(() => scheduler.Context).Returns(new SchedulerContext());
            A.CallTo(() => scheduler.GetTrigger(A <TriggerKey> ._)).Returns(null);
            A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._)).Returns(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();
                schedulerFactoryObject.Start();
            }
            finally
            {
                schedulerFactoryObject.Dispose();
            }

            A.CallTo(() => scheduler.ScheduleJob(trigger0)).MustHaveHappened();
            A.CallTo(() => scheduler.ScheduleJob(trigger1)).MustHaveHappened();

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

            A.CallTo(() => scheduler.Start()).MustHaveHappened();
            A.CallTo(() => scheduler.Shutdown(false)).MustHaveHappened();
        }
Esempio n. 7
0
        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 = A.Fake <IScheduler>();

            A.CallTo(() => scheduler.Context).Returns(new SchedulerContext());
            A.CallTo(() => scheduler.GetJobDetail(A <JobKey> ._)).Returns(null);
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup))).Returns(null);
            A.CallTo(() => scheduler.GetTrigger(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup))).Returns(new SimpleTriggerImpl());
            if (overwrite)
            {
                scheduler.AddJob(jobDetail1, true);
                A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger1", SchedulerConstants.DefaultGroup), trigger1)).Returns(DateTime.UtcNow);
            }

            A.CallTo(() => scheduler.ScheduleJob(trigger0)).Throws(new ObjectAlreadyExistsException(""));

            if (overwrite)
            {
                A.CallTo(() => scheduler.RescheduleJob(new TriggerKey("myTrigger0", SchedulerConstants.DefaultGroup), trigger0)).Returns(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();
            }

            A.CallTo(() => scheduler.AddJob(jobDetail0, true, true)).MustHaveHappened();
        }