2 // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
11 using System
.Security
.Cryptography
;
12 using System
.Security
.Cryptography
.Xml
;
15 using NUnit
.Framework
;
17 namespace MonoTests
.System
.Security
.Cryptography
.Xml
{
20 public class KeyInfoRetrievalMethodTest
: Assertion
{
23 public void TestNewEmptyKeyNode ()
25 KeyInfoRetrievalMethod uri1
= new KeyInfoRetrievalMethod ();
27 AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1
.GetXml ().OuterXml
));
29 AssertEquals ("Empty", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1
.GetXml ().OuterXml
));
34 public void TestNewKeyNode ()
36 string uri
= "http://www.go-mono.com/";
37 KeyInfoRetrievalMethod uri1
= new KeyInfoRetrievalMethod ();
39 XmlElement xel
= uri1
.GetXml ();
41 KeyInfoRetrievalMethod uri2
= new KeyInfoRetrievalMethod (uri1
.Uri
);
44 AssertEquals ("uri1==uri2", (uri1
.GetXml ().OuterXml
), (uri2
.GetXml ().OuterXml
));
45 AssertEquals ("uri==Uri", uri
, uri1
.Uri
);
49 public void TestImportKeyNode ()
52 string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
54 string value = "<RetrievalMethod URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
56 XmlDocument doc
= new XmlDocument ();
59 KeyInfoRetrievalMethod uri1
= new KeyInfoRetrievalMethod ();
60 uri1
.LoadXml (doc
.DocumentElement
);
62 // verify that proper XML is generated (equals to original)
63 string s
= (uri1
.GetXml ().OuterXml
);
64 AssertEquals ("Xml", value, s
);
66 // verify that property is parsed correctly
67 AssertEquals ("Uri", "http://www.go-mono.com/", uri1
.Uri
);
71 [ExpectedException (typeof (ArgumentNullException
))]
72 public void InvalidKeyNode1 ()
74 KeyInfoRetrievalMethod uri1
= new KeyInfoRetrievalMethod ();
79 public void InvalidKeyNode2 ()
81 string bad
= "<Test></Test>";
82 XmlDocument doc
= new XmlDocument ();
85 KeyInfoRetrievalMethod uri1
= new KeyInfoRetrievalMethod ();
86 // no exception is thrown
87 uri1
.LoadXml (doc
.DocumentElement
);
88 // note that URI="" is present (unlike a empty Uri)
90 AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1
.GetXml ().OuterXml
));
92 AssertEquals("invalid", "<RetrievalMethod URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1
.GetXml ().OuterXml
));