KeyInfoRetrievalMethodTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System;
  10. using System.Security.Cryptography;
  11. using System.Security.Cryptography.Xml;
  12. using System.Xml;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Security.Cryptography.Xml {
  15. [TestFixture]
  16. public class KeyInfoRetrievalMethodTest {
  17. [Test]
  18. public void TestNewKeyNode ()
  19. {
  20. string uri = "http://www.go-mono.com/";
  21. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  22. // verify empty XML
  23. Assertion.AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  24. uri1.Uri = uri;
  25. XmlElement xel = uri1.GetXml ();
  26. KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
  27. uri2.LoadXml (xel);
  28. Assertion.AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
  29. Assertion.AssertEquals ("uri==Uri", uri, uri1.Uri);
  30. }
  31. [Test]
  32. public void TestImportKeyNode ()
  33. {
  34. string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
  35. XmlDocument doc = new XmlDocument ();
  36. doc.LoadXml (value);
  37. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  38. uri1.LoadXml (doc.DocumentElement);
  39. // verify that proper XML is generated (equals to original)
  40. string s = (uri1.GetXml ().OuterXml);
  41. Assertion.AssertEquals ("Xml", value, s);
  42. // verify that property is parsed correctly
  43. Assertion.AssertEquals ("Uri", "http://www.go-mono.com/", uri1.Uri);
  44. }
  45. [Test]
  46. [ExpectedException (typeof (ArgumentNullException))]
  47. public void InvalidKeyNode1 ()
  48. {
  49. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  50. uri1.LoadXml (null);
  51. }
  52. [Test]
  53. public void InvalidKeyNode2 ()
  54. {
  55. string bad = "<Test></Test>";
  56. XmlDocument doc = new XmlDocument ();
  57. doc.LoadXml (bad);
  58. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  59. // no exception is thrown
  60. uri1.LoadXml (doc.DocumentElement);
  61. // note that URI="" is present (unlike a empty Uri)
  62. Assertion.AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  63. }
  64. }
  65. }