KeyInfoRetrievalMethodTest.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // KeyInfoRetrievalMethodTest.cs - NUnit Test Cases for KeyInfoRetrievalMethod
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Security.Cryptography;
  12. using System.Security.Cryptography.Xml;
  13. using System.Xml;
  14. namespace MonoTests.System.Security.Cryptography.Xml {
  15. public class KeyInfoRetrievalMethodTest : TestCase {
  16. public KeyInfoRetrievalMethodTest () : base ("System.Security.Cryptography.Xml.KeyInfoRetrievalMethod testsuite") {}
  17. public KeyInfoRetrievalMethodTest (string name) : base (name) {}
  18. protected override void SetUp () {}
  19. protected override void TearDown () {}
  20. public static ITest Suite {
  21. get {
  22. return new TestSuite (typeof (KeyInfoRetrievalMethodTest));
  23. }
  24. }
  25. public void TestNewKeyNode ()
  26. {
  27. string uri = "http://www.go-mono.com/";
  28. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  29. // verify empty XML
  30. AssertEquals ("Empty", "<RetrievalElement xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  31. uri1.Uri = uri;
  32. XmlElement xel = uri1.GetXml ();
  33. KeyInfoRetrievalMethod uri2 = new KeyInfoRetrievalMethod (uri1.Uri);
  34. uri2.LoadXml (xel);
  35. AssertEquals ("uri1==uri2", (uri1.GetXml ().OuterXml), (uri2.GetXml ().OuterXml));
  36. AssertEquals ("uri==Uri", uri, uri1.Uri);
  37. }
  38. public void TestImportKeyNode ()
  39. {
  40. string value = "<RetrievalElement 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. AssertEquals ("Xml", value, s);
  48. // verify that property is parsed correctly
  49. AssertEquals ("Uri", "http://www.go-mono.com/", uri1.Uri);
  50. }
  51. public void TestInvalidKeyNode ()
  52. {
  53. KeyInfoRetrievalMethod uri1 = new KeyInfoRetrievalMethod ();
  54. try {
  55. uri1.LoadXml (null);
  56. Fail ("Expected ArgumentNullException but got none");
  57. }
  58. catch (ArgumentNullException) {
  59. // this is what we expect
  60. }
  61. catch (Exception e) {
  62. Fail ("Expected ArgumentNullException but got: " + e.ToString ());
  63. }
  64. string bad = "<Test></Test>";
  65. XmlDocument doc = new XmlDocument ();
  66. doc.LoadXml (bad);
  67. // no exception is thrown
  68. uri1.LoadXml (doc.DocumentElement);
  69. // note that URI="" is present (unlike a empty Uri)
  70. AssertEquals("invalid", "<RetrievalElement URI=\"\" xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />", (uri1.GetXml ().OuterXml));
  71. }
  72. }
  73. }