<commit_before>﻿namespace Fixie.Execution.Listeners
{
    using System;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Xml.Linq;
    using Execution;

    public static class XUnitXml
    {
        public static void Save(Report report, string path)
        {
            var xDocument = Transform(report);

            var directory = Path.GetDirectoryName(path);

            if (String.IsNullOrEmpty(directory))
                return;

            Directory.CreateDirectory(directory);

            using (var stream = new FileStream(path, FileMode.Create))
            using (var writer = new StreamWriter(stream))
                xDocument.Save(writer, SaveOptions.None);
        }

        public static XDocument Transform(Report report)
        {
            var now = DateTime.UtcNow;

            return new XDocument(
                new XElement("assemblies",
                    new XElement("assembly",
                        new XAttribute("name", report.Assembly.Location),
                        new XAttribute("run-date", now.ToString("yyyy-MM-dd")),
                        new XAttribute("run-time", now.ToString("HH:mm:ss")),
                        new XAttribute("configFile", ConfigFile),
                        new XAttribute("time", Seconds(report.Duration)),
                        new XAttribute("total", report.Total),
                        new XAttribute("passed", report.Passed),
                        new XAttribute("failed", report.Failed),
                        new XAttribute("skipped", report.Skipped),
                        new XAttribute("environment", $"{IntPtr.Size * 8}-bit .NET {Framework}"),
                        new XAttribute("test-framework", Fixie.Framework.Version),
                        report.Classes.Select(Class))));
        }

#if NET452
        static string ConfigFile => AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
        static string Framework => Environment.Version.ToString();
#else
        static string ConfigFile => "N/A";
        static string Framework => "Core";
#endif

        static XElement Class(ClassReport classReport)
        {
            return new XElement("class",
                new XAttribute("time", Seconds(classReport.Duration)),
                new XAttribute("name", classReport.Class.FullName),
                new XAttribute("total", classReport.Failed + classReport.Passed + classReport.Skipped),
                new XAttribute("passed", classReport.Passed),
                new XAttribute("failed", classReport.Failed),
                new XAttribute("skipped", classReport.Skipped),
                classReport.Cases.Select(Case));
        }

        static XElement Case(CaseCompleted message)
        {
            var @case = new XElement("test",
                new XAttribute("name", message.Name),
                new XAttribute("type", message.Class.FullName),
                new XAttribute("method", message.Method.Name),
                new XAttribute("result",
                    message.Status == CaseStatus.Failed
                        ? "Fail"
                        : message.Status == CaseStatus.Passed
                            ? "Pass"
                            : "Skip"));

            if (message.Status != CaseStatus.Skipped)
                @case.Add(new XAttribute("time", Seconds(message.Duration)));

            if (message.Status == CaseStatus.Skipped)
            {
                var skip = (CaseSkipped)message;
                if (skip.Reason != null)
                    @case.Add(new XElement("reason", new XElement("message", new XCData(skip.Reason))));
            }

            if (message.Status == CaseStatus.Failed)
            {
                var exception = ((CaseFailed)message).Exception;
                @case.Add(
                    new XElement("failure",
                        new XAttribute("exception-type", exception.Type),
                        new XElement("message", new XCData(exception.Message)),
                        new XElement("stack-trace", new XCData(exception.StackTrace))));
            }

            return @case;
        }

        static string Seconds(TimeSpan duration)
        {
            //The XML Schema spec requires decimal values to use a culture-ignorant format.
            return duration.TotalSeconds.ToString("0.000", NumberFormatInfo.InvariantInfo);
        }
    }
}<commit_msg>Simplify conditional logic within XUnitXml.<commit_after>﻿namespace Fixie.Execution.Listeners
{
    using System;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Xml.Linq;
    using Execution;

    public static class XUnitXml
    {
        public static void Save(Report report, string path)
        {
            var xDocument = Transform(report);

            var directory = Path.GetDirectoryName(path);

            if (String.IsNullOrEmpty(directory))
                return;

            Directory.CreateDirectory(directory);

            using (var stream = new FileStream(path, FileMode.Create))
            using (var writer = new StreamWriter(stream))
                xDocument.Save(writer, SaveOptions.None);
        }

        public static XDocument Transform(Report report)
        {
            var now = DateTime.UtcNow;

            return new XDocument(
                new XElement("assemblies",
                    new XElement("assembly",
                        new XAttribute("name", report.Assembly.Location),
                        new XAttribute("run-date", now.ToString("yyyy-MM-dd")),
                        new XAttribute("run-time", now.ToString("HH:mm:ss")),
                        new XAttribute("configFile", ConfigFile),
                        new XAttribute("time", Seconds(report.Duration)),
                        new XAttribute("total", report.Total),
                        new XAttribute("passed", report.Passed),
                        new XAttribute("failed", report.Failed),
                        new XAttribute("skipped", report.Skipped),
                        new XAttribute("environment", $"{IntPtr.Size * 8}-bit .NET {Framework}"),
                        new XAttribute("test-framework", Fixie.Framework.Version),
                        report.Classes.Select(Class))));
        }

#if NET452
        static string ConfigFile => AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
        static string Framework => Environment.Version.ToString();
#else
        static string ConfigFile => "N/A";
        static string Framework => "Core";
#endif

        static XElement Class(ClassReport classReport)
        {
            return new XElement("class",
                new XAttribute("time", Seconds(classReport.Duration)),
                new XAttribute("name", classReport.Class.FullName),
                new XAttribute("total", classReport.Failed + classReport.Passed + classReport.Skipped),
                new XAttribute("passed", classReport.Passed),
                new XAttribute("failed", classReport.Failed),
                new XAttribute("skipped", classReport.Skipped),
                classReport.Cases.Select(Case));
        }

        static XElement Case(CaseCompleted message)
        {
            if (message is CaseSkipped skipped)
                return Case(skipped);

            if (message is CasePassed passed)
                return Case(passed);

            if (message is CaseFailed failed)
                return Case(failed);

            return null;
        }

        static XElement Case(CaseSkipped message)
            => new XElement("test",
                new XAttribute("name", message.Name),
                new XAttribute("type", message.Class.FullName),
                new XAttribute("method", message.Method.Name),
                new XAttribute("result", "Skip"),
                message.Reason != null
                    ? new XElement("reason", new XElement("message", new XCData(message.Reason)))
                    : null);

        static XElement Case(CasePassed message)
            => new XElement("test",
                new XAttribute("name", message.Name),
                new XAttribute("type", message.Class.FullName),
                new XAttribute("method", message.Method.Name),
                new XAttribute("result", "Pass"),
                new XAttribute("time", Seconds(message.Duration)));

        static XElement Case(CaseFailed message)
            => new XElement("test",
                new XAttribute("name", message.Name),
                new XAttribute("type", message.Class.FullName),
                new XAttribute("method", message.Method.Name),
                new XAttribute("result", "Fail"),
                new XAttribute("time", Seconds(message.Duration)),
                Failure(message.Exception));

        static XElement Failure(CompoundException exception)
        {
            return new XElement("failure",
                new XAttribute("exception-type", exception.Type),
                new XElement("message", new XCData(exception.Message)),
                new XElement("stack-trace", new XCData(exception.StackTrace)));
        }

        static string Seconds(TimeSpan duration)
        {
            //The XML Schema spec requires decimal values to use a culture-ignorant format.
            return duration.TotalSeconds.ToString("0.000", NumberFormatInfo.InvariantInfo);
        }
    }
}
{'fraction_non_alphanumeric': 0.10383437202915391, 'fraction_numerical': 0.0016900813351642548, 'mean_word_length': 1.7814336075205641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '400534', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2176, 'n_words': 522}