private void AddVariousLogsForSubresultIfOutcomeIsFailed(TestCaseSubResultData resultCreateModel, XmlNode resultNode)
        {
            if (!resultCreateModel.Outcome.Equals("Failed"))
            {
                return;
            }
            XmlNode errorMessage, errorStackTrace, consoleLog, standardError;

            if ((errorMessage = resultNode.SelectSingleNode("./Output/ErrorInfo/Message")) != null &&
                !string.IsNullOrWhiteSpace(errorMessage.InnerText))
            {
                resultCreateModel.ErrorMessage = errorMessage.InnerText;
            }

            // stack trace
            if ((errorStackTrace = resultNode.SelectSingleNode("./Output/ErrorInfo/StackTrace")) != null &&
                !string.IsNullOrWhiteSpace(errorStackTrace.InnerText))
            {
                resultCreateModel.StackTrace = errorStackTrace.InnerText;
            }

            // console log
            if ((consoleLog = resultNode.SelectSingleNode("./Output/StdOut")) != null &&
                !string.IsNullOrWhiteSpace(consoleLog.InnerText))
            {
                resultCreateModel.AttachmentData.ConsoleLog = consoleLog.InnerText;
            }

            // standard error
            if ((standardError = resultNode.SelectSingleNode("./Output/StdErr")) != null &&
                !string.IsNullOrWhiteSpace(standardError.InnerText))
            {
                resultCreateModel.AttachmentData.StandardError = standardError.InnerText;
            }
        }
Пример #2
0
        private async Task UploadTestSubResultsAttachmentAsync(int testRunId,
                                                               int testResultId,
                                                               TestCaseSubResultData subResultData,
                                                               TestSubResult subresult,
                                                               int level,
                                                               CancellationToken cancellationToken)
        {
            if (level > TestManagementConstants.maxHierarchyLevelForSubresults || subresult == null || subResultData == null || subResultData.AttachmentData == null)
            {
                return;
            }

            string[] attachments = subResultData.AttachmentData.AttachmentsFilePathList?.ToArray();

            // remove duplicate entries
            HashSet <string> attachedFiles = GetUniqueTestRunFiles(attachments);

            if (attachedFiles != null && attachedFiles.Any())
            {
                var createAttachmentsTasks = attachedFiles
                                             .Select(async attachment =>
                {
                    TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment);
                    if (reqModel != null)
                    {
                        await _testResultsServer.CreateTestSubResultAttachmentAsync(reqModel, _projectName, testRunId, testResultId, subresult.Id, cancellationToken);
                    }
                });
                await Task.WhenAll(createAttachmentsTasks);
            }

            // Upload console log as attachment
            string consoleLog = subResultData.AttachmentData.ConsoleLog;
            TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog);

            if (attachmentRequestModel != null)
            {
                await _testResultsServer.CreateTestSubResultAttachmentAsync(attachmentRequestModel, _projectName, testRunId, testResultId, subresult.Id, cancellationToken);
            }

            // Upload standard error as attachment
            string standardError = subResultData.AttachmentData.StandardError;
            TestAttachmentRequestModel stdErrAttachmentRequestModel = GetStandardErrorAttachmentRequestModel(standardError);

            if (stdErrAttachmentRequestModel != null)
            {
                await _testResultsServer.CreateTestSubResultAttachmentAsync(stdErrAttachmentRequestModel, _projectName, testRunId, testResultId, subresult.Id, cancellationToken);
            }

            if (subResultData.SubResultData != null)
            {
                for (int i = 0; i < subResultData.SubResultData.Count; ++i)
                {
                    await UploadTestSubResultsAttachmentAsync(testRunId, testResultId, subResultData.SubResultData[i], subresult.SubResults[i], level + 1, cancellationToken);
                }
            }
        }
