using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
using System.Text.RegularExpressions;
public TestResults(string result, string message) => (Result, Message) = (result, message);
public string Result { get; }
public string Message { get; }
private static List<TestResults> GetTestAutomationExecutionResult(string filePath)
=> GetTestAutomationExecutionResult(XElement.Load(filePath));
private static List<TestResults> GetTestAutomationExecutionResult(XElement xelement)
var query = from e in xelement.Descendants()
where e.Name.LocalName == "test"
let r = e.Attribute("result").Value
let m = r == "Fail" ? e.Elements("failure").Elements("message").FirstOrDefault()?.Value : ""
select new TestResults(r, m);
public static void Test()
var xelement = XElement.Parse(GetXml());
Console.WriteLine(xelement);
var list = GetTestAutomationExecutionResult(xelement);
foreach (var item in list)
Console.WriteLine("{0}: {1}", item.Result, item.Message);
static string GetXml() => @"<?xml version=""1.0"" encoding=""utf-8""?>
<assemblies timestamp=""07/31/2018 14:58:48"">
<assembly name=""C:\Users\bf\Documents\Visual Studio 2015\Projects\xUnitDemo\xUnitDemo\bin\Debug\xUnitDemo.DLL"" environment=""64-bit .NET 4.0.30319.42000 [collection-per-class, parallel (1 threads)]"" test-framework=""xUnit.net 2.3.1.3858"" run-date=""2018-07-31"" run-time=""14:58:47"" config-file=""C:\Users\bf\Documents\Visual Studio 2015\Projects\xUnitDemo\packages\xunit.runner.console.2.4.0\tools\net452\xunit.console.exe.Config"" total=""15"" passed=""14"" failed=""1"" skipped=""0"" time=""0.257"" errors=""0"">
<collection total=""2"" passed=""1"" failed=""1"" skipped=""0"" name=""Test collection for xUnitDemo.SimpleTests"" time=""0.070"">
<test name=""xUnitDemo.SimpleTests.PassingTest"" type=""xUnitDemo.SimpleTests"" method=""PassingTest"" time=""0.0636741"" result=""Pass"">
<trait name=""test"" value=""test"" />
<trait name=""requirement"" value=""test"" />
<trait name=""labels"" value=""test"" />
<test name=""xUnitDemo.SimpleTests.FailingTest"" type=""xUnitDemo.SimpleTests"" method=""FailingTest"" time=""0.0059474"" result=""Fail"">
<failure exception-type=""Xunit.Sdk.EqualException"">
<message><![CDATA[Assert.Equal() Failure\r\nExpected: 5\r\nActual: 4]]></message>
<stack-trace><![CDATA[ at xUnitDemo.SimpleTests.FailingTest() in C:\Users\smsf\documents\visual studio 2015\Projects\xUnitDemo\xUnitDemo\SimpleTests.cs:line 30]]></stack-trace>
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];