Exemple #1
0
        public async Task ItAllowsForScheduledTasksToBeCanceled()
        {
            var           taskName      = Guid.NewGuid().ToString();
            ScheduledTask scheduledTask = null;

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                scheduledTask = await taskScheduler.AddScheduledTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                                     DateTime.UtcNow + TimeSpan.FromSeconds(IntervalSeconds));
            };

            Func <TaskScheduler, Task> cancelTaskAction = async(taskScheduler) =>
            {
                (await taskScheduler.CancelScheduledTask(scheduledTask)).Should().BeTrue();
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerDoesNotWriteSemaphore(
                IntervalSeconds,
                configureSchedulerAction,
                cancelTaskAction);
        }
Exemple #2
0
        public async Task ItAllowsForRecurringTasksToBeCanceled()
        {
            var           taskName      = Guid.NewGuid().ToString();
            RecurringTask recurringTask = null;

            Func <string, TaskScheduler, Task> configureSchedulerAction = async(semaphoreFile, taskScheduler) =>
            {
                recurringTask = await taskScheduler.AddRecurringTask(() => TaskQueueTestFixture.WriteSemaphore(semaphoreFile),
                                                                     $"*/{IntervalSeconds} * * * * *", taskName);
            };

            Func <TaskScheduler, Task> cancelTaskAction = async(taskScheduler) =>
            {
                (await taskScheduler.CancelRecurringTask(recurringTask)).Should().BeTrue();
            };

            await TaskSchedulerTestHelpers.AssertTaskSchedulerDoesNotWriteSemaphore(
                IntervalSeconds,
                configureSchedulerAction,
                cancelTaskAction);
        }