示例#1
0
        public void EveryDayAtMidnight()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "*",
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2007, 1, 1);

            DateTime expected = new DateTime(2007, 1, 1);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public void EveryDayForTwoYearsTest()
        {
            // Every day at 00:00:00
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "*",
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            // 2008 is a leap year
            DateTime fromDate = new DateTime(2007, 1, 1);

            while (fromDate.Year < 2009)
            {
                DateTime expected = fromDate;
                DateTime actual = target.NextDateTime(fromDate);
                Assert.AreEqual(expected, actual);

                fromDate = fromDate.AddDays(1);
            }
        }
示例#3
0
        public void WeekStandardTests()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "1",
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2010, 10, 1);
            while (fromDate.Day < 25)
            {
                int day = fromDate.Day;
                int mondayDay = 1;
                if (day >= 1 && day <= 4)
                    mondayDay = 4;
                else if (day >= 5 && day <= 11)
                    mondayDay = 11;
                else if (day >= 12 && day <= 18)
                    mondayDay = 18;
                else if (day >= 19 && day <= 25)
                    mondayDay = 25;
                DateTime expected = new DateTime(fromDate.Year, fromDate.Month, mondayDay);
                DateTime actual = target.NextDateTime(fromDate);
                Assert.AreEqual(expected, actual);

                fromDate = fromDate.AddDays(1);
            }
        }
示例#4
0
        public void SpecificMonth()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "7",
                DaysOfWeek = "*",
                Months = "12"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2010, 12, 7);
            DateTime expected = new DateTime(2010, 12, 7);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void WeekLastTests()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "4L",      // last thursday
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2010, 10, 1);
            DateTime expected = new DateTime(fromDate.Year, fromDate.Month, 28);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "5L",      // last friday
                Months = "*"
            };
            target = new ScheduleEngine(entry);

            fromDate = new DateTime(2007, 1, 1);
            while (fromDate.Year < 2009)
            {
                expected = FindLastExpectedWeekday(DayOfWeek.Friday, fromDate);
                actual = target.NextDateTime(fromDate);
                Assert.AreEqual(expected, actual);

                fromDate = fromDate.AddDays(1);
            }
        }
示例#6
0
        public void SecondsIntervalTest()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "*/5"
            };
            ScheduleEngine target = new ScheduleEngine(entry);
            DateTime fromDate = GetFromDateTime();
            DateTime expected = fromDate;
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime().AddSeconds(1);
            expected = GetFromDateTime().AddSeconds(5);
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#7
0
        public void SecondsRangeTest()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "30-40"
            };
            ScheduleEngine target = new ScheduleEngine(entry);
            DateTime fromDate = GetFromDateTime();
            DateTime expected = fromDate.AddSeconds(30);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime(30);
            expected = fromDate;
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime(31);
            expected = fromDate;
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime(40);
            expected = fromDate;
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime(41);
            expected = GetFromDateTime(30).AddMinutes(1);
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#8
0
        public void SecondsFixedTest()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "15"
            };
            ScheduleEngine target = new ScheduleEngine(entry);
            DateTime fromDate = GetFromDateTime(0);
            DateTime expected = fromDate.AddSeconds(15);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            fromDate = GetFromDateTime(20);
            expected = GetFromDateTime(15).AddMinutes(1);
            actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#9
0
        public void NastyBugDateTest()
        {
            // Every day at 00:00:00
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "*",
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2007, 11, 30);
            DateTime expected = new DateTime(2007, 11, 30);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);
        }
示例#10
0
        public void LastThursdayEveryOtherMonth()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "*",
                DaysOfWeek = "4L",
                Months = "*/2"      // jan, mar, may, ... because 0=jan
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2010, 11, 25);
            DateTime expected = new DateTime(2010, 11, 25);
            DateTime actual = target.NextDateTime(fromDate);
            Assert.AreEqual(expected, actual);

            DateTime[] lastThursdays = new DateTime[]
            {
                new DateTime(2010, 1, 28),
                new DateTime(2010, 3, 25),
                new DateTime(2010, 5, 27),
                new DateTime(2010, 7, 29),
                new DateTime(2010, 9, 30),
                new DateTime(2010, 11, 25)
            };

            fromDate = new DateTime(2010,1,1);
            foreach (DateTime lastExpected in lastThursdays)
            {
                actual = target.NextDateTime(fromDate);
                Assert.AreEqual(lastExpected, actual);
                fromDate = actual.AddDays(1);
            }
        }
示例#11
0
        public void LastDayOfEveryMonth()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "L",
                DaysOfWeek = "*",
                Months = "*"
            };
            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(2007, 1, 1);

            while (fromDate.Year < 2009)
            {
                int daysInMonth = DateTime.DaysInMonth(fromDate.Year, fromDate.Month);
                DateTime expected = new DateTime(fromDate.Year, fromDate.Month, daysInMonth);
                DateTime actual = target.NextDateTime(fromDate);
                Assert.AreEqual(expected, actual, "fromDate = " + fromDate.ToString());

                fromDate = fromDate.AddDays(1);
            }
        }
示例#12
0
        public void EveryOtherYear()
        {
            ScheduleEntry entry = new ScheduleEntry
            {
                Seconds = "0",
                Minutes = "0",
                Hours = "0",
                DaysOfMonth = "1",
                DaysOfWeek = "*",
                Months = "1",
                Years = "*/2"
            };

            ScheduleEngine target = new ScheduleEngine(entry);

            DateTime fromDate = new DateTime(1969,1,1);
            DateTime expected = new DateTime(1970,1,1);
            DateTime actual;

            while (fromDate.Year < 2400)
            {
                actual = target.NextDateTime(fromDate);
                Assert.AreEqual(expected, actual);

                fromDate = actual.AddDays(1);
                expected = expected.AddYears(2);
            }
        }