예제 #1
0
        internal TaskObserver UseTaskObserver()
        {
            if (_taskObserver.Value != null)
            {
                throw new InvalidOperationException("AsyncLocal<TaskObserver> reentrancy");
            }

            var context = new TaskObserver(RemoveTaskObserver);

            _taskObserver.Value = context;
            return(context);
        }
예제 #2
0
        private async Task <RunSummary> RunTestCaseWithMethodFixturesAsync(IXunitTestCase testCase, TaskObserver taskObserver, TestMainThread testMainThread)
        {
            var runSummary     = new RunSummary();
            var methodFixtures = CreateMethodFixtures(testCase, runSummary);

            if (Aggregator.HasExceptions)
            {
                return(runSummary);
            }

            var testCaseConstructorArguments = await InitializeMethodFixturesAsync(testCase, runSummary, methodFixtures);

            if (!Aggregator.HasExceptions)
            {
                var testCaseRunTask    = testCase.RunAsync(_diagnosticMessageSink, MessageBus, testCaseConstructorArguments, new ExceptionAggregator(Aggregator), CancellationTokenSource);
                var testCaseRunSummary = await GetTestRunSummary(testCaseRunTask, taskObserver.Task);

                runSummary.Aggregate(testCaseRunSummary);
            }

            await DisposeMethodFixturesAsync(testCase, runSummary, methodFixtures);
            await WaitForObservedTasksAsync(testCase, runSummary, taskObserver, testMainThread);

            return(runSummary);
        }
예제 #3
0
 private Task WaitForObservedTasksAsync(IXunitTestCase testCase, RunSummary runSummary, TaskObserver taskObserver, TestMainThread testMainThread)
 {
     testMainThread.CancelPendingTasks();
     taskObserver.TestCompleted();
     return(RunAsync(testCase, () => taskObserver.Task, runSummary, "Tasks that have been started during test run are still not completed"));
 }
예제 #4
0
        private async Task <RunSummary> RunTestCaseWithMethodFixturesAsync(IXunitTestCase testCase, TaskObserver taskObserver, ITestMainThread testMainThread)
        {
            var runSummary     = new RunSummary();
            var methodFixtures = CreateMethodFixtures(testCase, runSummary);

            if (Aggregator.HasExceptions)
            {
                return(runSummary);
            }

            var testCaseConstructorArguments = await InitializeMethodFixturesAsync(testCase, runSummary, methodFixtures);

            if (!Aggregator.HasExceptions)
            {
                var testCaseRunSummary = await GetTestRunSummary(RunTestCaseAsync(testCase, testCaseConstructorArguments), taskObserver.Task);

                runSummary.Aggregate(testCaseRunSummary);
            }

            await DisposeMethodFixturesAsync(testCase, runSummary, methodFixtures);
            await WaitForObservedTasksAsync(testCase, runSummary, taskObserver, testMainThread);

            return(runSummary);
        }