KeyInfoRetrievalMethodTest.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 TestNewEmptyKeyNode ()
  19. {
  20. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  21. Assertion.AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  22. }
  23. [Test]
  24. public void TestNewKeyNode ()
  25. {
  26. string uri = "http://www.go-mono.com/";
  27. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  28. uri1.Uri = uri;
  29. XmlElement xel = uri1.GetXml ();
  30. KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
  31. uri2.LoadXml (xel);
  32. Assertion.AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
  33. Assertion.AssertEquals ("uri==Uri", uri, uri1.Uri);
  34. }
  35. [Test]
  36. public void TestImportKeyNode ()
  37. {
  38. string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
  39. XmlDocument doc = new XmlDocument ();
  40. doc.LoadXml (value);
  41. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  42. uri1.LoadXml (doc.DocumentElement);
  43. // verify that proper XML is generated (equals to original)
  44. string s = (uri1.GetXml ().OuterXml);
  45. Assertion.AssertEquals ("Xml", value, s);
  46. // verify that property is parsed correctly
  47. Assertion.AssertEquals ("Uri", "http://www.go-mono.com/", uri1.Uri);
  48. }
  49. [Test]
  50. [ExpectedException (typeof (ArgumentNullException))]
  51. public void InvalidKeyNode1 ()
  52. {
  53. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  54. uri1.LoadXml (null);
  55. }
  56. [Test]
  57. public void InvalidKeyNode2 ()
  58. {
  59. string bad = "<Test></Test>";
  60. XmlDocument doc = new XmlDocument ();
  61. doc.LoadXml (bad);
  62. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  63. // no exception is thrown
  64. uri1.LoadXml (doc.DocumentElement);
  65. // note that URI="" is present (unlike a empty Uri)
  66. Assertion.AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  67. }
  68. }
  69. }