0

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();
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
dav10
  • 263
  • 1
  • 3
  • 8

1 Answers1

0

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.

hangy
  • 10,765
  • 6
  • 43
  • 63
  • Yes I tried setting my systemTime to same as I set it for SystemTime.UtcNow before executing the code. Still its the same , not triggering . – dav10 Dec 04 '13 at 11:10
  • SystemTime will always call the fixed delegate you provide. The time will not change and the job won't get triggered as Quartz thinks that it's 23:58 all the time. You should probably revisit your testing strategy towards testing using triggers directly and testing the GetFireTimeAfter/GetNextFireTimeUtc methods. – Marko Lahma Dec 06 '13 at 08:54
  • Hi thanks for pointing out. It would be helpful, if u could provide an example for the scenario which I was trying to test in my above test code. – dav10 Dec 10 '13 at 19:32
  • When `IIS` is running, it already read the system time and if you change it later, it won't trick the web app. – Jaider Feb 10 '14 at 22:52