Esempio n. 1
0
        private void PublishTestResult(Dictionary <string, string> testResult)
        {
            var jsonSb = new StringBuilder();

            jsonSb.Append("{");

            bool firstItem = true;

            foreach (var field in testResult)
            {
                if (!firstItem)
                {
                    jsonSb.Append(",");
                }
                firstItem = false;
                jsonSb.Append("\"" + field.Key + "\": ");
                JsonEscape.SerializeString(field.Value, jsonSb);
            }

            jsonSb.Append("}");

            queue.Enqueue(jsonSb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Called when a test result is received.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The eventArgs.
        /// </param>
        private void TestResultHandler(object sender, TestResultEventArgs e)
        {
            var name     = e.Result.TestCase.FullyQualifiedName;
            var filename = string.IsNullOrEmpty(e.Result.TestCase.Source) ? string.Empty : Path.GetFileName(e.Result.TestCase.Source);
            var outcome  = e.Result.Outcome.ToString();

            var testResult = new Dictionary <string, string>();

            testResult.Add("name", name);
            testResult.Add("Framework", e.Result.TestCase.ExecutorUri.ToString());
            testResult.Add("Outcome", outcome);

            if (!string.IsNullOrEmpty(filename))
            {
                testResult.Add("FileName", filename);
            }

            if (e.Result.Outcome == TestOutcome.Passed || e.Result.Outcome == TestOutcome.Failed)
            {
                var duration = Convert.ToInt32(e.Result.Duration.TotalMilliseconds);

                var errorMessage    = e.Result.ErrorMessage;
                var errorStackTrace = e.Result.ErrorStackTrace;

                var stdErr = new StringBuilder();
                var stdOut = new StringBuilder();

                foreach (var m in e.Result.Messages)
                {
                    if (TestResultMessage.StandardOutCategory.Equals(m.Category, StringComparison.OrdinalIgnoreCase))
                    {
                        stdOut.AppendLine(m.Text);
                    }
                    else if (TestResultMessage.StandardErrorCategory.Equals(m.Category, StringComparison.OrdinalIgnoreCase))
                    {
                        stdErr.AppendLine(m.Text);
                    }
                }

                testResult.Add("Duration", duration.ToString(CultureInfo.InvariantCulture));

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    testResult.Add("ErrorMessage", errorMessage);
                }
                if (!string.IsNullOrEmpty(errorStackTrace))
                {
                    testResult.Add("ErrorStackTrace", errorStackTrace);
                }
                if (!string.IsNullOrEmpty(stdOut.ToString()))
                {
                    testResult.Add("StdOut", stdOut.ToString());
                }
                if (!string.IsNullOrEmpty(stdErr.ToString()))
                {
                    testResult.Add("StdErr", stdErr.ToString());
                }
            }

            queue.Enqueue(testResult);
        }