/// <summary>
        ///     Called when a test result is received.
        /// </summary>
        private void TestResultHandler(object sender, TestResultEventArgs e)
        {
            machineName = e.Result.ComputerName;

            var testCase = new TestCase
            {
                Name      = e.Result.TestCase.DisplayName,
                Classname = GetClassName(e.Result.TestCase.FullyQualifiedName),
                Status    = e.Result.Outcome.ToString(),
                Time      = e.Result.Duration.TotalSeconds,
            };

            if (e.Result.Outcome == TestOutcome.Skipped)
            {
                var methodInfo  = this.GetTestMethodInfo(e.Result);
                var description = this.GetDescription(methodInfo);

                testCase.Skipped = new Skipped
                {
                    Text    = "Yes",
                    Message = description ?? "---EMPTY---"
                };
            }

            IncludeErrorsAndFailures(e, testCase);
            this.PrintSourceCodeInformation(e, testCase);
            IncludeMessages(e, testCase);

            testCases.Enqueue(testCase);
        }
 private static void IncludeMessages(TestResultEventArgs e, TestCase testCase)
 {
     foreach (TestResultMessage msg in e.Result.Messages)
     {
         if (msg.Category == "StdOutMsgs")
         {
             if (testCase.SystemOut == null)
             {
                 testCase.SystemOut = string.Empty;
             }
             testCase.SystemOut += msg.Text + Environment.NewLine;
         }
         else if (msg.Category == "StdErrMsgs")
         {
             if (testCase.SystemErr == null)
             {
                 testCase.SystemErr = string.Empty;
             }
             testCase.SystemErr += msg.Text + Environment.NewLine;
         }
         else
         {
             testCase.SystemOut += msg.Category + ": " + msg.Text + Environment.NewLine;
         }
     }
 }
        private static void IncludeErrorsAndFailures(TestResultEventArgs e, TestCase testCase)
        {
            var errorMessage    = e.Result.ErrorMessage ?? string.Empty;
            var errorStackTrace = e.Result.ErrorStackTrace ?? string.Empty;

            if (string.IsNullOrWhiteSpace(errorMessage) && string.IsNullOrWhiteSpace(errorStackTrace))
            {
                return;
            }

            var err = new List <ErrorOrFailure>
            {
                new ErrorOrFailure
                {
                    Message = new string(errorMessage.Select(ch => XmlConvert.IsXmlChar(ch) ? ch : '?').ToArray()),
                    Text    = new string(errorStackTrace.Select(ch => XmlConvert.IsXmlChar(ch) ? ch : '?').ToArray())
                }
            };

            if (e.Result.Outcome == TestOutcome.Failed)
            {
                testCase.Failures = err;
            }
            else
            {
                testCase.Errors = err;
            }
        }
        /// <summary>
        ///     Called when a test result is received.
        /// </summary>
        private void TestResultHandler(object sender, TestResultEventArgs e)
        {
            machineName = e.Result.ComputerName;

            var testCase = new TestCase
            {
                Name      = e.Result.TestCase.DisplayName,
                Classname = GetClassName(e.Result.TestCase.FullyQualifiedName),
                Status    = e.Result.Outcome.ToString(),
                Time      = e.Result.Duration.TotalSeconds,
                Skipped   = (e.Result.Outcome == TestOutcome.Skipped).ToString()
            };

            IncludeErrorsAndFailures(e, testCase);
            PrintSourceCodeInformation(e, testCase);
            IncludeMessages(e, testCase);

            testCases.Enqueue(testCase);
        }
        private void PrintSourceCodeInformation(TestResultEventArgs e, TestCase testCase)
        {
            if (startupParameters.ContainsKey("IncludeSourceFileInfo") &&
                Convert.ToBoolean(startupParameters["IncludeSourceFileInfo"]))
            {
                var systemOut = new StringBuilder();
                systemOut.AppendLine("------------- Source code information -------------");
                systemOut.AppendLine("Source: " + e.Result.TestCase.GetPropertyValue(TestCaseProperties.Source, "N/A"));
                systemOut.AppendLine("Code file path: " +
                                     e.Result.TestCase.GetPropertyValue(TestCaseProperties.CodeFilePath, "N/A"));
                systemOut.AppendLine("Line number: " +
                                     e.Result.TestCase.GetPropertyValue(TestCaseProperties.LineNumber, "N/A"));
                systemOut.AppendLine("Started: " + e.Result.GetPropertyValue(TestResultProperties.StartTime, "N/A"));
                systemOut.AppendLine("Finished: " + e.Result.GetPropertyValue(TestResultProperties.EndTime, "N/A"));
                testCase.SystemOut = systemOut.ToString();

                if (e.Result.Messages.Any(m => m.Category == "StdOutMsgs"))
                {
                    systemOut.AppendLine("------------- Stdout -------------");
                }
            }
        }
 private static void IncludeErrorsAndFailures(TestResultEventArgs e, TestCase testCase)
 {
     if (!string.IsNullOrWhiteSpace(e.Result.ErrorMessage) ||
         !string.IsNullOrWhiteSpace(e.Result.ErrorStackTrace))
     {
         var err = new List<ErrorOrFailure>
         {
             new ErrorOrFailure
             {
                 Message = new string(e.Result.ErrorMessage.Select(ch => XmlConvert.IsXmlChar(ch) ? ch : '?').ToArray()),
                 Text = new string(e.Result.ErrorStackTrace.Select(ch => XmlConvert.IsXmlChar(ch) ? ch : '?').ToArray())
             }
         };
         if (e.Result.Outcome == TestOutcome.Failed)
         {
             testCase.Failures = err;
         }
         else
         {
             testCase.Errors = err;
         }
     }
 }
 private static void IncludeMessages(TestResultEventArgs e, TestCase testCase)
 {
     foreach (TestResultMessage msg in e.Result.Messages)
     {
         if (msg.Category == "StdOutMsgs")
         {
             if (testCase.SystemOut == null) testCase.SystemOut = string.Empty;
             testCase.SystemOut += msg.Text + Environment.NewLine;
         }
         else if (msg.Category == "StdErrMsgs")
         {
             if (testCase.SystemErr == null) testCase.SystemErr = string.Empty;
             testCase.SystemErr += msg.Text + Environment.NewLine;
         }
         else
         {
             testCase.SystemOut += msg.Category + ": " + msg.Text + Environment.NewLine;
         }
     }
 }
        /// <summary>
        ///     Called when a test result is received.
        /// </summary>
        private void TestResultHandler(object sender, TestResultEventArgs e)
        {
            machineName = e.Result.ComputerName;

            var testCase = new TestCase
            {
                Name = e.Result.TestCase.DisplayName,
                Classname = GetClassName(e.Result.TestCase.FullyQualifiedName),
                Status = e.Result.Outcome.ToString(),
                Time = e.Result.Duration.TotalSeconds,
                Skipped = (e.Result.Outcome == TestOutcome.Skipped).ToString()
            };

            IncludeErrorsAndFailures(e, testCase);
            PrintSourceCodeInformation(e, testCase);
            IncludeMessages(e, testCase);

            testCases.Enqueue(testCase);
        }
        private void PrintSourceCodeInformation(TestResultEventArgs e, TestCase testCase)
        {
            if (startupParameters.ContainsKey("IncludeSourceFileInfo") &&
                Convert.ToBoolean(startupParameters["IncludeSourceFileInfo"]))
            {
                var systemOut = new StringBuilder();
                systemOut.AppendLine("------------- Source code information -------------");
                systemOut.AppendLine("Source: " + e.Result.TestCase.GetPropertyValue(TestCaseProperties.Source, "N/A"));
                systemOut.AppendLine("Code file path: " +
                                     e.Result.TestCase.GetPropertyValue(TestCaseProperties.CodeFilePath, "N/A"));
                systemOut.AppendLine("Line number: " +
                                     e.Result.TestCase.GetPropertyValue(TestCaseProperties.LineNumber, "N/A"));
                systemOut.AppendLine("Started: " + e.Result.GetPropertyValue(TestResultProperties.StartTime, "N/A"));
                systemOut.AppendLine("Finished: " + e.Result.GetPropertyValue(TestResultProperties.EndTime, "N/A"));
                testCase.SystemOut = systemOut.ToString();

                if (e.Result.Messages.Any(m => m.Category == "StdOutMsgs"))
                {
                    systemOut.AppendLine("------------- Stdout -------------");
                }
            }
        }