public void Constructor_TimeStrings() { DailySchedule schedule = new DailySchedule("08:30:00", "12:00:00", "15:00:00"); DateTime now = new DateTime(2015, 5, 23, 7, 30, 0); DateTime nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("08:30:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("12:00:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("15:00:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); }
public void OneTimePerDay() { // previously we had a bug in calculating the next occurrence // when the current time was greater than the single daily time. DailySchedule schedule = new DailySchedule("2:00:00"); DateTime now = new DateTime(2015, 9, 15, 21, 57, 40); DateTime nextOccurrence = schedule.GetNextOccurrence(now); TimeSpan nextInterval = nextOccurrence - now; Assert.Equal(14540000, nextInterval.TotalMilliseconds); }
public void Constructor_TimeSpans() { DailySchedule schedule = new DailySchedule( new TimeSpan(8, 30, 0), new TimeSpan(15, 0, 0), // verify the schedule self orders new TimeSpan(12, 00, 0)); DateTime now = new DateTime(2015, 5, 23, 7, 30, 0); DateTime nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("08:30:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("12:00:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal("15:00:00", nextOccurrence.TimeOfDay.ToString()); now = nextOccurrence + TimeSpan.FromSeconds(1); }
private void VerifySchedule(List<TimeSpan> scheduleData, DateTime now) { DailySchedule schedule = new DailySchedule(scheduleData.ToArray()); for (int i = 0; i < 10; i++) { for (int j = 0; j < scheduleData.Count; j++) { DateTime nextOccurrence = schedule.GetNextOccurrence(now); Assert.Equal(scheduleData[j], nextOccurrence.TimeOfDay); now = nextOccurrence + TimeSpan.FromSeconds(1); } } }