public void GetNextTrigger_29FebruaryNotLeapYear_ReturnNextLeapYear() { var startDate = new DateTime(2014, 1, 1, 12, 02, 01, 123); var months = new HashSet<EMonth> { EMonth.February }; var days = new HashSet<EDayOfMonth> { EDayOfMonth.D29 }; var recurrence = new MonthlyRecurrence(months, days, null); var trigger = CreateMonthlyTrigger(startDate, startDate.AddYears(4), recurrence); var result = trigger.GetNextTrigger(startDate.AddSeconds(1)); var nextTrigger = new DateTime(2016, 2, 29, startDate.Hour, startDate.Minute, startDate.Second, startDate.Millisecond); Assert.That(result, IsEqual.WithinOneMillisecond(nextTrigger)); }
public void GetNextTrigger_DxInSameMonthButNextYear_ReturnsDateAccordingly( [Values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31)] int dayOfMonth) { var startDate = new DateTime(2014, 1, 1, 12, 02, 01, 123); var month = startDate.Month; var months = new HashSet<EMonth>{ (EMonth) month }; var days = new HashSet<EDayOfMonth>{ (EDayOfMonth) dayOfMonth }; var recurrence = new MonthlyRecurrence(months, days, null); var trigger = CreateMonthlyTrigger(startDate, startDate.AddYears(2), recurrence); var result = trigger.GetNextTrigger(startDate.AddDays(dayOfMonth)); var nextTrigger = new DateTime(startDate.Year + 1, month, dayOfMonth, startDate.Hour, startDate.Minute, startDate.Second, startDate.Millisecond); Assert.That(result, IsEqual.WithinOneMillisecond(nextTrigger)); }
public MonthlyTrigger(DateTime startDate, DateTime endDate, MonthlyRecurrence monthlyRecurrence) : base(startDate, endDate) { MonthlyRecurrence = monthlyRecurrence; }
protected virtual MonthlyTrigger CreateMonthlyTrigger(DateTime startDate, DateTime endDate, MonthlyRecurrence monthlyRecurrence) { return new MonthlyTrigger(startDate, endDate, monthlyRecurrence); }
public void GetNextTrigger_MonthlyOnTheXDayOfWeekYOfMay2014_ReturnZOfMay2014(EMonthlyOn monthlyOn, DayOfWeek dayOfWeek, int expectedDay) { var startDate = new DateTime(2014, 4, 1, 12, 02, 01, 123); var months = new HashSet<EMonth> { EMonth.May }; var specialDays = new Dictionary<EMonthlyOn, IList<DayOfWeek>>{ {monthlyOn, new List<DayOfWeek>{dayOfWeek}} }; var recurrence = new MonthlyRecurrence(months, null, specialDays); var trigger = CreateMonthlyTrigger(startDate, startDate.AddYears(2), recurrence); var result = trigger.GetNextTrigger(startDate.AddSeconds(1)); var nextTrigger = new DateTime(2014, 5, expectedDay, startDate.Hour, startDate.Minute, startDate.Second, startDate.Millisecond); Assert.That(result, IsEqual.WithinOneMillisecond(nextTrigger)); }
public void GetNextTrigger_LastInMonth_ReturnsLastInMonth(int month, int lastDay) { var startDate = new DateTime(2014, 1, 1, 12, 02, 01, 123); var months = new HashSet<EMonth>{ (EMonth) month }; var days = new HashSet<EDayOfMonth> { EDayOfMonth.Last }; var recurrence = new MonthlyRecurrence(months, days, null); var trigger = CreateMonthlyTrigger(startDate, startDate.AddYears(2), recurrence); var result = trigger.GetNextTrigger(startDate.AddSeconds(1)); var nextTrigger = new DateTime(startDate.Year, month, lastDay, startDate.Hour, startDate.Minute, startDate.Second, startDate.Millisecond); Assert.That(result, IsEqual.WithinOneMillisecond(nextTrigger)); }