KeyInfoRetrievalMethodTest.cs 2.8 KB

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