[bcl] Remove more NET_2_0 checks from class libs
[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                         Assert.AreEqual ("<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "Empty");
28                 }
29
30                 [Test]
31                 public void TestNewKeyNode () 
32                 {
33                         string uri = "http://www.go-mono.com/";
34                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
35                         uri1.Uri = uri;
36                         XmlElement xel = uri1.GetXml ();
37
38                         KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
39                         uri2.LoadXml (xel);
40
41                         Assert.AreEqual ((uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml), "uri1==uri2");
42                         Assert.AreEqual (uri, uri1.Uri, "uri==Uri");
43                 }
44
45                 [Test]
46                 public void TestImportKeyNode () 
47                 {
48                         string value = "<RetrievalMethod URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
49                         XmlDocument doc = new XmlDocument ();
50                         doc.LoadXml (value);
51
52                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
53                         uri1.LoadXml (doc.DocumentElement);
54
55                         // verify that proper XML is generated (equals to original)
56                         string s = (uri1.GetXml ().OuterXml);
57                         Assert.AreEqual (value, s, "Xml");
58
59                         // verify that property is parsed correctly
60                         Assert.AreEqual ("http://www.go-mono.com/", uri1.Uri, "Uri");
61                 }
62
63                 [Test]
64                 [ExpectedException (typeof (ArgumentNullException))]
65                 public void InvalidKeyNode1 () 
66                 {
67                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
68                         uri1.LoadXml (null);
69                 }
70
71                 [Test]
72                 public void InvalidKeyNode2 () 
73                 {
74                         string bad = "<Test></Test>";
75                         XmlDocument doc = new XmlDocument ();
76                         doc.LoadXml (bad);
77
78                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
79                         // no exception is thrown
80                         uri1.LoadXml (doc.DocumentElement);
81                         AssertCrypto.AssertXmlEquals ("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
82                 }
83         }
84 }