Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        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");
        }