BindingFlags.Public needed here as Exception.HResult is now public in .NET 4.5. This...
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / KeyInfoRetrievalMethodTest.cs
1 //
2 // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10
11 using System;
12 using System.Security.Cryptography;
13 using System.Security.Cryptography.Xml;
14 using System.Xml;
15
16 using NUnit.Framework;
17
18 namespace MonoTests.System.Security.Cryptography.Xml {
19
20         [TestFixture]
21         public class KeyInfoRetrievalMethodTest {
22
23                 [Test]
24                 public void TestNewEmptyKeyNode () 
25                 {
26                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
27 #if NET_1_0
28                         Assert.AreEqual ("<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "Empty");
29 #else
30                         Assert.AreEqual ("<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "Empty");
31 #endif
32                 }
33
34                 [Test]
35                 public void TestNewKeyNode () 
36                 {
37                         string uri = "http://www.go-mono.com/";
38                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
39                         uri1.Uri = uri;
40                         XmlElement xel = uri1.GetXml ();
41
42                         KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
43                         uri2.LoadXml (xel);
44
45                         Assert.AreEqual ((uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml), "uri1==uri2");
46                         Assert.AreEqual (uri, uri1.Uri, "uri==Uri");
47                 }
48
49                 [Test]
50                 public void TestImportKeyNode () 
51                 {
52 #if NET_1_0
53                         string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
54 #else
55                         string value = "<RetrievalMethod URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
56 #endif
57                         XmlDocument doc = new XmlDocument ();
58                         doc.LoadXml (value);
59
60                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
61                         uri1.LoadXml (doc.DocumentElement);
62
63                         // verify that proper XML is generated (equals to original)
64                         string s = (uri1.GetXml ().OuterXml);
65                         Assert.AreEqual (value, s, "Xml");
66
67                         // verify that property is parsed correctly
68                         Assert.AreEqual ("http://www.go-mono.com/", uri1.Uri, "Uri");
69                 }
70
71                 [Test]
72                 [ExpectedException (typeof (ArgumentNullException))]
73                 public void InvalidKeyNode1 () 
74                 {
75                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
76                         uri1.LoadXml (null);
77                 }
78
79                 [Test]
80                 public void InvalidKeyNode2 () 
81                 {
82                         string bad = "<Test></Test>";
83                         XmlDocument doc = new XmlDocument ();
84                         doc.LoadXml (bad);
85
86                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
87                         // no exception is thrown
88                         uri1.LoadXml (doc.DocumentElement);
89 #if NET_2_0
90                         AssertCrypto.AssertXmlEquals ("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
91 #elif NET_1_1
92                         // note that URI="" is present (unlike a empty Uri)
93                         Assert.AreEqual ("<RetrievalMethod URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "invalid");
94 #else
95                         // Fx 1.0 misnamed the tag name
96                         Assert.AreEqual ("<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "invalid");
97 #endif
98                 }
99         }
100 }