diff --git a/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj b/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj index 3de190a9a7bb..d2a1ead69baa 100644 --- a/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj +++ b/src/System.Security.Cryptography.Xml/tests/System.Security.Cryptography.Xml.Tests.csproj @@ -43,9 +43,6 @@ - - - @@ -57,4 +54,4 @@ - + \ No newline at end of file diff --git a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs index aedbca01861a..92bcef303020 100644 --- a/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs +++ b/src/System.Security.Cryptography.Xml/tests/TestHelpers.cs @@ -2,46 +2,120 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.IO; +using System.Text; +using System.Xml; +using System.Xml.Resolvers; namespace System.Security.Cryptography.Xml.Tests { internal static class TestHelpers { - public static TempFile CreateTestDtdFile(string testName) + /// + /// Convert a to a using the given . + /// + /// + /// The to read from. This cannot be null. + /// + /// + /// The to use. This cannot be null. + /// + /// + /// The stream as a string. + /// + /// + /// No argument can be null. + /// + public static string StreamToString(Stream stream, Encoding encoding) { - if (testName == null) - throw new ArgumentNullException(nameof(testName)); + if (stream == null) + { + throw new ArgumentNullException(nameof(stream)); + } + if (encoding == null) + { + throw new ArgumentNullException(nameof(encoding)); + } - var file = new TempFile( - Path.Combine(Directory.GetCurrentDirectory(), testName + ".dtd") - ); - - File.WriteAllText(file.Path, ""); - - return file; + using (StreamReader streamReader = new StreamReader(stream, encoding)) + { + return streamReader.ReadToEnd(); + } } - public static TempFile CreateTestTextFile(string testName, string content) + /// + /// Perform + /// + /// + /// The XML to transform. This cannot be null, empty or whitespace. + /// + /// + /// The to perform on + /// . This cannot be null. + /// + /// + /// An optional to use when serializing or + /// deserializing . This should match the + /// encoding specified in . If omitted or + /// null, is used. + /// + /// + /// An optional to use. If omitted or null, + /// no resolver is used. + /// + /// + /// The transformed . + /// + /// + /// cannot be null. + /// + /// + /// cannot be null, empty or whitespace. + /// + /// + /// is not valid XML. + /// + public static string ExecuteTransform(string inputXml, Transform transform, Encoding encoding = null, XmlResolver resolver = null) { - if (testName == null) - throw new ArgumentNullException(nameof(testName)); - - if (content == null) - throw new ArgumentNullException(nameof(content)); - - var file = new TempFile( - Path.Combine(Directory.GetCurrentDirectory(), testName + ".txt") - ); + if (string.IsNullOrEmpty(inputXml)) + { + throw new ArgumentException("Cannot be null, empty or whitespace", nameof(inputXml)); + } + if (transform == null) + { + throw new ArgumentNullException(nameof(Transform)); + } - File.WriteAllText(file.Path, content); + XmlDocument doc = new XmlDocument(); + doc.XmlResolver = resolver; + doc.PreserveWhitespace = true; + doc.LoadXml(inputXml); - return file; + Encoding actualEncoding = encoding ?? Encoding.UTF8; + byte[] data = actualEncoding.GetBytes(inputXml); + using (Stream stream = new MemoryStream(data)) + using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse, XmlResolver = resolver })) + { + doc.Load(reader); + transform.LoadInput(doc); + return StreamToString((Stream)transform.GetOutput(), actualEncoding); + } } - public static string EscapePath(string path) + /// + /// Convert to a full URI for referencing + /// in an . + /// + /// + /// The file name. + /// + /// + /// The created . + /// + public static Uri ToUri(string fileName) { - return path.Replace("-", "D;"); + return new Uri("file:///" + Path.Combine(Directory.GetCurrentDirectory(), fileName)); } } } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index 52e2489c97de..31c224a8a28c 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -15,6 +15,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -24,15 +25,6 @@ namespace System.Security.Cryptography.Xml.Tests // difficult to test properly. This class "open it up" :-) public class UnprotectedXmlDsigC14NTransform : XmlDsigC14NTransform { - public UnprotectedXmlDsigC14NTransform() - { - } - - public UnprotectedXmlDsigC14NTransform(bool includeComments) - : base(includeComments) - { - } - public XmlNodeList UnprotectedGetInnerXml() { return base.GetInnerXml(); @@ -41,85 +33,39 @@ public XmlNodeList UnprotectedGetInnerXml() public class XmlDsigC14NTransformTest { - - protected UnprotectedXmlDsigC14NTransform transform; - - public XmlDsigC14NTransformTest() - { - transform = new UnprotectedXmlDsigC14NTransform(); - } - - [Fact] // ctor () - public void Constructor1() + [Fact] + public void Constructor_Empty() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm); CheckProperties(transform); } - [Fact] // ctor (Boolean) - public void Constructor2() + [Theory] + [InlineData(true, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments")] + [InlineData(false, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")] + public void Constructor_Bool(bool includeComments, string expectedAlgorithm) { - transform = new UnprotectedXmlDsigC14NTransform(true); - Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", transform.Algorithm); - CheckProperties(transform); - - transform = new UnprotectedXmlDsigC14NTransform(false); - Assert.Equal("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm); + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(includeComments); + Assert.Equal(expectedAlgorithm, transform.Algorithm); CheckProperties(transform); } - void CheckProperties(XmlDsigC14NTransform transform) + public void CheckProperties(XmlDsigC14NTransform transform) { - Type[] input = transform.InputTypes; - Assert.True((input.Length == 3), "Input #"); - // check presence of every supported input types - bool istream = false; - bool ixmldoc = false; - bool ixmlnl = false; - foreach (Type t in input) - { - if (t.ToString() == "System.IO.Stream") - istream = true; - if (t.ToString() == "System.Xml.XmlDocument") - ixmldoc = true; - if (t.ToString() == "System.Xml.XmlNodeList") - ixmlnl = true; - } - Assert.True(istream, "Input Stream"); - Assert.True(ixmldoc, "Input XmlDocument"); - Assert.True(ixmlnl, "Input XmlNodeList"); - - Type[] output = transform.OutputTypes; - Assert.True((output.Length == 1), "Output #"); - // check presence of every supported output types - bool ostream = false; - foreach (Type t in output) - { - if (t.ToString() == "System.IO.Stream") - ostream = true; - } - Assert.True(ostream, "Output Stream"); + Assert.Null(transform.Context); + Assert.Equal(new[] { typeof(Stream), typeof(XmlDocument), typeof(XmlNodeList) }, transform.InputTypes); + Assert.Equal(new[] { typeof(Stream) }, transform.OutputTypes); } [Fact] public void GetInnerXml() { + UnprotectedXmlDsigC14NTransform transform = new UnprotectedXmlDsigC14NTransform(); XmlNodeList xnl = transform.UnprotectedGetInnerXml(); Assert.Null(xnl); } - private string Stream2String(Stream s) - { - StringBuilder sb = new StringBuilder(); - int b = s.ReadByte(); - while (b != -1) - { - sb.Append(Convert.ToChar(b)); - b = s.ReadByte(); - } - return sb.ToString(); - } - static string xml = " \r\n text & "; // GOOD for Stream input static string c14xml2 = " \n text & "; @@ -139,55 +85,60 @@ private XmlDocument GetDoc() [Fact] public void LoadInputAsXmlDocument() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); transform.LoadInput(doc); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(c14xml3, output); } - [Fact(Skip = "TODO: fix me")] + [Fact()] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); // Argument list just contains element Test. transform.LoadInput(doc.ChildNodes); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); - Assert.Equal("", output); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); + Assert.Equal(@"", output); } - [Fact(Skip = "TODO: fix me")] + [Fact()] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel public void LoadInputAsXmlNodeList2() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = GetDoc(); transform.LoadInput(doc.SelectNodes("//*")); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); - string expected = @""; + string output = TestHelpers.StreamToString(s, Encoding.UTF8); + string expected = @""; Assert.Equal(expected, output); } [Fact] public void LoadInputAsStream() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); MemoryStream ms = new MemoryStream(); byte[] x = Encoding.ASCII.GetBytes(xml); ms.Write(x, 0, x.Length); ms.Position = 0; transform.LoadInput(ms); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(c14xml2, output); } [Fact] public void LoadInputWithUnsupportedType() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); byte[] bad = { 0xBA, 0xD }; Assert.Throws(() => transform.LoadInput(bad)); } @@ -195,6 +146,7 @@ public void LoadInputWithUnsupportedType() [Fact] public void UnsupportedOutput() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); Assert.Throws(() => transform.GetOutput(doc.GetType())); } @@ -202,72 +154,36 @@ public void UnsupportedOutput() [Fact] public void C14NSpecExample1() { - using (TestHelpers.CreateTestDtdFile(GetType().Name + "." + nameof(C14NSpecExample1))) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input); - Assert.Equal(C14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(new Uri("doc.xsl", UriKind.Relative), ""); + string result = TestHelpers.ExecuteTransform(C14NSpecExample1Input, new XmlDsigC14NTransform()); + Assert.Equal(C14NSpecExample1Output, result); } - [Fact] - public void C14NSpecExample2() + [Theory] + [InlineData(C14NSpecExample2Input, C14NSpecExample2Output)] + [InlineData(C14NSpecExample3Input, C14NSpecExample3Output)] + [InlineData(C14NSpecExample4Input, C14NSpecExample4Output)] + public void C14NSpecExample(string input, string expectedOutput) { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample2Input); - Assert.Equal(C14NSpecExample2Output, res); + string result = TestHelpers.ExecuteTransform(input, new XmlDsigC14NTransform()); + Assert.Equal(expectedOutput, result); } [Fact] - public void C14NSpecExample3() - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample3Input); - Assert.Equal(C14NSpecExample3Output, res); - } - - [Fact] - // [Ignore ("This test should be fine, but it does not pass under MS.NET")] - public void C14NSpecExample4() - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample4Input); - Assert.Equal(C14NSpecExample4Output, res); - } - - [Fact(Skip = "TODO: fix me")] public void C14NSpecExample5() { - string testName = GetType().Name + "." + nameof(C14NSpecExample5); - using (TestHelpers.CreateTestTextFile(testName, "world")) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample5Input(testName)); - Assert.Equal(C14NSpecExample5Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); + string result = TestHelpers.ExecuteTransform(C14NSpecExample5Input, new XmlDsigC14NTransform(), Encoding.UTF8, resolver); + Assert.Equal(C14NSpecExample5Output, result); } [Fact] public void C14NSpecExample6() { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample6Input); - Assert.Equal(C14NSpecExample6Output, res); - } - - private string ExecuteXmlDSigC14NTransform(string InputXml) - { - XmlDocument doc = new XmlDocument(); - doc.PreserveWhitespace = true; - doc.LoadXml(InputXml); - - // Testing default attribute support with - // vreader.ValidationType = ValidationType.None. - // - UTF8Encoding utf8 = new UTF8Encoding(); - byte[] data = utf8.GetBytes(InputXml.ToString()); - Stream stream = new MemoryStream(data); - using (XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings { ValidationType = ValidationType.None, DtdProcessing = DtdProcessing.Parse })) - { - doc.Load(reader); - - transform.LoadInput(doc); - return Stream2String((Stream)transform.GetOutput()); - } + string result = TestHelpers.ExecuteTransform(C14NSpecExample6Input, new XmlDsigC14NTransform(), Encoding.GetEncoding("ISO-8859-1")); + Assert.Equal(C14NSpecExample6Output, result); } // @@ -283,7 +199,6 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) "\n" + "\n" + - // "\n" + "\n" + "Hello, world!\n" + "\n" + @@ -300,7 +215,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) // Example 2 from C14N spec - Whitespace in Document Content: // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent // - static string C14NSpecExample2Input = + const string C14NSpecExample2Input = "\n" + " \n" + " A B \n" + @@ -312,7 +227,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) " C\n" + " \n" + "\n"; - static string C14NSpecExample2Output = + const string C14NSpecExample2Output = "\n" + " \n" + " A B \n" + @@ -329,7 +244,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) // Example 3 from C14N spec - Start and End Tags: // http://www.w3.org/TR/xml-c14n#Example-SETags // - static string C14NSpecExample3Input = + const string C14NSpecExample3Input = "]>\n" + "\n" + " \n" + @@ -348,7 +263,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) " \n" + " \n" + "\n"; - static string C14NSpecExample3Output = + const string C14NSpecExample3Output = "\n" + " \n" + " \n" + @@ -376,7 +291,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) // should be normalized by XML parser. Currently Mono // does not support this (see comment after this example // in the spec). - static string C14NSpecExample4Input = + const string C14NSpecExample4Input = "]>\n" + "\n" + " First line Second line\n" + @@ -386,7 +301,7 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) " \n" + // " \n" + "\n"; - static string C14NSpecExample4Output = + const string C14NSpecExample4Output = "\n" + " First line \n" + "Second line\n" + @@ -401,11 +316,11 @@ private string ExecuteXmlDSigC14NTransform(string InputXml) // Example 5 from C14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string C14NSpecExample5Input(string worldName) => + static string C14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -447,13 +362,14 @@ public void SimpleNamespacePrefixes() [Fact] public void OrdinalSortForAttributes() { + XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); string xml = ""; doc.LoadXml(xml); transform.LoadInput(doc); Stream s = (Stream)transform.GetOutput(); - string output = Stream2String(s); + string output = TestHelpers.StreamToString(s, Encoding.UTF8); Assert.Equal(xml, output); } diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index 15247d71169b..f0b0257ae6f2 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -14,6 +14,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -70,23 +71,10 @@ public void GetOutput_UnsupportedType(Type type) [Fact] public void C14NSpecExample1() { - string testName = GetType().Name + "." + nameof(C14NSpecExample1); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input(testName), Encoding.UTF8, new XmlUrlResolver()); - Assert.Equal(C14NSpecExample1Output, res); - } - } - - [Fact] - public void C14NSpecExample1_WithoutResolver() - { - string testName = GetType().Name + "." + nameof(C14NSpecExample1_WithoutResolver); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigC14NTransform(C14NSpecExample1Input(testName)); - Assert.Equal(C14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("world.dtd"), ""); + string res = TestHelpers.ExecuteTransform(C14NSpecExample1Input, new XmlDsigC14NWithCommentsTransform(), Encoding.UTF8, resolver); + Assert.Equal(C14NSpecExample1Output, res); } [Theory] @@ -101,14 +89,12 @@ public void C14NSpecExample(string input, string expectedOutput) [Fact] public void C14NSpecExample5() { - string testName = GetType().Name + "." + nameof(C14NSpecExample5); - using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) - { - string input = C14NSpecExample5Input(tempFile.Path); - string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, new XmlUrlResolver()); - string expectedResult = C14NSpecExample5Output(tempFile.Path); - Assert.Equal(expectedResult, result); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); + string input = C14NSpecExample5Input; + string result = ExecuteXmlDSigC14NTransform(input, Encoding.UTF8, resolver); + string expectedResult = C14NSpecExample5Output; + Assert.Equal(expectedResult, result); } [Fact] @@ -133,15 +119,7 @@ private string ExecuteXmlDSigC14NTransform(string inputXml, Encoding encoding = doc.Load(reader); XmlDsigC14NWithCommentsTransform transform = new XmlDsigC14NWithCommentsTransform(); transform.LoadInput(doc); - return Stream2String((Stream) transform.GetOutput(), actualEncoding); - } - } - - private string Stream2String(Stream stream, Encoding encoding) - { - using (StreamReader streamReader = new StreamReader(stream, encoding)) - { - return streamReader.ReadToEnd(); + return TestHelpers.StreamToString((Stream) transform.GetOutput(), actualEncoding); } } @@ -149,13 +127,13 @@ private string Stream2String(Stream stream, Encoding encoding) // Example 1 from C14N spec - PIs, Comments, and Outside of Document Element: // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc // - static string C14NSpecExample1Input(string testName) => + static string C14NSpecExample1Input => "\n" + "\n" + "\n" + "\n" + - $"\n" + + "\n" + "\n" + "Hello, world!\n" + "\n" + @@ -275,11 +253,11 @@ static string C14NSpecExample1Input(string testName) => // Example 5 from C14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string C14NSpecExample5Input(string path) => + static string C14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -287,12 +265,12 @@ static string C14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; - static string C14NSpecExample5Output(string path) => + $"\n"; + static string C14NSpecExample5Output => "\n" + " Hello, world!\n" + "\n" + - $""; + $""; // // Example 6 from C14N spec - UTF-8 Encoding: diff --git a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index b4a5eb230fe3..c803d6c390e4 100644 --- a/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -19,6 +19,7 @@ using System.IO; using System.Text; using System.Xml; +using System.Xml.Resolvers; using Xunit; namespace System.Security.Cryptography.Xml.Tests @@ -292,12 +293,10 @@ public void UnsupportedOutput() [Fact] public void ExcC14NSpecExample1() { - string testName = GetType().Name + "." + nameof(ExcC14NSpecExample1); - using (TestHelpers.CreateTestDtdFile(testName)) - { - string res = ExecuteXmlDSigExcC14NTransform(ExcC14NSpecExample1Input); - Assert.Equal(ExcC14NSpecExample1Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("doc.dtd"), ""); + string res = ExecuteXmlDSigExcC14NTransform(ExcC14NSpecExample1Input); + Assert.Equal(ExcC14NSpecExample1Output, res); } [Fact] @@ -325,13 +324,11 @@ public void ExcC14NSpecExample4() [Fact] public void ExcC14NSpecExample5() { - string testName = GetType().Name + "." + nameof(ExcC14NSpecExample5); - using (TempFile tempFile = TestHelpers.CreateTestTextFile(testName, "world")) - { - string input = ExcC14NSpecExample5Input(tempFile.Path); - string res = ExecuteXmlDSigExcC14NTransform(input, new XmlUrlResolver()); - Assert.Equal(ExcC14NSpecExample5Output, res); - } + XmlPreloadedResolver resolver = new XmlPreloadedResolver(); + resolver.Add(TestHelpers.ToUri("doc.txt"), "world"); + string input = ExcC14NSpecExample5Input; + string res = ExecuteXmlDSigExcC14NTransform(input, resolver); + Assert.Equal(ExcC14NSpecExample5Output, res); } [Fact] @@ -381,7 +378,7 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml, XmlResolver resol "\n" + "\n" + - // "\n" + + "\n" + "\n" + "Hello, world!\n" + "\n" + @@ -499,11 +496,11 @@ private string ExecuteXmlDSigExcC14NTransform(string InputXml, XmlResolver resol // Example 5 from ExcC14N spec - Entity References: // http://www.w3.org/TR/xml-c14n#Example-Entities // - static string ExcC14NSpecExample5Input(string path) => + static string ExcC14NSpecExample5Input => "\n" + "\n" + - $"\n" + + $"\n" + "\n" + "\n" + "]>\n" + @@ -511,7 +508,7 @@ static string ExcC14NSpecExample5Input(string path) => " &ent1;, &ent2;!\n" + "\n" + "\n" + - $"\n"; + $"\n"; static string ExcC14NSpecExample5Output = "\n" + " Hello, world!\n" +