Пример #3
0
        private static void ConvertSubResults(TestCaseSubResultData testCaseSubResultData, TestSubResult testSubResultWebApi)
        {
            if (testCaseSubResultData.SubResultData == null || !testCaseSubResultData.SubResultData.Any())
            {
                return;
            }

            testSubResultWebApi.SubResults = new List <TestSubResult>();
            foreach (var subResultData in testCaseSubResultData.SubResultData)
            {
                var subResultWebApi = new TestSubResult();
                TestCaseSubResultDataConverter.Convert(subResultData, subResultWebApi);
                testSubResultWebApi.SubResults.Add(subResultWebApi);
            }
        }
Пример #4
0
 public static void Convert(TestCaseSubResultData testCaseSubResultData, TestSubResult testSubResultWebApi)
 {
     testSubResultWebApi.CompletedDate   = testCaseSubResultData.CompletedDate;
     testSubResultWebApi.Comment         = testCaseSubResultData.Comment;
     testSubResultWebApi.ComputerName    = testCaseSubResultData.ComputerName;
     testSubResultWebApi.Configuration   = testCaseSubResultData.Configuration;
     testSubResultWebApi.CustomFields    = testCaseSubResultData.CustomFields;
     testSubResultWebApi.DurationInMs    = testCaseSubResultData.DurationInMs;
     testSubResultWebApi.DisplayName     = testCaseSubResultData.DisplayName;
     testSubResultWebApi.ErrorMessage    = testCaseSubResultData.ErrorMessage;
     testSubResultWebApi.Id              = testCaseSubResultData.Id;
     testSubResultWebApi.LastUpdatedDate = testCaseSubResultData.LastUpdatedDate;
     testSubResultWebApi.Outcome         = testCaseSubResultData.Outcome;
     testSubResultWebApi.ParentId        = testCaseSubResultData.ParentId;
     testSubResultWebApi.ResultGroupType = testCaseSubResultData.ResultGroupType;
     testSubResultWebApi.StackTrace      = testCaseSubResultData.StackTrace;
     testSubResultWebApi.SequenceId      = testCaseSubResultData.SequenceId;
     testSubResultWebApi.StartedDate     = testCaseSubResultData.StartedDate;
     testSubResultWebApi.TestResult      = testCaseSubResultData.TestResult;
     testSubResultWebApi.Url             = testCaseSubResultData.Url;
     ConvertSubResults(testCaseSubResultData, testSubResultWebApi);
 }
        private List <TestCaseSubResultData> ReadActualSubResults(XmlNodeList resultsNodes, TestType testType, int level)
        {
            List <TestCaseSubResultData> results = new List <TestCaseSubResultData>();

            if (level > TestManagementConstants.maxHierarchyLevelForSubresults)
            {
                _executionContext.Warning(StringUtil.Loc("MaxHierarchyLevelReached", TestManagementConstants.maxHierarchyLevelForSubresults));
                return(results);
            }
            object sync           = new object();
            var    resultXmlNodes = resultsNodes.Cast <XmlNode>();

            foreach (var resultNode in resultXmlNodes)
            {
                TestCaseSubResultData resultCreateModel = new TestCaseSubResultData();

                //Find and format dates as per TCM requirement.
                TimeSpan duration;
                if (resultNode.Attributes["duration"] != null && resultNode.Attributes["duration"].Value != null)
                {
                    TimeSpan.TryParse(resultNode.Attributes["duration"].Value, CultureInfo.InvariantCulture, out duration);
                }
                else
                {
                    duration = TimeSpan.Zero;
                }
                resultCreateModel.DurationInMs = (long)duration.TotalMilliseconds;

                DateTime startedDate;
                if (resultNode.Attributes["startTime"] != null && resultNode.Attributes["startTime"].Value != null)
                {
                    DateTime.TryParse(resultNode.Attributes["startTime"].Value, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out startedDate);
                }
                else
                {
                    startedDate = DateTime.UtcNow;
                }
                resultCreateModel.StartedDate = startedDate;

                DateTime completedDate = startedDate.AddTicks(duration.Ticks);
                resultCreateModel.CompletedDate = completedDate;

                if (resultNode.Attributes["outcome"] == null || resultNode.Attributes["outcome"].Value == null || string.Equals(resultNode.Attributes["outcome"].Value, "failed", StringComparison.OrdinalIgnoreCase))
                {
                    resultCreateModel.Outcome = TestOutcome.Failed.ToString();;
                }
                else if (string.Equals(resultNode.Attributes["outcome"].Value, "passed", StringComparison.OrdinalIgnoreCase))
                {
                    resultCreateModel.Outcome = TestOutcome.Passed.ToString();
                }
                else if (string.Equals(resultNode.Attributes["outcome"].Value, "inconclusive", StringComparison.OrdinalIgnoreCase))
                {
                    resultCreateModel.Outcome = TestOutcome.Inconclusive.ToString();
                }
                else
                {
                    resultCreateModel.Outcome = TestOutcome.NotExecuted.ToString();
                }

                if (resultNode.Attributes["testName"] != null && resultNode.Attributes["testName"].Value != null)
                {
                    resultCreateModel.DisplayName = resultNode.Attributes["testName"].Value;
                }

                if (resultNode.Attributes["computerName"] != null && resultNode.Attributes["computerName"].Value != null)
                {
                    resultCreateModel.ComputerName = resultNode.Attributes["computerName"].Value;
                }

                string executionId = null;
                if (resultNode.Attributes["executionId"] != null && resultNode.Attributes["executionId"].Value != null)
                {
                    executionId = resultNode.Attributes["executionId"].Value;
                }

                List <string> resulLeveltAttachments = new List <string>()
                {
                };

                XmlNodeList resultAttachmentNodes = resultNode.SelectNodes("CollectorDataEntries/Collector/UriAttachments/UriAttachment/A");
                if (resultAttachmentNodes.Count > 0 && executionId != null)
                {
                    foreach (XmlNode resultAttachmentNode in resultAttachmentNodes)
                    {
                        if (resultAttachmentNode.Attributes["href"] != null && resultAttachmentNode.Attributes["href"].Value != null)
                        {
                            resulLeveltAttachments.Add(Path.Combine(_attachmentLocation, executionId, resultAttachmentNode.Attributes["href"].Value));
                        }
                    }
                }

                XmlNodeList resultFileNodes = resultNode.SelectNodes("ResultFiles/ResultFile");

                if (resultFileNodes.Count > 0 && executionId != null)
                {
                    foreach (XmlNode resultFileNode in resultFileNodes)
                    {
                        if (resultFileNode.Attributes["path"] != null && resultFileNode.Attributes["path"].Value != null)
                        {
                            resulLeveltAttachments.Add(Path.Combine(_attachmentLocation, executionId, resultFileNode.Attributes["path"].Value));
                        }
                    }
                }

                resultCreateModel.AttachmentData = new AttachmentData()
                {
                    AttachmentsFilePathList = resulLeveltAttachments.ToArray()
                };

                AddVariousLogsForSubresultIfOutcomeIsFailed(resultCreateModel, resultNode);

                XmlNode innerResults = resultNode.SelectSingleNode("InnerResults");
                if (innerResults != null)
                {
                    resultCreateModel.ResultGroupType = GetResultGroupType(resultNode, testType);

                    XmlNodeList resNodes               = innerResults.SelectNodes("UnitTestResult");
                    XmlNodeList webTestResultNodes     = innerResults.SelectNodes("WebTestResult");
                    XmlNodeList orderedTestResultNodes = innerResults.SelectNodes("TestResultAggregation");

                    resultCreateModel.SubResultData = new List <TestCaseSubResultData>();

                    resultCreateModel.SubResultData.AddRange(ReadActualSubResults(resNodes, TestType.UnitTest, level + 1));
                    resultCreateModel.SubResultData.AddRange(ReadActualSubResults(webTestResultNodes, TestType.WebTest, level + 1));
                    resultCreateModel.SubResultData.AddRange(ReadActualSubResults(orderedTestResultNodes, TestType.OrderedTest, level + 1));
                }

                results.Add(resultCreateModel);
            }

            return(results);
        }