private JobInfo ExtractJobInfo(string name, string group, IJobDetail jobDetail, ITrigger trigger) { var jobInfo = JobDetailService.GetJobDetail(name, group); var scheduleExpr = string.Empty; if (trigger is ICronTrigger cronTrigger) { scheduleExpr = cronTrigger.CronExpressionString; } var originJobInfo = JobInfo.Create( group, name, desc: jobDetail.Description, schedule: scheduleExpr, state: _quartzScheduler.GetTriggerState(trigger.Key).Result.GetJobState().ToString(), actionState: (_quartzScheduler.GetCurrentlyExecutingJobs().Result.ContainsJob(name, group)) ? JobActionState.Executing.ToString() : string.Empty, nextFire: trigger.GetNextFireTimeUtc(), prevFire: trigger.GetPreviousFireTimeUtc() ); return(JobInfo.Create( group, name, desc: jobInfo?.JobDescription ?? originJobInfo.Description, schedule: CronExpressionDescriptor.ExpressionDescriptor.GetDescription( jobInfo?.JobSchedule ?? originJobInfo.Schedule, new Options { Locale = "en" }), state: originJobInfo.State, actionState: originJobInfo.ActionState, nextFire: jobInfo?.JobNextRunTime ?? originJobInfo.NextFireTimeUtc, prevFire: jobInfo?.JobLastRunTime ?? originJobInfo.PrevFireTimeUtc )); }
public void ThenShouldReturnExpectedCountExecutionsGivenRangeStart000000AndRangeEnd125959( int frequencySubdayType, int frequencySubdayInterval, string activeStartDateTime, string activeEndDateTime, int expectedCount, string description) { // Arrange var jobRepository = new Mock <IJobRepository>(); var jobId = new Guid("C647117A-050A-4913-8BD8-D92A20315351"); var scheduleId = 1; var sysjobschedules = new List <sysjobschedule> { new sysjobschedule { job_id = jobId, schedule_id = scheduleId } }; jobRepository.Setup(repository => repository.GetJobSchedules()).Returns(sysjobschedules); var sysschedules = new List <sysschedule> { new sysschedule() }; //doesn't really matter what values are here for testing purposes, as the object gets datamapper-d into its final form jobRepository.Setup(repository => repository.GetSchedules()) .Returns(sysschedules); var jobs = new List <Job> { new Job { JobId = jobId } }; jobRepository.Setup(repository => repository.GetJobHistory(It.IsAny <IEnumerable <Guid> >())) .Returns(new List <sysjobhistory> { new sysjobhistory { job_id = jobId } }); var dataMapper = new Mock <IDataMapper>(); dataMapper.Setup(mapper => mapper.Map <IList <SystemJobSchedule> >(sysjobschedules)) .Returns(new List <SystemJobSchedule> { new SystemJobSchedule { JobId = jobId, ScheduleId = scheduleId, NextRunDate = new DateTime(2016, 8, 29) } }); var activeStartDate = DateTime.Parse(activeStartDateTime); var activeEndDate = DateTime.Parse(activeEndDateTime); dataMapper.Setup(mapper => mapper.Map <IList <SystemSchedule> >(sysschedules)) .Returns(new List <SystemSchedule> { new SystemSchedule { ScheduleId = scheduleId, FreqType = 4, //Daily FreqInterval = 62, //M-F ActiveStartDate = activeStartDate, ActiveEndDate = activeEndDate, FreqSubdayType = frequencySubdayType, FreqSubdayInterval = frequencySubdayInterval } }); var jobDetailService = new JobDetailService(dataMapper.Object, jobRepository.Object); //Act var result = jobDetailService.GetInterpolatedRunTimes(jobs, new DateTime(2016, 8, 29), new DateTime(2016, 9, 4, 23, 59, 59)); //Assert Assert.That(result, Has.Count.EqualTo(expectedCount), description); Assert.That(result, Has.All.Matches <ScheduledExecution>( execution => execution.ExpectedRunDate.TimeOfDay.IsGreaterThanOrEqualTo(activeStartDate.TimeOfDay) && //Expected run date times are not before the start date time execution.ExpectedRunDate.TimeOfDay.IsLessThanOrEqualTo(activeEndDate.TimeOfDay))); //Expected run date times are not after the end date time }