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 : Assertion {
24 public void TestNewEmptyKeyNode ()
26 KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
28 AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
30 AssertEquals ("Empty", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
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 AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
46 AssertEquals ("uri==Uri", uri, uri1.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 AssertEquals ("Xml", value, s);
67 // verify that property is parsed correctly
68 AssertEquals ("Uri", "http://www.go-mono.com/", uri1.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 AssertEquals("invalid", "<RetrievalMethod URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
95 // Fx 1.0 misnamed the tag name
96 AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));