예제 #1
0
        private List <TestCaseResultData> ReadActualResults(XmlNodeList resultsNodes, string testType)
        {
            List <TestCaseResultData> results = new List <TestCaseResultData>();

            object sync = new object();

            Parallel.ForEach <XmlNode>(resultsNodes.Cast <XmlNode>(), resultNode =>
            {
                TestCaseResultData resultCreateModel = new TestCaseResultData();

                //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, out duration);
                }
                else
                {
                    duration = TimeSpan.Zero;
                }
                resultCreateModel.DurationInMs = ((int)duration.TotalMilliseconds).ToString();

                DateTime startedDate;
                if (resultNode.Attributes["startTime"] != null && resultNode.Attributes["startTime"].Value != null)
                {
                    DateTime.TryParse(resultNode.Attributes["startTime"].Value, out startedDate);
                }
                else
                {
                    startedDate = DateTime.Now;
                }
                resultCreateModel.StartedDate = startedDate.ToString("o");

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

                if (resultNode.Attributes["outcome"] != null && resultNode.Attributes["outcome"].Value != null)
                {
                    resultCreateModel.Outcome = resultNode.Attributes["outcome"].Value;
                }
                else
                {
                    resultCreateModel.Outcome = "Failed";
                }

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

                resultCreateModel.State = "Completed";

                resultCreateModel.AutomatedTestType = testType;

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

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

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

                lock (sync)
                {
                    if (resultCreateModel.AutomatedTestId != null && _definitions.ContainsKey(resultCreateModel.AutomatedTestId))
                    {
                        TestCaseDefinition definition = _definitions[resultCreateModel.AutomatedTestId];
                        if (definition != null)
                        {
                            if (definition.Storage != null)
                            {
                                resultCreateModel.AutomatedTestStorage = definition.Storage;
                            }
                            if (definition.Priority != null)
                            {
                                resultCreateModel.TestCasePriority = definition.Priority;
                            }
                            if (definition.Owner != null)
                            {
                                resultCreateModel.Owner = definition.Owner;
                            }
                            if (definition.AutomatedTestName != null)
                            {
                                resultCreateModel.AutomatedTestName = definition.AutomatedTestName;
                            }
                        }
                    }

                    //AutomatedTestId should be a valid guid. Delaying the check to here since we use it as dictionary key above.
                    Guid automatedTestId;
                    if (!Guid.TryParse(resultCreateModel.AutomatedTestId, out automatedTestId))
                    {
                        resultCreateModel.AutomatedTestId = null;
                    }
                }

                if (resultNode.Attributes["testType"] != null && resultNode.Attributes["testType"].Value != null)
                {
                    Guid automatedTestType;
                    if (Guid.TryParse(resultNode.Attributes["testType"].Value, out automatedTestType))
                    {
                        resultCreateModel.AutomatedTestTypeId = resultNode.Attributes["testType"].Value;
                    }
                }

                resultCreateModel.RunBy = _runUserIdRef;

                if (resultCreateModel.Outcome.Equals("Failed"))
                {
                    XmlNode errorMessage, errorStackTrace, consoleLog;

                    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.ConsoleLog = consoleLog.InnerText;
                    }
                }

                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.Attachments = resulLeveltAttachments.ToArray();

                lock (sync)
                {
                    //Mandatory fields. Skip if they are not available.
                    if (!string.IsNullOrEmpty(resultCreateModel.AutomatedTestName) && !string.IsNullOrEmpty(resultCreateModel.TestCaseTitle))
                    {
                        results.Add(resultCreateModel);
                    }
                }
            });

            return(results);
        }
