Esempio n. 1
0
        public void InCompletionOrder_HandlesFaultedTasks()
        {
            var timeMachine = new TimeMachine();

            var task1 = timeMachine.AddFaultingTask<int>(2, new Exception("oops"));
            var task2 = timeMachine.AddFaultingTask<int>(1, new Exception("whoa"));
            var tasks = new List<Task<int>>
            {
                task1,
                task2
            };

            foreach (var task in tasks.InCompletionOrder())
            {
                task.IsCompleted.Should().BeFalse("the task hasn't completed yet");
            }

            // step 1
            timeMachine.AdvanceBy(1);
            task2.IsCompleted.Should().BeTrue("because the task has completed");
            task2.IsFaulted.Should().BeTrue("because the task was canceled");

            // step 2
            timeMachine.AdvanceBy(2);
            task1.IsCompleted.Should().BeTrue("because the task has completed");
            task1.IsFaulted.Should().BeTrue("because the task was canceled");
        }