-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathHtmlTransformerTests.cs
More file actions
102 lines (88 loc) · 3.4 KB
/
HtmlTransformerTests.cs
File metadata and controls
102 lines (88 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests;
[TestClass]
public class HtmlTransformerTests
{
[TestMethod]
public void TransformShouldHandleSpecialCharactersWithoutThrowingException()
{
// Create a simple XML with special characters that could cause issues
var xmlContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<TestRun>
<Results>
<UnitTestResult testName=""TestWithSpecialChars"" outcome=""Failed"">
<Output>
<ErrorInfo>
<Message>Test failed with special chars: </Message>
<StackTrace>Stack trace with special chars: </StackTrace>
</ErrorInfo>
</Output>
</UnitTestResult>
</Results>
</TestRun>";
var xmlFile = Path.GetTempFileName();
var htmlFile = Path.ChangeExtension(xmlFile, ".html");
try
{
File.WriteAllText(xmlFile, xmlContent, Encoding.UTF8);
var transformer = new HtmlTransformer();
// This should not throw an exception, even with special characters
try
{
transformer.Transform(xmlFile, htmlFile);
}
catch (Exception ex)
{
Assert.Fail($"HtmlTransformer.Transform should not throw an exception with special characters: {ex.Message}");
}
// Verify that HTML file was created
Assert.IsTrue(File.Exists(htmlFile), "HTML file should be created");
// Verify that HTML file has content
var htmlContent = File.ReadAllText(htmlFile);
Assert.IsFalse(string.IsNullOrEmpty(htmlContent), "HTML content should not be empty");
}
finally
{
if (File.Exists(xmlFile)) File.Delete(xmlFile);
if (File.Exists(htmlFile)) File.Delete(htmlFile);
}
}
[TestMethod]
public void TransformShouldCreateValidHtmlOutput()
{
// Create a basic XML structure
var xmlContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<TestRun>
<Results>
<UnitTestResult testName=""SimpleTest"" outcome=""Passed"">
<Output>
<StdOut>Test output</StdOut>
</Output>
</UnitTestResult>
</Results>
</TestRun>";
var xmlFile = Path.GetTempFileName();
var htmlFile = Path.ChangeExtension(xmlFile, ".html");
try
{
File.WriteAllText(xmlFile, xmlContent, Encoding.UTF8);
var transformer = new HtmlTransformer();
transformer.Transform(xmlFile, htmlFile);
// Verify that HTML file was created and has content
Assert.IsTrue(File.Exists(htmlFile), "HTML file should be created");
var htmlContent = File.ReadAllText(htmlFile);
Assert.IsFalse(string.IsNullOrEmpty(htmlContent), "HTML content should not be empty");
}
finally
{
if (File.Exists(xmlFile)) File.Delete(xmlFile);
if (File.Exists(htmlFile)) File.Delete(htmlFile);
}
}
}