Esempio n. 1
0
        public async Task ScheduleEvery4thSeconds()
        {
            var clock    = new TestClock(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), TimeSpan.FromSeconds(1));
            var start    = new DateTimeOffset(2000, 1, 1, 0, 0, 4, 0, TimeSpan.Zero);
            var schedule = new ScheduleEveryInterval(TimeSpan.FromSeconds(4), start);

            using var timer     = new TestTimer();
            using var scheduler = new Scheduler(clock, timer, Logger.None);
            var testService = new TestScheduledService(schedule, scheduler);

            for (int i = 0; i < 10; i++)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(1));

                timer.Tick();
            }

            await Task.Delay(TimeSpan.FromMilliseconds(1));

            testService.Invokations.Should().Be(2);
        }
Esempio n. 2
0
        public async Task CronScheduleEvery5Minutes()
        {
            var clock = new TestClock(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), TimeSpan.FromMinutes(1));

            var schedule = new CronSchedule(CronExpression.Parse("*/5 * * * *"));

            using var timer     = new TestTimer();
            using var scheduler = new Scheduler(clock, timer, Logger.None);

            var testService = new TestScheduledService(schedule, scheduler);

            for (int i = 0; i < 10; i++)
            {
                await Task.Delay(TimeSpan.FromMilliseconds(1));

                timer.Tick();
            }

            await Task.Delay(TimeSpan.FromMilliseconds(1));

            testService.Invokations.Should().Be(2);
        }