2003-03-02 Sebastien Pouliot <spouliot@videotron.ca>
[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 (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using System.Security.Cryptography;
12 using System.Security.Cryptography.Xml;
13 using System.Xml;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Security.Cryptography.Xml {
18
19         [TestFixture]
20         public class KeyInfoRetrievalMethodTest {
21
22                 [Test]
23                 public void TestNewEmptyKeyNode () 
24                 {
25                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
26                         Assertion.AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
27                 }
28
29                 [Test]
30                 public void TestNewKeyNode () 
31                 {
32                         string uri = "http://www.go-mono.com/";
33                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
34                         uri1.Uri = uri;
35                         XmlElement xel = uri1.GetXml ();
36
37                         KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
38                         uri2.LoadXml (xel);
39
40                         Assertion.AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
41                         Assertion.AssertEquals ("uri==Uri", uri, uri1.Uri);
42                 }
43
44                 [Test]
45                 public void TestImportKeyNode () 
46                 {
47                         string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
48                         XmlDocument doc = new XmlDocument ();
49                         doc.LoadXml (value);
50
51                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
52                         uri1.LoadXml (doc.DocumentElement);
53
54                         // verify that proper XML is generated (equals to original)
55                         string s = (uri1.GetXml ().OuterXml);
56                         Assertion.AssertEquals ("Xml", value, s);
57
58                         // verify that property is parsed correctly
59                         Assertion.AssertEquals ("Uri", "http://www.go-mono.com/", uri1.Uri);
60                 }
61
62                 [Test]
63                 [ExpectedException (typeof (ArgumentNullException))]
64                 public void InvalidKeyNode1 () 
65                 {
66                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
67                         uri1.LoadXml (null);
68                 }
69
70                 [Test]
71                 public void InvalidKeyNode2 () 
72                 {
73                         string bad = "<Test></Test>";
74                         XmlDocument doc = new XmlDocument ();
75                         doc.LoadXml (bad);
76
77                         KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
78                         // no exception is thrown
79                         uri1.LoadXml (doc.DocumentElement);
80                         // note that URI="" is present (unlike a empty Uri)
81                         Assertion.AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
82                 }
83         }
84 }