2009-06-26 Robert Jordan <robertj@gmx.net>
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigC14NTransformTest.cs
1 //
2 // XmlDsigC14NTransformTest.cs - NUnit Test Cases for XmlDsigC14NTransform
3 //
4 // Author:
5 //      Sebastien Pouliot <sebastien@ximian.com>
6 //      Aleksey Sanin (aleksey@aleksey.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
10 // (C) 2004 Novell (http://www.novell.com)
11 //
12
13 using System;
14 using System.IO;
15 using System.Security.Cryptography.Xml;
16 using System.Text;
17 using System.Xml;
18
19 using NUnit.Framework;
20
21 namespace MonoTests.System.Security.Cryptography.Xml {
22
23         // Note: GetInnerXml is protected in XmlDsigC14NTransform making it
24         // difficult to test properly. This class "open it up" :-)
25         public class UnprotectedXmlDsigC14NTransform : XmlDsigC14NTransform {
26                 public UnprotectedXmlDsigC14NTransform ()
27                 {
28                 }
29
30                 public UnprotectedXmlDsigC14NTransform (bool includeComments)
31                         : base (includeComments)
32                 {
33                 }
34
35                 public XmlNodeList UnprotectedGetInnerXml () {
36                         return base.GetInnerXml ();
37                 }
38         }
39
40         [TestFixture]
41         public class XmlDsigC14NTransformTest {
42
43                 protected UnprotectedXmlDsigC14NTransform transform;
44
45                 [SetUp]
46                 protected void SetUp () 
47                 {
48                         transform = new UnprotectedXmlDsigC14NTransform ();
49                 }
50
51                 [TearDown]
52                 protected void CleanUp () 
53                 {
54                         try {
55                                 if (File.Exists ("doc.dtd"))
56                                         File.Delete ("doc.dtd");
57                                 if (File.Exists ("world.txt"))
58                                         File.Delete ("world.txt");
59                         }
60                         catch {}
61                 }
62
63                 [Test] // ctor ()
64                 public void Constructor1 ()
65                 {
66                         Assert.AreEqual ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm, "Algorithm");
67                         CheckProperties (transform);
68                 }
69
70                 [Test] // ctor (Boolean)
71                 public void Constructor2 ()
72                 {
73                         transform = new UnprotectedXmlDsigC14NTransform (true);
74                         Assert.AreEqual ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", transform.Algorithm, "Algorithm");
75                         CheckProperties (transform);
76
77                         transform = new UnprotectedXmlDsigC14NTransform (false);
78                         Assert.AreEqual ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", transform.Algorithm, "Algorithm");
79                         CheckProperties (transform);
80                 }
81
82                 void CheckProperties (XmlDsigC14NTransform transform)
83                 {
84                         Type[] input = transform.InputTypes;
85                         Assert.IsTrue ((input.Length == 3), "Input #");
86                         // check presence of every supported input types
87                         bool istream = false;
88                         bool ixmldoc = false;
89                         bool ixmlnl = false;
90                         foreach (Type t in input) {
91                                 if (t.ToString () == "System.IO.Stream")
92                                         istream = true;
93                                 if (t.ToString () == "System.Xml.XmlDocument")
94                                         ixmldoc = true;
95                                 if (t.ToString () == "System.Xml.XmlNodeList")
96                                         ixmlnl = true;
97                         }
98                         Assert.IsTrue (istream, "Input Stream");
99                         Assert.IsTrue (ixmldoc, "Input XmlDocument");
100                         Assert.IsTrue (ixmlnl, "Input XmlNodeList");
101
102                         Type[] output = transform.OutputTypes;
103                         Assert.IsTrue ((output.Length == 1), "Output #");
104                         // check presence of every supported output types
105                         bool ostream = false;
106                         foreach (Type t in output) {
107                                 if (t.ToString () == "System.IO.Stream")
108                                         ostream = true;
109                         }
110                         Assert.IsTrue (ostream, "Output Stream");
111                 }
112
113                 [Test]
114                 public void GetInnerXml () 
115                 {
116                         XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
117                         Assert.IsNull (xnl, "Default InnerXml");
118                 }
119
120                 private string Stream2String (Stream s) 
121                 {
122                         StringBuilder sb = new StringBuilder ();
123                         int b = s.ReadByte ();
124                         while (b != -1) {
125                                 sb.Append (Convert.ToChar (b));
126                                 b = s.ReadByte ();
127                         }
128                         return sb.ToString ();
129                 }
130
131                 static string xml = "<Test  attrib='at ' xmlns=\"http://www.go-mono.com/\" > \r\n &#xD; <Toto/> text &amp; </Test   >";
132                 // BAD for XmlDocument input (framework 1.0 result)
133                 static string c14xml1 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n \r <Toto></Toto> text &amp; </Test>";
134                 // GOOD for Stream input
135                 static string c14xml2 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n &#xD; <Toto></Toto> text &amp; </Test>";
136                 // GOOD for XmlDocument input. The difference is because once
137                 // xml string is loaded to XmlDocument, there is no difference
138                 // between \r and &#xD;, so every \r must be handled as &#xD;.
139                 static string c14xml3 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> &#xD;\n &#xD; <Toto></Toto> text &amp; </Test>";
140
141                 private XmlDocument GetDoc () 
142                 {
143                         XmlDocument doc = new XmlDocument ();
144                         doc.PreserveWhitespace = true;
145                         doc.LoadXml (xml);
146                         return doc;
147                 }
148
149                 [Test]
150                 public void LoadInputAsXmlDocument () 
151                 {
152                         XmlDocument doc = GetDoc ();
153                         transform.LoadInput (doc);
154                         Stream s = (Stream) transform.GetOutput ();
155                         string output = Stream2String (s);
156 #if NET_1_1
157                         Assert.AreEqual (c14xml3, output, "XmlDocument");
158 #else
159                         // .NET 1.0 keeps the \r\n (0x0D, 0x0A) - bug
160                         Assert.AreEqual (c14xml1, output, "XmlDocument");
161 #endif
162                 }
163
164                 [Test]
165 #if NET_2_0
166                 [Category ("NotDotNet")]
167                 // see LoadInputAsXmlNodeList2 description
168 #endif
169                 public void LoadInputAsXmlNodeList () 
170                 {
171                         XmlDocument doc = GetDoc ();
172                         // Argument list just contains element Test.
173                         transform.LoadInput (doc.ChildNodes);
174                         Stream s = (Stream) transform.GetOutput ();
175                         string output = Stream2String (s);
176                         Assert.AreEqual ("<Test></Test>", output, "XmlChildNodes");
177                 }
178
179                 [Test]
180                 [Category ("NotDotNet")]
181                 // MS has a bug that those namespace declaration nodes in
182                 // the node-set are written to output. Related spec section is:
183                 // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel
184                 public void LoadInputAsXmlNodeList2 () 
185                 {
186                         XmlDocument doc = GetDoc ();
187                         transform.LoadInput (doc.SelectNodes ("//*"));
188                         Stream s = (Stream) transform.GetOutput ();
189                         string output = Stream2String (s);
190                         string expected = @"<Test><Toto></Toto></Test>";
191                         Assert.AreEqual (expected, output, "XmlChildNodes");
192                 }
193
194                 [Test]
195                 public void LoadInputAsStream () 
196                 {
197                         MemoryStream ms = new MemoryStream ();
198                         byte[] x = Encoding.ASCII.GetBytes (xml);
199                         ms.Write (x, 0, x.Length);
200                         ms.Position = 0;
201                         transform.LoadInput (ms);
202                         Stream s = (Stream) transform.GetOutput ();
203                         string output = Stream2String (s);
204                         Assert.AreEqual (c14xml2, output, "MemoryStream");
205                 }
206
207                 [Test]
208 #if NET_2_0
209                 [ExpectedException (typeof (ArgumentException))]
210 #else
211                 // LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)
212 #endif
213                 public void LoadInputWithUnsupportedType () 
214                 {
215                         byte[] bad = { 0xBA, 0xD };
216                         transform.LoadInput (bad);
217                 }
218
219                 [Test]
220                 [ExpectedException (typeof (ArgumentException))]
221                 public void UnsupportedOutput () 
222                 {
223                         XmlDocument doc = new XmlDocument();
224                         object o = transform.GetOutput (doc.GetType ());
225                 }
226
227                 [Test]
228                 public void C14NSpecExample1 ()
229                 {
230                         using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
231                                 sw.Write ("<!-- presence, not content, required -->");
232                                 sw.Close ();
233                         }
234                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample1Input);
235                         Assert.AreEqual (C14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)");
236                 }
237
238                 [Test]
239                 public void C14NSpecExample2 ()
240                 {
241                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample2Input);
242                         Assert.AreEqual (C14NSpecExample2Output, res, "Example 2 from c14n spec - Whitespace in Document Content (without comments)");
243                 }
244
245                 [Test]
246                 public void C14NSpecExample3 ()
247                 {
248                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample3Input);
249                         Assert.AreEqual (C14NSpecExample3Output, res, "Example 3 from c14n spec - Start and End Tags (without comments)");
250                 }
251             
252                 [Test]
253 //              [Ignore ("This test should be fine, but it does not pass under MS.NET")]
254                 public void C14NSpecExample4 ()
255                 {
256                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample4Input);
257                         Assert.AreEqual (C14NSpecExample4Output, res, "Example 4 from c14n spec - Character Modifications and Character References (without comments)");
258                 }
259             
260                 [Test]
261                 public void C14NSpecExample5 ()
262                 {
263                         using (StreamWriter sw = new StreamWriter ("world.txt", false, Encoding.ASCII)) {
264                                 sw.Write ("world");
265                                 sw.Close ();
266                         }
267                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample5Input);
268                         Assert.AreEqual (C14NSpecExample5Output, res, "Example 5 from c14n spec - Entity References (without comments)");
269                 }
270     
271                 [Test]
272                 public void C14NSpecExample6 ()
273                 {
274                         string res = ExecuteXmlDSigC14NTransform (C14NSpecExample6Input);
275                         Assert.AreEqual (C14NSpecExample6Output, res, "Example 6 from c14n spec - UTF-8 Encoding (without comments)");
276                 }
277
278                 private string ExecuteXmlDSigC14NTransform (string InputXml)
279                 {
280                         XmlDocument doc = new XmlDocument ();
281                         doc.PreserveWhitespace = true;
282                         doc.LoadXml (InputXml);
283                 
284                         // Testing default attribute support with
285                         // vreader.ValidationType = ValidationType.None.
286                         //
287                         UTF8Encoding utf8 = new UTF8Encoding ();
288                         byte[] data = utf8.GetBytes (InputXml.ToString ());
289                         Stream stream = new MemoryStream (data);
290                         XmlTextReader reader = new XmlTextReader (stream);
291                         XmlValidatingReader vreader = new XmlValidatingReader (reader);
292                         vreader.ValidationType = ValidationType.None;
293                         vreader.EntityHandling = EntityHandling.ExpandCharEntities;
294                         doc.Load (vreader);
295
296                         transform.LoadInput (doc);
297                         return Stream2String ((Stream)transform.GetOutput ());
298                 }
299
300                 //
301                 // Example 1 from C14N spec - PIs, Comments, and Outside of Document Element: 
302                 // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
303                 // 
304                 // Aleksey: 
305                 // removed reference to an empty external DTD
306                 //
307                 static string C14NSpecExample1Input =  
308                         "<?xml version=\"1.0\"?>\n" +
309                         "\n" +
310                         "<?xml-stylesheet   href=\"doc.xsl\"\n" +
311                         "   type=\"text/xsl\"   ?>\n" +
312                         "\n" +
313                         // "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" +
314                         "\n" +
315                         "<doc>Hello, world!<!-- Comment 1 --></doc>\n" +
316                         "\n" +
317                         "<?pi-without-data     ?>\n\n" +
318                         "<!-- Comment 2 -->\n\n" +
319                         "<!-- Comment 3 -->\n";
320                 static string C14NSpecExample1Output =   
321                         "<?xml-stylesheet href=\"doc.xsl\"\n" +
322                         "   type=\"text/xsl\"   ?>\n" +
323                         "<doc>Hello, world!</doc>\n" +
324                         "<?pi-without-data?>";
325                 
326                 //
327                 // Example 2 from C14N spec - Whitespace in Document Content: 
328                 // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
329                 // 
330                 static string C14NSpecExample2Input =  
331                         "<doc>\n" +
332                         "  <clean>   </clean>\n" +
333                         "   <dirty>   A   B   </dirty>\n" +
334                         "   <mixed>\n" +
335                         "      A\n" +
336                         "      <clean>   </clean>\n" +
337                         "      B\n" +
338                         "      <dirty>   A   B   </dirty>\n" +
339                         "      C\n" +
340                         "   </mixed>\n" +
341                         "</doc>\n";
342                 static string C14NSpecExample2Output =   
343                         "<doc>\n" +
344                         "  <clean>   </clean>\n" +
345                         "   <dirty>   A   B   </dirty>\n" +
346                         "   <mixed>\n" +
347                         "      A\n" +
348                         "      <clean>   </clean>\n" +
349                         "      B\n" +
350                         "      <dirty>   A   B   </dirty>\n" +
351                         "      C\n" +
352                         "   </mixed>\n" +
353                         "</doc>";
354             
355                 //
356                 // Example 3 from C14N spec - Start and End Tags: 
357                 // http://www.w3.org/TR/xml-c14n#Example-SETags
358                 //
359                 static string C14NSpecExample3Input =  
360                         "<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" +
361                         "<doc>\n" +
362                         "   <e1   />\n" +
363                         "   <e2   ></e2>\n" +
364                         "   <e3    name = \"elem3\"   id=\"elem3\"    />\n" +
365                         "   <e4    name=\"elem4\"   id=\"elem4\"    ></e4>\n" +
366                         "   <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" +
367                         "       xmlns:b=\"http://www.ietf.org\" \n" +
368                         "       xmlns:a=\"http://www.w3.org\"\n" +
369                         "       xmlns=\"http://www.uvic.ca\"/>\n" +
370                         "   <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
371                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
372                         "           <e8 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
373                         "               <e9 xmlns=\"\" xmlns:a=\"http://www.ietf.org\"/>\n" +
374                         "           </e8>\n" +
375                         "       </e7>\n" +
376                         "   </e6>\n" +
377                         "</doc>\n";
378                 static string C14NSpecExample3Output =   
379                         "<doc>\n" +
380                         "   <e1></e1>\n" +
381                         "   <e2></e2>\n" +
382                         "   <e3 id=\"elem3\" name=\"elem3\"></e3>\n" +
383                         "   <e4 id=\"elem4\" name=\"elem4\"></e4>\n" +
384                         "   <e5 xmlns=\"http://www.uvic.ca\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" +
385                         "   <e6 xmlns:a=\"http://www.w3.org\">\n" +
386                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
387                         "           <e8 xmlns=\"\">\n" +
388                         "               <e9 xmlns:a=\"http://www.ietf.org\" attr=\"default\"></e9>\n" +
389 //                      "               <e9 xmlns:a=\"http://www.ietf.org\"></e9>\n" +
390                         "           </e8>\n" +
391                         "       </e7>\n" +
392                         "   </e6>\n" +
393                         "</doc>";
394             
395             
396                 //
397                 // Example 4 from C14N spec - Character Modifications and Character References: 
398                 // http://www.w3.org/TR/xml-c14n#Example-Chars
399                 //
400                 // Aleksey: 
401                 // This test does not include "normId" element
402                 // because it has an invalid ID attribute "id" which
403                 // should be normalized by XML parser. Currently Mono
404                 // does not support this (see comment after this example
405                 // in the spec).
406                 static string C14NSpecExample4Input =  
407                         "<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>\n" +
408                         "<doc>\n" +
409                         "   <text>First line&#x0d;&#10;Second line</text>\n" +
410                         "   <value>&#x32;</value>\n" +
411                         "   <compute><![CDATA[value>\"0\" && value<\"10\" ?\"valid\":\"error\"]]></compute>\n" +
412                         "   <compute expr=\'value>\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"\'>valid</compute>\n" +
413                         "   <norm attr=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
414                         // "   <normId id=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
415                         "</doc>\n";
416                 static string C14NSpecExample4Output =   
417                         "<doc>\n" +
418                         "   <text>First line&#xD;\n" +
419                         "Second line</text>\n" +
420                         "   <value>2</value>\n" +
421                         "   <compute>value&gt;\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"</compute>\n" +
422                         "   <compute expr=\"value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;\">valid</compute>\n" +
423                         "   <norm attr=\" \'    &#xD;&#xA;&#x9;   \' \"></norm>\n" +
424                         // "   <normId id=\"\' &#xD;&#xA;&#x9; \'\"></normId>\n" +
425                         "</doc>";
426             
427                 //
428                 // Example 5 from C14N spec - Entity References: 
429                 // http://www.w3.org/TR/xml-c14n#Example-Entities
430                 //
431                 static string C14NSpecExample5Input =  
432                         "<!DOCTYPE doc [\n" +
433                         "<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>\n" +
434                         "<!ENTITY ent1 \"Hello\">\n" +
435                         "<!ENTITY ent2 SYSTEM \"world.txt\">\n" +
436                         "<!ENTITY entExt SYSTEM \"earth.gif\" NDATA gif>\n" +
437                         "<!NOTATION gif SYSTEM \"viewgif.exe\">\n" +
438                         "]>\n" +
439                         "<doc attrExtEnt=\"entExt\">\n" +
440                         "   &ent1;, &ent2;!\n" +
441                         "</doc>\n" +
442                         "\n" +
443                         "<!-- Let world.txt contain \"world\" (excluding the quotes) -->\n";
444                 static string C14NSpecExample5Output =  
445                         "<doc attrExtEnt=\"entExt\">\n" +
446                         "   Hello, world!\n" +
447                         "</doc>";           
448     
449                 //
450                 // Example 6 from C14N spec - UTF-8 Encoding: 
451                 // http://www.w3.org/TR/xml-c14n#Example-UTF8
452                 // 
453                 static string C14NSpecExample6Input =  
454                         "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
455                         "<doc>&#169;</doc>\n";
456                 static string C14NSpecExample6Output =  
457                         "<doc>\xC2\xA9</doc>";
458             
459
460                 //
461                 // Example 7 from C14N spec - Document Subsets: 
462                 // http://www.w3.org/TR/xml-c14n#Example-DocSubsets
463                 // 
464                 // Aleksey:
465                 // Well, XPath support in Mono is far from complete....
466                 // I was not able to simplify the xpath expression from this test
467                 // so it runs on Mono and still makes sense for testing this feature.
468                 // Thus this test is not included in the suite now.
469                 static string C14NSpecExample7Input =  
470                         "<!DOCTYPE doc [\n" +
471                         "<!ATTLIST e2 xml:space (default|preserve) \'preserve\'>\n" +
472                         "<!ATTLIST e3 id ID #IMPLIED>\n" +
473                         "]>\n" +
474                         "<doc xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\">\n" +
475                         "   <e1>\n" +
476                         "      <e2 xmlns=\"\">\n" +
477                         "         <e3 id=\"E3\"/>\n" +
478                         "      </e2>\n" +
479                         "   </e1>\n" +
480                         "</doc>\n";
481
482                 static string C14NSpecExample7Xpath =  
483                         "(//.|//@*|//namespace::*)\n" +
484                         "[\n" +
485                         "self::ietf:e1\n" +
486                         "    or\n" +
487                         "(parent::ietf:e1 and not(self::text() or self::e2))\n" +
488                         "    or\n" +
489                         "count(id(\"E3\")|ancestor-or-self::node()) = count(ancestor-or-self::node())\n" +
490                         "]";
491                 static string C14NSpecExample7Output =  
492                         "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>";
493
494                 [Test]
495                 public void SimpleNamespacePrefixes ()
496                 {
497                         string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>";
498                         string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>";
499
500                         XmlDocument doc = new XmlDocument ();
501                         doc.LoadXml (input);
502                         XmlDsigC14NTransform t = new XmlDsigC14NTransform ();
503                         t.LoadInput (doc);
504                         Stream s = t.GetOutput () as Stream;
505                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
506                 }
507
508 #if NET_2_0
509                 [Test]
510                 public void PrefixlessNamespaceOutput ()
511                 {
512                         XmlDocument doc = new XmlDocument ();
513                         doc.AppendChild (doc.CreateElement ("foo", "urn:foo"));
514                         doc.DocumentElement.AppendChild (doc.CreateElement ("bar", "urn:bar"));
515                         Assert.AreEqual (String.Empty, doc.DocumentElement.GetAttribute ("xmlns"), "#1");
516                         XmlDsigC14NTransform t = new XmlDsigC14NTransform ();
517                         t.LoadInput (doc);
518                         Stream s = t.GetOutput () as Stream;
519                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), "<foo xmlns=\"urn:foo\"><bar xmlns=\"urn:bar\"></bar></foo>");
520                         Assert.AreEqual ("urn:foo", doc.DocumentElement.GetAttribute ("xmlns"), "#2");
521                 }
522
523                 [Test]
524                 [Ignore ("find out how PropagatedNamespaces returns non-null instance on .NET")]
525                 public void PropagatedNamespaces ()
526                 {
527                         XmlDocument doc = new XmlDocument ();
528                         doc.AppendChild (doc.CreateElement ("foo", "urn:foo"));
529                         doc.DocumentElement.AppendChild (doc.CreateElement ("bar", "urn:bar"));
530                         Assert.AreEqual (String.Empty, doc.DocumentElement.GetAttribute ("xmlns:f"), "#1");
531                         XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
532                         t.LoadInput (doc);
533                         t.PropagatedNamespaces.Add ("f", "urn:foo");
534                         t.PropagatedNamespaces.Add ("b", "urn:bar");
535                         Stream s = t.GetOutput () as Stream;
536                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), "<f:foo xmlns:f=\"urn:foo\"><b:bar xmlns:b=\"urn:bar\"></b:bar></f:foo>");
537                         Assert.AreEqual ("urn:foo", doc.DocumentElement.GetAttribute ("xmlns:f"), "#2");
538                 }
539
540                 [Test]
541                 [ExpectedException (typeof (NullReferenceException))]
542                 public void GetDigestedOutput_Null ()
543                 {
544                         new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
545                 }
546 #endif
547         }    
548 }