private void AddToParentResult(Guid parentExecutionId, ObjectModel.TestResult testResult) { if (Results.TryGetValue(parentExecutionId, out var parentTestResult)) { if (parentTestResult.InnerTestResults == null) { parentTestResult.InnerTestResults = new List <ObjectModel.TestResult>(); } parentTestResult.InnerTestResults.Add(testResult); } }
/// <summary> /// Handles the result coming from vs test and store it in test results. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void TestResultHandler(object sender, TestResultEventArgs e) { ValidateArg.NotNull(sender, "sender"); ValidateArg.NotNull(e, "e"); var testResult = new ObjectModel.TestResult { DisplayName = e.Result.DisplayName ?? e.Result.TestCase.FullyQualifiedName, FullyQualifiedName = e.Result.TestCase.FullyQualifiedName, ErrorStackTrace = e.Result.ErrorStackTrace, ErrorMessage = e.Result.ErrorMessage, TestResultId = e.Result.TestCase.Id, Duration = GetFormattedDurationString(e.Result.Duration), ResultOutcome = e.Result.Outcome }; var executionId = GetExecutionId(e.Result); var parentExecutionId = GetParentExecutionId(e.Result); ResultCollectionDictionary.TryGetValue(e.Result.TestCase.Source, out var testResultCollection); if (testResultCollection == null) { testResultCollection = new TestResultCollection(e.Result.TestCase.Source) { ResultList = new List <ObjectModel.TestResult>(), FailedResultList = new List <ObjectModel.TestResult>(), }; ResultCollectionDictionary.TryAdd(e.Result.TestCase.Source, testResultCollection); TestRunDetails.ResultCollectionList.Add(testResultCollection); } TotalTests++; switch (e.Result.Outcome) { case TestOutcome.Failed: FailedTests++; break; case TestOutcome.Passed: PassedTests++; break; case TestOutcome.Skipped: SkippedTests++; break; default: break; } Results.TryAdd(executionId, testResult); // Check for parent execution id to store the test results in hierarchical way if (parentExecutionId == Guid.Empty) { if (e.Result.Outcome == TestOutcome.Failed) { testResultCollection.FailedResultList.Add(testResult); } testResultCollection.ResultList.Add(testResult); } else { AddToParentResult(parentExecutionId, testResult); } }