예제 #2
0
        private List <TestCaseResultData> ReadActualResults(XmlNodeList resultsNodes, TestType testType)
        {
            List <TestCaseResultData> results = new List <TestCaseResultData>();

            object sync = new object();

            Parallel.ForEach <XmlNode>(resultsNodes.Cast <XmlNode>(), resultNode =>
            {
                TestCaseResultData resultCreateModel = new TestCaseResultData()
                {
                    Priority = TestManagementConstants.UnspecifiedPriority,  //Priority is int type so if no priority set then its 255.
                };

                //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 = 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 ((DateTime.Compare(default(DateTime), startedDate) < 0 && DateTime.Compare(startedDate, (DateTime)SqlDateTime.MinValue) <= 0) ||
                    (DateTime.Compare(default(DateTime), completedDate) < 0 && DateTime.Compare(completedDate, (DateTime)SqlDateTime.MinValue) <= 0))
                {
                    DateTime utcNow = DateTime.UtcNow;
                    resultCreateModel.StartedDate   = utcNow;
                    resultCreateModel.CompletedDate = utcNow.AddTicks(duration.Ticks);
                }

                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.TestCaseTitle = resultNode.Attributes["testName"].Value;
                }

                resultCreateModel.State = "Completed";

                resultCreateModel.AutomatedTestType = testType.ToString();

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

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

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

                lock (sync)
                {
                    if (resultCreateModel.AutomatedTestId != null && _definitions.ContainsKey(resultCreateModel.AutomatedTestId))
                    {
                        TestCaseDefinition definition = _definitions[resultCreateModel.AutomatedTestId];
                        if (definition != null)
                        {
                            if (definition.Storage != null)
                            {
                                resultCreateModel.AutomatedTestStorage = definition.Storage;
                            }
                            if (definition.Priority != null)
                            {
                                resultCreateModel.Priority = !string.IsNullOrEmpty(definition.Priority) ? Convert.ToInt32(definition.Priority) : TestManagementConstants.UnspecifiedPriority;
                            }
                            if (definition.Owner != null)
                            {
                                resultCreateModel.Owner = definition.Owner;
                            }
                            if (definition.AutomatedTestName != null)
                            {
                                resultCreateModel.AutomatedTestName = definition.AutomatedTestName;
                            }
                        }
                    }

                    //AutomatedTestId should be a valid guid. Delaying the check to here since we use it as dictionary key above.
                    Guid automatedTestId;
                    if (!Guid.TryParse(resultCreateModel.AutomatedTestId, out automatedTestId))
                    {
                        resultCreateModel.AutomatedTestId = null;
                    }
                }

                if (resultNode.Attributes["testType"] != null && resultNode.Attributes["testType"].Value != null)
                {
                    Guid automatedTestType;
                    if (Guid.TryParse(resultNode.Attributes["testType"].Value, out automatedTestType))
                    {
                        resultCreateModel.AutomatedTestTypeId = resultNode.Attributes["testType"].Value;
                    }
                }

                resultCreateModel.RunBy = _runUserIdRef;

                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"]?.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"]?.Value != null)
                        {
                            resulLeveltAttachments.Add(Path.Combine(_attachmentLocation, executionId, resultFileNode.Attributes["path"].Value));
                        }
                    }
                }

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

                AddVariousLogsForResultIfOutcomeIsFailed(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.TestCaseSubResultData = new List <TestCaseSubResultData>();

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

                lock (sync)
                {
                    //Mandatory fields. Skip if they are not available.
                    if (!string.IsNullOrEmpty(resultCreateModel.AutomatedTestName) && !string.IsNullOrEmpty(resultCreateModel.TestCaseTitle))
                    {
                        results.Add(resultCreateModel);
                    }
                }
            });

            return(results);
        }
예제 #3
0
        private List <TestCaseResultData> ReadActualResults(XmlNodeList resultsNodes, string testType)
        {
            List <TestCaseResultData> results = new List <TestCaseResultData>();

            object sync = new object();

            Parallel.ForEach <XmlNode>(resultsNodes.Cast <XmlNode>(), resultNode =>
            {
                TestCaseResultData resultCreateModel = new TestCaseResultData()
                {
                    Priority = TestManagementConstants.UnspecifiedPriority,  //Priority is int type so if no priority set then its 255.
                };

                //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 = 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.TestCaseTitle = resultNode.Attributes["testName"].Value;
                }

                resultCreateModel.State = "Completed";

                resultCreateModel.AutomatedTestType = testType;

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

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

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

                lock (sync)
                {
                    if (resultCreateModel.AutomatedTestId != null && _definitions.ContainsKey(resultCreateModel.AutomatedTestId))
                    {
                        TestCaseDefinition definition = _definitions[resultCreateModel.AutomatedTestId];
                        if (definition != null)
                        {
                            if (definition.Storage != null)
                            {
                                resultCreateModel.AutomatedTestStorage = definition.Storage;
                            }
                            if (definition.Priority != null)
                            {
                                resultCreateModel.Priority = !string.IsNullOrEmpty(definition.Priority) ? Convert.ToInt32(definition.Priority) : TestManagementConstants.UnspecifiedPriority;
                            }
                            if (definition.Owner != null)
                            {
                                resultCreateModel.Owner = definition.Owner;
                            }
                            if (definition.AutomatedTestName != null)
                            {
                                resultCreateModel.AutomatedTestName = definition.AutomatedTestName;
                            }
                        }
                    }

                    //AutomatedTestId should be a valid guid. Delaying the check to here since we use it as dictionary key above.
                    Guid automatedTestId;
                    if (!Guid.TryParse(resultCreateModel.AutomatedTestId, out automatedTestId))
                    {
                        resultCreateModel.AutomatedTestId = null;
                    }
                }

                if (resultNode.Attributes["testType"] != null && resultNode.Attributes["testType"].Value != null)
                {
                    Guid automatedTestType;
                    if (Guid.TryParse(resultNode.Attributes["testType"].Value, out automatedTestType))
                    {
                        resultCreateModel.AutomatedTestTypeId = resultNode.Attributes["testType"].Value;
                    }
                }

                resultCreateModel.RunBy = _runUserIdRef;

                if (resultCreateModel.Outcome.Equals("Failed"))
                {
                    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.ConsoleLog = consoleLog.InnerText;
                    }

                    // standard error
                    if ((standardError = resultNode.SelectSingleNode("./Output/StdErr")) != null && !string.IsNullOrWhiteSpace(standardError.InnerText))
                    {
                        resultCreateModel.StandardError = standardError.InnerText;
                    }
                }

                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.Attachments = resulLeveltAttachments.ToArray();

                lock (sync)
                {
                    //Mandatory fields. Skip if they are not available.
                    if (!string.IsNullOrEmpty(resultCreateModel.AutomatedTestName) && !string.IsNullOrEmpty(resultCreateModel.TestCaseTitle))
                    {
                        results.Add(resultCreateModel);
                    }
                }
            });

            return(results);
        }