예제 #1
0
        public void QueueTask_NullTask()
        {
            var scheduler = new TestableScheduler();

            scheduler
            .Invoking(s => s.QueueTask(null !))
            .Should().Throw <ArgumentNullException>();
        }
예제 #2
0
        public void Queue_Initial()
        {
            var scheduler = new TestableScheduler()
            {
                IsReliable = true
            };

            scheduler.GetScheduledTasks().Should().BeEmpty();
            scheduler.TryStartDispatcherCount.Should().Be(0);
        }
예제 #3
0
        public void TryStartDispatcher_ConcurrencyConflict()
        {
            var scheduler = new TestableScheduler {
                IsDispatcherEnabled = true
            };
            var task0 = ATask();
            var task1 = ATask();
            var task2 = ATask();

            task0.Start(scheduler);
            task1.Start(scheduler);
            task2.Start(scheduler);

            Task.WaitAll(task0, task1, task2);

            scheduler.TryStartDispatcherCount.Should().BeGreaterThan(3);
        }
예제 #4
0
        public void Queue_AfterQueueTasks()
        {
            var scheduler = new TestableScheduler()
            {
                IsReliable = true
            };
            var task0 = ATask();
            var task1 = ATask();
            var task2 = ATask();

            scheduler.QueueTask(task0);
            scheduler.QueueTask(task1);
            scheduler.QueueTask(task2);

            scheduler.GetScheduledTasks().Should().BeEquivalentTo(task0, task1, task2);
            scheduler.TryStartDispatcherCount.Should().Be(3);
        }
예제 #5
0
        public void TryExecuteTaskInline_QueuedTask()
        {
            var scheduler = new TestableScheduler(concurrency: 1);
            var task0     = null as Task;
            var task1     = ATask();
            var task2     = ATask();

            task0 = new Task(() =>
            {
                // Now inside dispatcher thread
                scheduler
                .TryExecuteTaskInline(task1, taskWasPreviouslyQueued: true)
                .Should().BeTrue();
            });

            task0.Start(scheduler);
            task1.Start(scheduler);
            scheduler.IsDispatcherEnabled = true;
            task2.Start(scheduler);

            Task.WaitAll(task0, task1, task2);
        }
예제 #6
0
        public void TryExecuteTaskInline_NonQueuedTask()
        {
            var scheduler = new TestableScheduler();
            var task0     = null as Task;
            var task1     = ATask();
            var task2     = ATask();

            task0 = new Task(() =>
            {
                // Now inside dispatcher thread
                task1.RunSynchronously(scheduler);
                // This should call:
                // scheduler
                //    .TryExecuteTaskInline(task1, taskWasPreviouslyQueued: false)
                //    => true
            });

            task0.Start(scheduler);
            scheduler.IsDispatcherEnabled = true;
            task2.Start(scheduler);

            Task.WaitAll(task0, task1, task2);
        }
예제 #7
0
        public void TryDequeue_NullTask()
        {
            var scheduler = new TestableScheduler();

            scheduler.TryDequeue(null !).Should().BeFalse();
        }
예제 #8
0
        public void TryExecuteTaskInline_NotInDispatcherThread()
        {
            var scheduler = new TestableScheduler();

            scheduler.TryExecuteTaskInline(ATask(), false).Should().BeFalse();
        }
예제 #9
0
        public void TryExecuteTaskInline_NullTask()
        {
            var scheduler = new TestableScheduler();

            scheduler.TryExecuteTaskInline(null, false).Should().BeFalse();
        }