Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class HtmlTransformer : IHtmlTransformer
public HtmlTransformer()
{
_xslTransform = new XslCompiledTransform();
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException()));
_xslTransform.Load(XmlReader.Create(GetType().Assembly.GetManifestResourceStream("Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Html.xslt") ?? throw new InvalidOperationException(), new XmlReaderSettings { CheckCharacters = false }));
}

/// <summary>
Expand All @@ -33,7 +33,9 @@ public void Transform(string xmlFile, string htmlFile)
// for example &#xFFFF;. DCS will load them, but for XSL to load them here we need to pass it
// a reader that we've configured to be tolerant of such references.
using XmlReader xr = XmlReader.Create(xmlFile, new XmlReaderSettings() { CheckCharacters = false });
using XmlWriter xw = XmlWriter.Create(htmlFile, new XmlWriterSettings() { CheckCharacters = false });

// Use output settings from the xslt, especially the output method, which is HTML, which avoids outputting broken <div /> tags.
using XmlWriter xw = XmlWriter.Create(htmlFile, _xslTransform.OutputSettings);

_xslTransform.Transform(xr, xw);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ public void HtmlLoggerWithFriendlyNameContainsExpectedContent(RunnerInfo runnerI
InvokeVsTest(arguments);

var htmlLogFilePath = Path.Combine(TempDirectory.Path, htmlFileName);
XmlDocument report = new();
report.Load(htmlLogFilePath);
XmlDocument report = LoadReport(htmlLogFilePath);

AssertExpectedHtml(report.DocumentElement!);
}

private static XmlDocument LoadReport(string htmlLogFilePath)
{
// XML reader cannot handle <br> tags because they are not closed, and hence are not valid XML.
// They are correct HTML though, so we patch it here.
var text = File.ReadAllText(htmlLogFilePath).Replace("<br>", "<br/>");
var report = new XmlDocument();
report.Load(new StringReader(text));
return report;
}

[TestMethod]
[NetCoreTargetFrameworkDataSource]
public void TrxLoggerWithExecutorUriShouldProperlyOverwriteFile(RunnerInfo runnerInfo)
Expand Down