问题
I am trying to test Quartz.net dll with sample code by creating jobs. But I want to change the system time and test some cases like : I am trying to set this SystemTime.UtcNow = () => new DateTime(2013,11,23,58,00); in my test console app before creating , and added a job to tick at .WithCronSchedule("0 59 23 ? * *") but its not ticking ... not sure whether SystemTime has taken effect.
sample code below :
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sched = sf.GetScheduler();
SystemTime.UtcNow = () => new DateTime(2013, 12, 04, 23, 58, 00);
SystemTime.Now = () => new DateTime(2013, 12, 04, 23, 58, 00);
////TEST
IJobDetail job = JobBuilder.Create<SimpleJob>()
.WithIdentity("job1", "group1")
.Build();
ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule("0 59 23 ? * *")
.Build();
回答1:
Have you tried setting the SystemTime
to exactly the scheduled time or a bit after that? Your SystemTime
value does not change and if Quartz.Net tries to check whether the job should be run using that delegate, it will actually never be the right time to run it in your test.
来源:https://stackoverflow.com/questions/20370784/quartz-net-testing-with-systemtime-utcnow