public void GetDaysOfWeekToRunOn_ForOneDay_ReturnsCorrectResult() { var result = ScheduleStringHelper.GetDaysOfWeekToRunOn("mon"); Assert.That(result.Length == 1); Assert.That(result[0] == DayOfWeek.Monday); }
public void GetDaysOfWeekToRunOn_ForMultipleDaysWithDuplicates_ReturnsCorrectUniqueResult() { var result = ScheduleStringHelper.GetDaysOfWeekToRunOn("mon,wed,tue,thu,sat,sun,sat"); Assert.That(result.Length == 6); Assert.That(result[0] == DayOfWeek.Monday); Assert.That(result[1] == DayOfWeek.Wednesday); Assert.That(result[2] == DayOfWeek.Tuesday); Assert.That(result[3] == DayOfWeek.Thursday); Assert.That(result[4] == DayOfWeek.Saturday); Assert.That(result[5] == DayOfWeek.Sunday); }
private static ITrigger CreateTriggerForSpecificRunTime(string triggerName, string runAtTime, string runOnDays, string excludeCalendar, string targetTimeZone) { ITrigger trigger = null; TimeZoneInfo timezone = TimeZoneInfo.Local; if (!string.IsNullOrEmpty(targetTimeZone)) { timezone = TimeZoneInfo.FindSystemTimeZoneById(targetTimeZone); } if (!string.IsNullOrEmpty(runOnDays)) { var daysOfWeek = ScheduleStringHelper.GetDaysOfWeekToRunOn(runOnDays); var runAtTuple = ScheduleStringHelper.GetHoursAndMinutes(runAtTime); trigger = TriggerBuilder.Create() .WithIdentity(triggerName) .WithDescription($"Run at: {runAtTime}, run days: {runOnDays}, exclusion calendar: {excludeCalendar}") .WithSchedule(CronScheduleBuilder.AtHourAndMinuteOnGivenDaysOfWeek(runAtTuple.Item1, runAtTuple.Item2, daysOfWeek) .InTimeZone(timezone)) .ModifiedByCalendar(excludeCalendar) .StartNow() .Build(); } //else if (!string.IsNullOrEmpty(runCalendar)) //{ // trigger = TriggerBuilder.Create() // .WithIdentity(string.Format("Trigger_for_{0}", job.Key)) // .WithDescription(string.Format("Run at: {0}, run calendar: {1}, exclusion calendar: {2}", runAt, runCalendar, excludeCalendar)) // .WithSchedule(CronScheduleBuilder.) // .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(hour, minute)) // .ModifiedByCalendar(runCalendar) // .StartNow() // .Build(); //} return(trigger); }