KeyInfoRetrievalMethodTest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Security.Cryptography.Xml;
  13. using System.Xml;
  14. using NUnit.Framework;
  15. namespace MonoTests.System.Security.Cryptography.Xml {
  16. [TestFixture]
  17. public class KeyInfoRetrievalMethodTest : Assertion {
  18. [Test]
  19. public void TestNewEmptyKeyNode ()
  20. {
  21. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  22. #if NET_1_0
  23. AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  24. #else
  25. AssertEquals ("Empty", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  26. #endif
  27. }
  28. [Test]
  29. public void TestNewKeyNode ()
  30. {
  31. string uri = "http://www.go-mono.com/";
  32. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  33. uri1.Uri = uri;
  34. XmlElement xel = uri1.GetXml ();
  35. KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
  36. uri2.LoadXml (xel);
  37. AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
  38. AssertEquals ("uri==Uri", uri, uri1.Uri);
  39. }
  40. [Test]
  41. public void TestImportKeyNode ()
  42. {
  43. #if NET_1_0
  44. string value = "<RetrievalElement URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
  45. #else
  46. string value = "<RetrievalMethod URI=\"http://www.go-mono.com/\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />";
  47. #endif
  48. XmlDocument doc = new XmlDocument ();
  49. doc.LoadXml (value);
  50. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  51. uri1.LoadXml (doc.DocumentElement);
  52. // verify that proper XML is generated (equals to original)
  53. string s = (uri1.GetXml ().OuterXml);
  54. AssertEquals ("Xml", value, s);
  55. // verify that property is parsed correctly
  56. AssertEquals ("Uri", "http://www.go-mono.com/", uri1.Uri);
  57. }
  58. [Test]
  59. [ExpectedException (typeof (ArgumentNullException))]
  60. public void InvalidKeyNode1 ()
  61. {
  62. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  63. uri1.LoadXml (null);
  64. }
  65. [Test]
  66. public void InvalidKeyNode2 ()
  67. {
  68. string bad = "<Test></Test>";
  69. XmlDocument doc = new XmlDocument ();
  70. doc.LoadXml (bad);
  71. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  72. // no exception is thrown
  73. uri1.LoadXml (doc.DocumentElement);
  74. #if NET_2_0
  75. AssertCrypto.AssertXmlEquals ("invalid", "<RetrievalMethod xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  76. #elif NET_1_1
  77. // note that URI="" is present (unlike a empty Uri)
  78. AssertEquals("invalid", "<RetrievalMethod URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  79. #else
  80. // Fx 1.0 misnamed the tag name
  81. AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  82. #endif
  83. }
  84. }
  85. }