Example #1
0
        private static JObject CreateAppVeyorObjectFromTestResult(
            String testFramework,
            String testNS,
            String testName,
            XElement testMethod,
            XElement unitTestResult
            )
        {
            var retVal = new JObject(
                new JProperty("testName", testName),
                new JProperty("testFramework", testFramework),
                new JProperty("fileName", Path.GetFileName(testMethod.Attribute("codeBase").Value))
                );

            retVal.AddAttributeIfPresent(
                unitTestResult,
                "outcome",
                null,
                outcome =>
            {
                if (!Char.IsUpper(outcome[0]))
                {
                    // Capitalize first letter
                    var chars = outcome.ToCharArray();
                    chars[0]  = Char.ToUpper(chars[0]);
                    outcome   = new String(chars);
                }
                return(outcome);
            });
            retVal.AddAttributeIfPresent(
                unitTestResult,
                "duration",
                "durationMilliseconds",
                duration => TimeSpan.Parse(duration).TotalMilliseconds.ToString("F0")
                );

            var output = unitTestResult.Element(XName.Get("Output", testNS));

            if (output != null)
            {
                retVal.AddTextFromChild(output, "StdOut", testNS, null);
                retVal.AddTextFromChild(output, "StdErr", testNS, null);
                var errorInfo = output.Element(XName.Get("ErrorInfo", testNS));
                if (errorInfo != null)
                {
                    retVal.AddTextFromChild(errorInfo, "Message", testNS, "ErrorMessage");
                    retVal.AddTextFromChild(errorInfo, "StackTrace", testNS, "ErrorStackTrace");
                }
            }

            return(retVal);
        }