/// <summary> /// Copies the result messages to unitTestResult /// </summary> /// <param name="unitTestResult">TRX TestResult</param> /// <param name="testResult"> rock steady test result</param> private static void UpdateResultMessages(TrxObjectModel.TestResult unitTestResult, ObjectModel.TestResult testResult) { StringBuilder debugTrace = new StringBuilder(); StringBuilder stdErr = new StringBuilder(); StringBuilder stdOut = new StringBuilder(); foreach (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResultMessage message in testResult.Messages) { if (ObjectModel.TestResultMessage.AdditionalInfoCategory.Equals(message.Category, StringComparison.OrdinalIgnoreCase)) { unitTestResult.AddTextMessage(message.Text); } else if (ObjectModel.TestResultMessage.DebugTraceCategory.Equals(message.Category, StringComparison.OrdinalIgnoreCase)) { debugTrace.AppendLine(message.Text); } else if (ObjectModel.TestResultMessage.StandardErrorCategory.Equals(message.Category, StringComparison.OrdinalIgnoreCase)) { stdErr.AppendLine(message.Text); } else if (ObjectModel.TestResultMessage.StandardOutCategory.Equals(message.Category, StringComparison.OrdinalIgnoreCase)) { stdOut.AppendLine(message.Text); } else { ObjectModel.EqtTrace.Warning("The message category " + message.Category + " does not match any predefined category."); } } unitTestResult.DebugTrace = debugTrace.ToString(); unitTestResult.StdErr = stdErr.ToString(); unitTestResult.StdOut = stdOut.ToString(); }
/// <summary> /// Updates test result attachments. /// </summary> /// <param name="rockSteadyTestResult"></param> /// <param name="testResult"></param> /// <param name="testRun"></param> /// <param name="trxFileDirectory"></param> /// <param name="addAttachments"></param> private static void UpdateTestResultAttachments(ObjectModel.TestResult rockSteadyTestResult, TrxObjectModel.TestResult testResult, TestRun testRun, string trxFileDirectory, bool addAttachments) { if (rockSteadyTestResult.Attachments == null || rockSteadyTestResult.Attachments.Count == 0) { return; } // the testResult needs to have the testRun property set. Otherwise Data Collector entries can't be added. testResult.SetTestRun(testRun); // result files List <string> resultFiles = new List <string>(); // data collection files List <CollectorDataEntry> collectorEntries = new List <CollectorDataEntry>(); foreach (ObjectModel.AttachmentSet attachmentSet in rockSteadyTestResult.Attachments) { try { // If the attachement is from data collector if (attachmentSet.Uri.AbsoluteUri.StartsWith(Constants.DataCollectorUriPrefix, StringComparison.OrdinalIgnoreCase)) { CollectorDataEntry collectorEntry = ToCollectorEntry(attachmentSet, testResult.Id.ExecutionId, testRun, trxFileDirectory); collectorEntries.Add(collectorEntry); } else { IList <string> testResultFiles = ToResultFiles(attachmentSet, testResult.Id.ExecutionId, testRun, trxFileDirectory); resultFiles.AddRange(testResultFiles); } } catch (Exception e) { string errorMsg = string.Format( CultureInfo.CurrentCulture, TrxLoggerResources.FailureToAttach, attachmentSet.DisplayName, e.GetType().ToString(), e); if (ObjectModel.EqtTrace.IsErrorEnabled) { ObjectModel.EqtTrace.Error("Converter: UpdateTestResultAttachments: " + errorMsg); } StringBuilder stdErr = new StringBuilder(testResult.StdErr); stdErr.AppendLine(errorMsg); testResult.StdErr = stdErr.ToString(); testResult.Outcome = TrxObjectModel.TestOutcome.Error; } } if (addAttachments) { if (resultFiles.Count > 0) { testResult.AddResultFiles(resultFiles); } if (collectorEntries.Count > 0) { testResult.AddCollectorDataEntries(collectorEntries); } } }