Example #1
0
        public void CronPerInterval_GivenIntervalAndTime_ReturnsCorrectCronString(Scheduling schedule, int year, int month, int day, string expected)
        {
            var dateToTest = new DateTime(year, month, day);
            var result     = CronStringHelper.CronPerInterval(schedule, dateToTest);

            Assert.Equal(expected, result);
        }
Example #2
0
        public void CreateFromAlarmDateAndScheduleReturns_With_Yearly_Interval_HandlesAlarmDate_InLeap_Year()
        {
            //Arrange
            var leapYearDate     = new DateTime(2020, 2, 29);
            var expectedInterval = CronStringHelper.CronPerInterval(Scheduling.Year, leapYearDate, true);

            //Act
            var adviceTriggers = AdviceTriggerFactory.CreateFrom(leapYearDate, Scheduling.Year).ToList();

            //Assert
            var adviceTrigger = Assert.Single(adviceTriggers);

            Assert.Equal(expectedInterval, adviceTrigger.Cron);
        }
Example #3
0
        public void CreateFromAlarmDateAndScheduleReturns_1_Trigger_With_LastDayInMonth_If_31_Is_Selected(Scheduling scheduling, int month, int day)
        {
            //Arrange
            var alarmDate        = new DateTime(2000, month, day);
            var expectedInterval = CronStringHelper.CronPerInterval(scheduling, new DateTime(2000, month, day), true);

            //Act
            var adviceTriggers = AdviceTriggerFactory.CreateFrom(alarmDate, scheduling).ToList();

            //Assert
            var adviceTrigger = Assert.Single(adviceTriggers);

            Assert.False(adviceTrigger.PartitionId.HasValue);
            Assert.Equal(expectedInterval, adviceTrigger.Cron);
        }
Example #4
0
        public void CreateFromAlarmDateAndScheduleReturns_2_Triggers_For_SemiAnnualTrigger_Trigger_With_Day_Which_Conflicts_With_February(int month, int day)
        {
            //Arrange
            var alarmDate          = new DateTime(2000, month, day);
            var expectedPartitions = Enumerable.Range(0, 2).ToList();
            var expectedCronJobs   = new[]
            {
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(2000, 2, 28), true),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(2000, 8, day))
            };

            //Act
            var adviceTriggers = AdviceTriggerFactory.CreateFrom(alarmDate, Scheduling.Semiannual).ToList();

            //Assert
            AssertCreatedJobs(adviceTriggers, expectedPartitions, expectedCronJobs);
        }
Example #5
0
        public void CreateFromAlarmDateAndScheduleReturns_With_SemiAnnual_Interval_HandlesAlarmDate_InLeap_Year()
        {
            //Arrange
            var leapYearDate       = new DateTime(2020, 2, 29);
            var expectedPartitions = Enumerable.Range(0, 2).ToList();
            var expectedCronJobs   = new[]
            {
                CronStringHelper.CronPerInterval(Scheduling.Year, leapYearDate, true),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(leapYearDate.Year, leapYearDate.Month + 6, leapYearDate.Day))
            };

            //Act
            var adviceTriggers = AdviceTriggerFactory.CreateFrom(leapYearDate, Scheduling.Semiannual).ToList();

            //Assert
            AssertCreatedJobs(adviceTriggers, expectedPartitions, expectedCronJobs);
        }
Example #6
0
        private static string[] CreateExpectedCronForMonthlyInterval(int year, int day, bool expectFebruaryLastDayInMonth)
        {
            var expectedCronJobs = new[]
            {
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 1, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 2, expectFebruaryLastDayInMonth ? 28 : day), expectFebruaryLastDayInMonth),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 3, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 4, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 5, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 6, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 7, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 8, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 9, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 10, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 11, day)),
                CronStringHelper.CronPerInterval(Scheduling.Year, new DateTime(year, 12, day))
            };

            return(expectedCronJobs);
        }
 private static AdviceTrigger SetupAdviceTrigger(Scheduling schedule, DateTime alarmDate, Maybe <int> partitionId, bool enforceLastDayInMonth = false)
 {
     return(new AdviceTrigger(CronStringHelper.CronPerInterval(schedule, alarmDate, enforceLastDayInMonth), partitionId));
 }