Пример #1
0
        async void MakeTestResultViewModel(ITestResultMessage testResult, TestState outcome)
        {
            var tcs = new TaskCompletionSource <TestResultViewModel>(TaskCreationOptions.RunContinuationsAsynchronously);

            TestCaseViewModel testCase;

            if (!testCases.TryGetValue(testResult.TestCase, out testCase))
            {
                // no matching reference, search by Unique ID as a fallback
                testCase = testCases.FirstOrDefault(kvp => kvp.Key.UniqueID?.Equals(testResult.TestCase.UniqueID) ?? false).Value;
                if (testCase == null)
                {
                    return;
                }
            }

            // Create the result VM on the UI thread as it updates properties
            context.Post(_ =>
            {
                var result = new TestResultViewModel(testCase, testResult)
                {
                    Duration = TimeSpan.FromSeconds((double)testResult.ExecutionTime)
                };


                if (outcome == TestState.Failed)
                {
                    result.ErrorMessage    = ExceptionUtility.CombineMessages((ITestFailed)testResult);
                    result.ErrorStackTrace = ExceptionUtility.CombineStackTraces((ITestFailed)testResult);
                }


                tcs.TrySetResult(result);
            }, null);


            var r = await tcs.Task;

            listener.RecordResult(r); // bring it back to the threadpool thread
        }