private static XElement CreateErrorElement(TestResultInfo result)
        {
            string errorMessage = result.ErrorMessage;

            int    indexOfErrorType = errorMessage.IndexOf('(');
            string errorType        = string.Empty;

            errorTypeKeyValuePair.TryGetValue(errorMessage.Substring(1, indexOfErrorType - 2), out errorType);
            errorMessage = errorMessage.Substring(indexOfErrorType + 1);

            int    indexOfName = errorMessage.IndexOf(')');
            string name        = errorMessage.Substring(0, indexOfName);

            errorMessage = errorMessage.Substring(indexOfName + 4);

            int    indexOfExceptionType = errorMessage.IndexOf(':');
            string exceptionType        = errorMessage.Substring(0, indexOfExceptionType - 1);

            XElement errorElement = new XElement("error");

            errorElement.SetAttributeValue("type", errorType);
            errorElement.SetAttributeValue("name", name);

            errorElement.Add(CreateFailureElement(exceptionType, errorMessage, result.ErrorStackTrace));

            return(errorElement);
        }
        private static void FillInReasonsOfSkippedTests(List <TestResultInfo> resultsGettingFilled, List <string> messageList)
        {
            // process all the messages collected during test run: If one ends with [SKIP], then the next message contains the
            // skip reason.
            Dictionary <string, string> skippedTestNamesWithReason = new Dictionary <string, string>();

            for (int i = 0; i < messageList.Count; i++)
            {
                string message = messageList[i];
                if (!message.EndsWith("[SKIP]"))
                {
                    continue;
                }

                // remove the gunk ...
                int    from     = message.IndexOf("]") + 1;
                int    to       = message.LastIndexOf("[") - from;
                string testName = message.Substring(from, to).Trim();

                string reasonMessage = messageList[++i];
                from = reasonMessage.IndexOf("]") + 1;
                string reason = reasonMessage.Substring(from).Trim();

                skippedTestNamesWithReason.Add(testName, reason);
            }

            foreach (var testWithReason in skippedTestNamesWithReason)
            {
                TestResultInfo result = resultsGettingFilled.Single(x => x.Name == testWithReason.Key);

                // TODO: Defining a new category for now...
                result.Messages.Add(new TestResultMessage("skipReason", testWithReason.Value));
            }
        }
        private static XElement CreateTestElement(TestResultInfo result)
        {
            var element = new XElement(
                "test",
                new XAttribute("name", result.TestCase.DisplayName.ReplaceInvalidXmlChar()),
                new XAttribute("type", result.FullTypeName),
                new XAttribute("method", result.Method),
                new XAttribute("time", result.Duration.TotalSeconds.ToString("F7", CultureInfo.InvariantCulture)),
                new XAttribute("result", OutcomeToString(result.Outcome)));

            StringBuilder stdOut = new StringBuilder();

            foreach (var m in result.Messages)
            {
                if (TestResultMessage.StandardOutCategory.Equals(m.Category, StringComparison.OrdinalIgnoreCase))
                {
                    stdOut.AppendLine(m.Text);
                }
                else if (m.Category == "skipReason")
                {
                    // Using the self-defined category skipReason for now
                    element.Add(new XElement("reason", new XCData(m.Text.ReplaceInvalidXmlChar())));
                }
            }

            if (!string.IsNullOrWhiteSpace(stdOut.ToString()))
            {
                element.Add(new XElement("output", stdOut.ToString().ReplaceInvalidXmlChar()));
            }

            var fileName = result.TestCase.CodeFilePath;

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                element.Add(new XElement("source-file", fileName));
                element.Add(new XElement("source-line", result.TestCase.LineNumber));
            }

            if (result.Outcome == TestOutcome.Failed)
            {
                element.Add(new XElement(
                                "failure",
                                new XElement("message", result.ErrorMessage.ReplaceInvalidXmlChar()),
                                new XElement("stack-trace", result.ErrorStackTrace.ReplaceInvalidXmlChar())));
            }

            if (result.TestCase.Traits != null)
            {
                var traits = from trait in result.TestCase.Traits
                             select new XElement("trait", new XAttribute("name", trait.Name), new XAttribute("value", trait.Value));
                element.Add(new XElement("traits", traits));
            }

            return(element);
        }
Example #4
0
            public override bool Equals(object obj)
            {
                if (obj is TestResultInfo)
                {
                    TestResultInfo objectToCompare = (TestResultInfo)obj;
                    if (string.Compare(this.ErrorMessage, objectToCompare.ErrorMessage) == 0 && string.Compare(this.ErrorStackTrace, objectToCompare.ErrorStackTrace) == 0)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        private static bool IsError(TestResultInfo result)
        {
            string errorMessage = result.ErrorMessage;

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                foreach (var m in errorTypes)
                {
                    if (errorMessage.IndexOf(m) >= 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }