コード例 #1
0
        public void Cron_DescriptionTimeMatches()
        {
            var cron = new CronBuilder();

            cron.Seconds.Add(4)
            .Every = true;
            cron.Seconds.Description.Should()
            .Be("Every 4 seconds");

            cron.Description.Should()
            .Be("Every 4 seconds");

            cron.Minutes.Add(5)
            .Every = true;

            cron.Minutes.Description.Should()
            .Be("every 5 minutes");

            cron.Description.Should()
            .Be(cron.Description);

            cron.Hours.Add(3)
            .Every = true;

            cron.Hours.Description.Should()
            .Be("every 3 hours");

            cron.Description.Should()
            .Be(cron.Description);
        }
コード例 #2
0
ファイル: CronTests.cs プロジェクト: cwinland/Cron.Core
        public void Cron_DateAtDescriptionMatches()
        {
            var cron = new CronBuilder {
                CronMonths.January, CronDays.Friday,
            };

            cron.Minutes.Add(20);

            cron.Minutes.Description.Should()
            .Be("only at 20 minutes past the hour");

            cron.Minutes.Add(22)
            .Add(24, 26);

            cron.Minutes.Description.Should()
            .Be("only at 20,22,24-26 minutes past the hour");

            cron.Description.Should()
            .Be("only at 20,22,24-26 minutes past the hour, only in January, only on Friday");

            cron.Hours.Add(4);
            cron.Hours.Description.Should().Be("only at 4 hours");

            cron.Description.Should()
            .Be("only at 20,22,24-26 minutes past the hour, only at 4 hours, only in January, only on Friday");
        }
コード例 #3
0
        public void Cron_CreateByExpressionDescriptionMatches(
            string expression, string matchExpression, string description)
        {
            CronBuilder Act1() => new CronBuilder(expression);

            if (matchExpression != null)
            {
                var cron = Act1();

                cron.ToString()
                .Should()
                .Be(matchExpression);
            }

            if (!string.IsNullOrEmpty(description))
            {
                Act1()
                .Description.Should()
                .Be(description);
            }
            else
            {
                Action act = () => _ = new CronBuilder(expression).Description;

                act
                .Should()
                .Throw <InvalidDataException>(
                    "This expression only has {0} parts. An expression must have 5, 6, or 7 parts.",
                    expression.Split(' ')
                    .Length);
            }
        }
コード例 #4
0
        public void Ranges_Valid()
        {
            var cron = new CronBuilder {
                Minutes = { Every = false, },
            };

            cron.Minutes.IsValidRange(44)
            .Should()
            .BeTrue();
            cron.Minutes.Every = true;
            cron.Minutes.IsValidRange(44)
            .Should()
            .BeFalse();

            cron.Months.IsValidRange(1)
            .Should()
            .BeTrue();

            cron.Months.IsValidRange(12)
            .Should()
            .BeTrue();

            cron.Months.IsValidRange(13)
            .Should()
            .BeFalse();
        }
コード例 #5
0
        public void Cron_DateAtDescriptionMatches()
        {
            var cron = new CronBuilder {
                CronMonths.January, CronDays.Friday,
            };

            cron.Years.Add(2020);

            cron.Years.Description.Should()
            .Be("only in year 2020");

            cron.Years.Add(2022)
            .Add(2024, 2026);

            cron.Years.Description.Should()
            .Be("only in year 2020,2022,2024-2026");

            cron.Description.Should()
            .Be("Every minute, only in January, only on Friday, only in year 2020,2022,2024-2026");

            cron.Hours.Add(4);
            cron.Description.Should()
            .Be(
                "Every minute, 04:00 AM-04:59 AM, only in January, only on Friday, only in year 2020,2022,2024-2026");
        }
コード例 #6
0
        public void Cron_CanRemoveByRange()
        {
            var cron = new CronBuilder
            {
                { CronTimeSections.Seconds, 5, 6 },
                { CronTimeSections.Seconds, 9 },
                { CronTimeSections.Seconds, 7 },
            };

            cron.Value.Should()
            .Be("5-6,7,9 * * * * * *");

            cron.Seconds.ToString()
            .Should()
            .Be("5-6,7,9");

            cron.Seconds.Remove(5, 6)
            .ToString()
            .Should()
            .Be("7,9");

            cron.Value.Should()
            .Be("7,9 * * * * * *");

            cron.Minutes.Add(5, 6)
            .ToString()
            .Should()
            .Be("5-6");
            cron.Remove(CronTimeSections.Minutes, 5, 6)
            .ToString()
            .Should()
            .Be("7,9 * * * * * *");
        }
