2 // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 using System.Security.Cryptography;
13 using System.Security.Cryptography.Xml;
16 using NUnit.Framework;
18 namespace MonoTests.System.Security.Cryptography.Xml {
21 public class KeyInfoRetrievalMethodTest {
24 public void TestNewEmptyKeyNode ()
26 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
28 Assert.AreEqual ("<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "Empty");
30 Assert.AreEqual ("<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml), "Empty");
35 public void TestNewKeyNode ()
37 string uri = "http://www.go-mono.com/";
38 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
40 XmlElement xel = uri1.GetXml ();
42 KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
45 Assert.AreEqual ((uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml), "uri1==uri2");
46 Assert.AreEqual (uri, uri1.Uri, "uri==Uri");
50 public void TestImportKeyNode ()
53 string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
55 string value = "<RetrievalMethod URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
57 XmlDocument doc = new XmlDocument ();
60 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
61 uri1.LoadXml (doc.DocumentElement);
63 // verify that proper XML is generated (equals to original)
64 string s = (uri1.GetXml ().OuterXml);
65 Assert.AreEqual (value, s, "Xml");
67 // verify that property is parsed correctly
68 Assert.AreEqual ("http://www.go-mono.com/", uri1.Uri, "Uri");
72 [ExpectedException (typeof (ArgumentNullException))]
73 public void InvalidKeyNode1 ()
75 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
80 public void InvalidKeyNode2 ()
82 string bad = "<Test></Test>";
83 XmlDocument doc = new XmlDocument ();
86 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
87 // no exception is thrown
88 uri1.LoadXml (doc.DocumentElement);
90 AssertCrypto.AssertXmlEquals ("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
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");
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");