Пример #1
0
        public void Execute_a_job()
        {
            // Arrange
            // - Add a job into the test scheduler
            IScheduler sched = GetTestScheduler();
            JobDetail  job   = new JobDetail("TestJob", "TestGroup", typeof(Quartz.Job.NoOpJob));

            sched.AddJob(job, true);
            // - Setup the mock HTTP Request
            var request = new Mock <System.Web.HttpRequestBase>();
            var context = new Mock <System.Web.HttpContextBase>();

            context.SetupGet(x => x.Request).Returns(request.Object);
            System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection();
            // NOTE: adding items to the formParameter collection is possible here
            request.SetupGet(x => x.Form).Returns(formParameters);


            // - Create the fake instance repo and the job execution controller
            QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository();
            instanceRepo.Save(GetTestInstance());
            QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo);

            // - Set the fake request for the controller
            jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec);

            // Act
            System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob");

            //Assert
            Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started");
        }
Пример #2
0
        public void Execute_a_job_with_job_data_map()
        {
            // Arrange
            // - Add a job into the test scheduler
            IScheduler sched = GetTestScheduler();
            JobDetail  job   = new JobDetail("TestJob2", "TestGroup", typeof(Quartz.Job.NoOpJob));

            job.JobDataMap.Add("MyParam1", "Initial Data");
            sched.AddJob(job, true);
            // - Setup the mock HTTP Request
            var request = new Mock <System.Web.HttpRequestBase>();
            var context = new Mock <System.Web.HttpContextBase>();

            context.SetupGet(x => x.Request).Returns(request.Object);
            System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection();

            formParameters.Add("jdm_MyParam1", "Working on the railroad");
            request.SetupGet(x => x.Form).Returns(formParameters);


            // - Create the fake instance repo and the job execution controller
            QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository();
            instanceRepo.Save(GetTestInstance());
            QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo);

            // - Set the mocked context for the controller
            jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec);

            // Act
            System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob2");
            // - Get the triggers of the job
            Trigger[] trigOfJob = sched.GetTriggersOfJob("TestJob2", "TestGroup");

            //Assert
            Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started");
            Assert.IsTrue(trigOfJob.Count() > 0);
            Assert.AreEqual(trigOfJob[0].JobDataMap["MyParam1"], "Working on the railroad");
        }
Пример #3
0
        public void Execute_a_job()
        {
            // Arrange
            // - Add a job into the test scheduler
            IScheduler sched = GetTestScheduler();
            JobDetail job = new JobDetail("TestJob", "TestGroup", typeof(Quartz.Job.NoOpJob));
            sched.AddJob(job, true);
            // - Setup the mock HTTP Request
            var request = new Mock<System.Web.HttpRequestBase>();
            var context = new Mock<System.Web.HttpContextBase>();
            context.SetupGet(x => x.Request).Returns(request.Object);
            System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection();
            // NOTE: adding items to the formParameter collection is possible here
            request.SetupGet(x => x.Form).Returns(formParameters);

            
            // - Create the fake instance repo and the job execution controller
            QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository();
            instanceRepo.Save(GetTestInstance());
            QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo);

            // - Set the fake request for the controller
            jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec);

            // Act
            System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob");

            //Assert
            Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started");

        }
Пример #4
0
        public void Execute_a_job_with_job_data_map()
        {
            // Arrange
            // - Add a job into the test scheduler
            IScheduler sched = GetTestScheduler();
            JobDetail job = new JobDetail("TestJob2", "TestGroup", typeof(Quartz.Job.NoOpJob));
            job.JobDataMap.Add("MyParam1", "Initial Data");
            sched.AddJob(job, true);
            // - Setup the mock HTTP Request
            var request = new Mock<System.Web.HttpRequestBase>();
            var context = new Mock<System.Web.HttpContextBase>();
            context.SetupGet(x => x.Request).Returns(request.Object);
            System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection();

            formParameters.Add("jdm_MyParam1", "Working on the railroad");
            request.SetupGet(x => x.Form).Returns(formParameters);


            // - Create the fake instance repo and the job execution controller
            QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository();
            instanceRepo.Save(GetTestInstance());
            QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo);

            // - Set the mocked context for the controller
            jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec);

            // Act
            System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob2");
            // - Get the triggers of the job
            Trigger[] trigOfJob = sched.GetTriggersOfJob("TestJob2", "TestGroup");

            //Assert
            Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started");
            Assert.IsTrue(trigOfJob.Count() > 0);
            Assert.AreEqual(trigOfJob[0].JobDataMap["MyParam1"], "Working on the railroad");

        }