Quartz.net + 使用 SystemTime.UtcNow 进行测试 [英] Quartz.net + testing with SystemTime.UtcNow

查看:35
本文介绍了Quartz.net + 使用 SystemTime.UtcNow 进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过创建作业来使用示例代码测试 Quartz.net dll.但我想更改系统时间并测试一些情况,例如:我正在尝试设置此 SystemTime.UtcNow = () => new DateTime(2013,11,23,58,00);在创建之前在我的测试控制台应用程序中,并添加了一个作业以在 .WithCronSchedule("0 59 23 ? * *") 处打勾,但它没有打勾……不确定 SystemTime 是否已生效.

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.

以下示例代码:

    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();

推荐答案

您是否尝试将 SystemTime 设置为与预定时间完全一致或稍晚一点?您的 SystemTime 值不会改变,如果 Quartz.Net 尝试检查是否应使用该委托来运行作业,实际上永远不会是在您的测试中运行它的正确时间.

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.

这篇关于Quartz.net + 使用 SystemTime.UtcNow 进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