コード例 #7
0
        public void Cron_EveryDateTests()
        {
            var cron = new CronBuilder();

            cron.SectionList.Where(x => x.Item2.SectionType == CronSectionType.Date)
            .ToList()
            .ForEach(x => TestDateSection(cron, x.Item2));
        }
コード例 #8
0
        public void SerializeInterface(string expression, bool allowSeconds, string expectedSerialization)
        {
            ICron schedule = new CronBuilder(expression, allowSeconds);

            JsonSerializer.Serialize(schedule)
            .Should()
            .Be(expectedSerialization);
        }
コード例 #9
0
        public void Cron_EveryTimeTestsNoResets()
        {
            var cron = new CronBuilder();

            TestTimeSection(cron, cron.Seconds);
            TestTimeSection(cron, cron.Minutes);
            TestTimeSection(cron, cron.Hours);
        }
コード例 #10
0
        protected ScrapeScheduler(ILogger logger)
        {
            Logger          = logger;
            WebPortalHelper = new WebPortalHelper(new HttpClient());
            CronBuilder     = new CronBuilder();

            // Inject
            WebPortalHelper.Logger = Logger;
        }
コード例 #11
0
        public void Cron_Build_With_Days_Of_Month_Exceptions(int[] daysOfMonth, CronBuilder builder, Exception ex)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When a days of month recurrence is set"
            .x(() => ex = Record.Exception(() => builder.WithDaysOfMonth(daysOfMonth)));

            "Then an exception is thrown"
            .x(() => Assert.IsType <CronException>(ex));
        }
コード例 #12
0
        public void Cron_Build_With_Monthly(int interval, string crontab, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When a minutely recurrence is set"
            .x(() => builder.WithMonthly(interval));

            "The cron statement should be"
            .x(() => builder.ToString().ShouldBe(crontab));
        }
コード例 #13
0
        public void Cron_Build_With_Output_Formats(int interval, string crontab, string format, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When a daily recurrence is set"
            .x(() => builder.WithDaily(interval));

            "The cron statement should be"
            .x(() => builder.ToString(format).ShouldBe(crontab));
        }
コード例 #14
0
ファイル: CronTests.cs プロジェクト: cwinland/Cron.Core
        public void Cron_DateEveryDescriptionMatches()
        {
            var cron = new CronBuilder();

            cron.Months.Add(1);
            cron.DayWeek.Add(5);
            cron.Minutes.Add(20);

            cron.Description.Should()
            .Be("At 12:20 AM, only in January, only on Friday");
        }
コード例 #15
0
        public void Cron_Build_With_Invalid_Output_Format(int interval, CronBuilder builder, Exception ex)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When an invalid format is used"
            .x(() => ex = Record.Exception(() => builder.ToString("W")));

            "Then a format exception is thrown"
            .x(() => Assert.IsType <FormatException>(ex));
        }
コード例 #16
0
        public void Cron_Build_With_Days_Of_Week(int[] daysOfWeek, string crontab, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When a days of week recurrence is set"
            .x(() => builder.WithDaysOfWeek(daysOfWeek));

            "The cron statement should be"
            .x(() => builder.ToString().ShouldBe(crontab));
        }
コード例 #17
0
        public void Cron_Build_With_Daily_Exceptions(int interval, CronBuilder builder, Exception ex)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When a daily recurrence is set"
            .x(() => ex = Record.Exception(() => builder.WithDaily(interval)));

            "Then an exception is thrown"
            .x(() => Assert.IsType <CronException>(ex));
        }
コード例 #18
0
        public void Cron_Build_With_Hours(int[] interval, string crontab, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder());

            "When an hours recurrence is set"
            .x(() => builder.WithHours(interval));

            "The cron statement should be"
            .x(() => builder.ToString().ShouldBe(crontab));
        }
コード例 #19
0
        public void Cron_CanResetMinutes()
        {
            var cron = new CronBuilder();
            var val  = cron.Value;

            cron.Add(CronTimeSections.Minutes, 4)
            .Value.Should()
            .NotBe(val);

            cron.Reset(cron.Minutes).Value.Should().Be(val);
        }
