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