KeyInfoRetrievalMethodTest.cs 2.4 KB

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