コード例 #20
0
        public void Cron_TimeAtDescriptionMatches()
        {
            var cron = new CronBuilder();

            cron.Seconds.Add(5);
            cron.Minutes.Add(44);
            cron.Hours.Add(3);

            cron.Description.Should()
            .Be("At 03:44:05 AM");
        }
コード例 #21
0
        public void Cron_DateEveryDescriptionMatches()
        {
            var cron = new CronBuilder();

            cron.Months.Add(1);
            cron.DayWeek.Add(5);
            cron.Years.Add(2021);

            cron.Description.Should()
            .Be("Every minute, only in January, only on Friday, only in year 2021");
        }
コード例 #22
0
        public void Cron_CanAddByCronMonthRange()
        {
            var cron = new CronBuilder();

            cron.Add(CronMonths.August, CronMonths.November)
            .Value.Should()
            .Be("* * * * 8-11 * *");

            cron.Months.Values.Any(x => x == "8-11")
            .Should()
            .BeTrue();
        }
コード例 #23
0
        public void Cron_Build_Option_QuestionMark(int interval, string crontab, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder(new CronBuilderOptions {
                DisableQuestionMark = true
            }));

            "When a daily recurrence is set"
            .x(() => builder.WithDaily(interval));

            "The cron statement should be"
            .x(() => builder.ToString().ShouldBe(crontab));
        }
コード例 #24
0
        public void Cron_TimeEveryDescriptionMatches()
        {
            var cron = new CronBuilder();

            cron.Seconds.Add(5)
            .Every = true;
            cron.Minutes.Add(44)
            .Every = true;
            cron.Hours.Add(3)
            .Every = true;
            cron.Description.Should()
            .Be("Every 5 seconds, every 44 minutes, every 3 hours");
        }
コード例 #25
0
        public void Cron_CanResetDayWeek()
        {
            var cron = new CronBuilder();
            var val  = cron.Value;

            cron.Add(CronDays.Friday)
            .Value.Should()
            .NotBe(val);

            cron.Reset(CronTimeSections.DayWeek)
            .Value.Should()
            .Be(val);
        }
コード例 #26
0
        public void Cron_CanAddByDayWeekRange()
        {
            var cron = new CronBuilder();

            cron.Add(CronDays.Thursday, CronDays.Saturday)
            .Value
            .Should()
            .Be("* * * * * 4-6 *");

            cron.DayWeek.Values.Any(x => x == "4-6")
            .Should()
            .BeTrue();
        }
コード例 #27
0
        public void Int_IsInt()
        {
            var minutes = new CronBuilder()
                          .Minutes
                          .Add(5);

            minutes.IsInt()
            .Should()
            .BeTrue();
            minutes.Every = true;
            minutes.IsInt()
            .Should()
            .BeFalse();
        }
コード例 #28
0
        public void Cron_Build_With_Monthly_StartDate(int interval, string crontab, DateTime startDate, CronBuilder builder)
        {
            "Given a cron builder and a start date"
            .x(() =>
            {
                startDate = new DateTime(2000, 5, 1);
                builder   = new CronBuilder(startDate);
            });

            "When a minutely recurrence is set"
            .x(() => builder.WithMonthly(interval));

            "The cron statement should be"
            .x(() => builder.ToString().ShouldBe(crontab));
        }
コード例 #29
0
        public void Cron_NCronTab_Parse_Test(int interval, string cron, CronBuilder builder)
        {
            "Given a cron builder"
            .x(() => builder = new CronBuilder(new CronBuilderOptions {
                DisableQuestionMark = true
            }));

            "When a daily recurrence is set"
            .x(() => builder.WithDaily(interval));

            "The cron statement should be"
            .x(() => builder.ToString("Y").ShouldBe(cron));

            "And it should parse without errors"
            .x(() => CrontabSchedule.Parse(builder.ToString("Y")));
        }
コード例 #30
0
        public void Cron_CanClearMinutes()
        {
            var cron = new CronBuilder();
            var val  = cron.Minutes.ToString();

            cron
            .Add(CronTimeSections.Minutes, 4)
            .Minutes.ToString()
            .Should()
            .NotBe(val);

            cron.Minutes.Clear()
            .ToString()
            .Should()
            .Be(val);
        }