Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c16a231

Browse files
clarkis117Paulo Janotti
authored andcommitted
Simplify regression test to not use compiled xslt (#28440)
Fixes #28299
1 parent 1a44ece commit c16a231

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/System.Private.Xml/tests/XmlWriter/WriteWithEncoding.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,33 @@ public static void WriteWithEncoding()
4242
[Fact]
4343
public void WriteWithUtf32EncodingNoBom()
4444
{
45-
// Given
46-
var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<breakfast_menu>\n <food>\n <name>Belgian Waffles</name>\n <price>$5.95</price>\n <description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>\n <calories>650</calories>\n </food>\n <food>\n <name>Strawberry Belgian Waffles</name>\n <price>$7.95</price>\n <description>Light Belgian waffles covered with strawberries and whipped cream</description>\n <calories>900</calories>\n </food>\n</breakfast_menu>";
47-
var xsl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<html xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xsl:version=\"1.0\">\n <body style=\"font-family:Arial;font-size:12pt;background-color:#EEEEEE\">\n <xsl:for-each select=\"breakfast_menu/food\">\n <div style=\"background-color:teal;color:white;padding:4px\">\n <span style=\"font-weight:bold\">\n <xsl:value-of select=\"name\" />\n -\n </span>\n <xsl:value-of select=\"price\" />\n </div>\n <div style=\"margin-left:20px;margin-bottom:1em;font-size:10pt\">\n <p>\n <xsl:value-of select=\"description\" />\n <span style=\"font-style:italic\">\n (\n <xsl:value-of select=\"calories\" />\n calories per serving)\n </span>\n </p>\n </div>\n </xsl:for-each>\n </body>\n</html>";
48-
49-
// set encoding to UTF32 with no BOM
45+
//Given, encoding set to UTF32 with no BOM
5046
var settings = new XmlWriterSettings
5147
{
48+
OmitXmlDeclaration = false,
49+
ConformanceLevel = ConformanceLevel.Document,
5250
Encoding = new UTF32Encoding(false, false, true)
5351
};
5452

5553
string resultString;
56-
using (TextReader xslReader = new StringReader(xsl),
57-
xmlReader = new StringReader(xml))
54+
using (var result = new MemoryStream())
5855
{
59-
using (var result = new MemoryStream())
60-
{
61-
var xslXmlReader = XmlReader.Create(xslReader);
62-
var xmlXmlReader = XmlReader.Create(xmlReader);
63-
64-
// BOM can be written in this call
65-
var resultXmlTextWriter = XmlWriter.Create(result, settings);
56+
// BOM can be written in this call
57+
var writer = XmlWriter.Create(result, settings);
6658

67-
// When, do work and get result
68-
var xslTransform = new XslCompiledTransform();
69-
xslTransform.Load(xslXmlReader);
70-
xslTransform.Transform(xmlXmlReader, resultXmlTextWriter);
71-
result.Position = 0;
72-
resultString = settings.Encoding.GetString(result.ToArray());
73-
}
59+
// When, do work and get result
60+
writer.WriteStartDocument();
61+
writer.WriteStartElement("orders");
62+
writer.WriteElementString("orderID", "1-456-ab\u0661");
63+
writer.WriteElementString("orderID", "2-36-00a\uD800\uDC00\uD801\uDC01");
64+
writer.WriteEndElement();
65+
writer.WriteEndDocument();
66+
writer.Flush();
67+
result.Position = 0;
68+
resultString = settings.Encoding.GetString(result.ToArray());
7469
}
7570

76-
// Then
71+
// Then, last '>' will be cut off in resulting string if BOM is present
7772
Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-32\"?>", string.Concat(resultString.Take(39)));
7873
}
7974
}

0 commit comments

Comments
 (0)