public void StartWithTimeOfDayLaterThenStart() { Type jobType = typeof(SleepJob); JobLockProvider jobLockProvider = new StaticLockProvider(); JobHistoryProvider jobHistoryProvider = new StaticHistoryProvider { LastResult = string.Empty, LastRunTime = DateTime.Now, LastStatus = JobStatus.None }; // run time 1 hour ago DateTime runTime = DateTime.Now.Subtract(TimeSpan.FromHours(1)); var jobConfiguration = new JobConfiguration { Name = "SleepJob", Description = "Test Sleep Job with xml history", Interval = runTime.TimeOfDay, IsTimeOfDay = true, Type = typeof(SleepJob).AssemblyQualifiedName, JobLockProvider = typeof(StaticLockProvider).AssemblyQualifiedName, JobHistoryProvider = typeof(StaticHistoryProvider).AssemblyQualifiedName }; var j = new JobRunner(jobConfiguration, jobType, jobLockProvider, jobHistoryProvider); Assert.IsNotNull(j); j.Start(); DateTime nextRun = runTime.AddDays(1); Assert.AreEqual(nextRun.Date, j.NextRunTime.Date); Assert.AreEqual(nextRun.Hour, j.NextRunTime.Hour); Assert.AreEqual(nextRun.Minute, j.NextRunTime.Minute); }
public void StartWithTimeOfDayOlderThenOneDay() { Type jobType = typeof(SleepJob); StaticLockProvider jobLockProvider = new StaticLockProvider(); StaticHistoryProvider jobHistoryProvider = new StaticHistoryProvider { LastResult = string.Empty, LastRunTime = DateTime.Now.Subtract(TimeSpan.FromDays(2)), // 2 days ago LastStatus = JobStatus.None }; // run time 1 hour ago DateTime runTime = DateTime.Now.Subtract(TimeSpan.FromHours(1)); var jobConfiguration = new JobConfiguration { Name = "SleepJob", Description = "Test Sleep Job with xml history", Interval = runTime.TimeOfDay, IsTimeOfDay = true, Type = typeof(SleepJob).AssemblyQualifiedName, JobLockProvider = typeof(StaticLockProvider).AssemblyQualifiedName, JobHistoryProvider = typeof(StaticHistoryProvider).AssemblyQualifiedName }; var j = new JobRunner(jobConfiguration, jobType, jobLockProvider, jobHistoryProvider); Assert.IsNotNull(j); Assert.AreEqual(1, jobHistoryProvider.RestoreCount); Assert.AreEqual(JobStatus.None, j.LastStatus); j.Start(); // wait 30 sec, then test Thread.Sleep(TimeSpan.FromSeconds(30)); Assert.AreEqual(1, jobHistoryProvider.SaveCount); Assert.AreEqual(JobStatus.Completed, j.LastStatus); // should set next run time to tomorrow DateTime nextRun = runTime.AddDays(1); Assert.AreEqual(nextRun.Date, j.NextRunTime.Date); Assert.AreEqual(nextRun.Hour, j.NextRunTime.Hour); Assert.AreEqual(nextRun.Minute, j.NextRunTime.Minute); }