Quartz.net + testing with SystemTime.UtcNow

你。 提交于 2019-12-13 06:12:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!