public void Scheduled_tasks_can_be_canceled(int loop, int cancelAfter)
        {
            // setup
            var  scheduler          = new SequentialScheduler();
            int  count              = 0;
            Task lastTask           = Task.FromResult(true);
            var  cancellationSource = new CancellationTokenSource();

            // execute
            for (int i = 0; i < loop; i++)
            {
                var currentLoop = i;
                lastTask = scheduler.Schedule(() =>
                {
                    TestSequence(count, currentLoop);
                    count++;
                    if (cancelAfter == count)
                    {
                        cancellationSource.Cancel();
                    }
                }, cancellationSource.Token);
            }
            Assert.Throws <OperationCanceledException>(() => lastTask.Wait(cancellationSource.Token));

            // verify
            count.Should().Be(cancelAfter);
        }
        public void Simple_task_runs()
        {
            // setup
            var scheduler = new SequentialScheduler();
            int count     = 0;

            // execute
            var t = scheduler.Schedule(() => count++, CancellationToken.None);

            t.Wait();

            // verify
            count.Should().Be(1);
        }
        public void Task_are_scheduled_sequentially(int loop)
        {
            // setup
            var  scheduler = new SequentialScheduler();
            int  count     = 0;
            Task lastTask  = Task.FromResult(true);

            // execute
            for (int i = 0; i < loop; i++)
            {
                var currentLoop = i;
                lastTask = scheduler.Schedule(() =>
                {
                    TestSequence(count, currentLoop);
                    count++;
                }, CancellationToken.None);
            }
            lastTask.Wait();

            // verify
            count.Should().Be(loop);
        }