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"); }
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"); }
public void Execute_a_job() { // Arrange // - Add a job into the test scheduler IScheduler sched = GetTestScheduler(); IJobDetail job = JobBuilder.Create<NoOpJob>() .WithIdentity("TestJob", "TestGroup") .Build(); sched.AddJob(job, true); // - Setup the mock HTTP Request var request = new Mock<HttpRequestBase>(); var context = new Mock<HttpContextBase>(); context.SetupGet(x => x.Request).Returns(request.Object); NameValueCollection formParameters = new 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 IInstanceRepository instanceRepo = new FakeInstanceRepository(); instanceRepo.Save(GetTestInstance()); JobExecutionController jec = new JobExecutionController(instanceRepo); // - Set the fake request for the controller jec.ControllerContext = new ControllerContext(context.Object, new RouteData(), jec); // Act ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob"); //Assert Assert.IsTrue(result is ContentResult && ((ContentResult)result).Content == "Job execution started"); }
public void Execute_a_job_with_job_data_map() { // Arrange // - Add a job into the test scheduler IScheduler sched = GetTestScheduler(); IJobDetail job = JobBuilder.Create<NoOpJob>() .WithIdentity("TestJob2", "TestGroup") .UsingJobData("MyParam1", "Initial Data") .Build(); sched.AddJob(job, true); // - Setup the mock HTTP Request var request = new Mock<HttpRequestBase>(); var context = new Mock<HttpContextBase>(); context.SetupGet(x => x.Request).Returns(request.Object); NameValueCollection formParameters = new 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 IInstanceRepository instanceRepo = new FakeInstanceRepository(); instanceRepo.Save(GetTestInstance()); JobExecutionController jec = new JobExecutionController(instanceRepo); // - Set the mocked context for the controller jec.ControllerContext = new ControllerContext(context.Object, new RouteData(), jec); // Act ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob2"); // - Get the triggers of the job IList<ITrigger> trigOfJob = sched.GetTriggersOfJob(JobKey.Create("TestJob2", "TestGroup")); //Assert Assert.IsTrue(result is ContentResult && ((ContentResult)result).Content == "Job execution started"); Assert.IsTrue(trigOfJob.Count() > 0); Assert.AreEqual(trigOfJob[0].JobDataMap["MyParam1"], "Working on the railroad"); }
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"); }
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"); }