KeyInfoNodeTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // KeyInfoNodeTest.cs - NUnit Test Cases for KeyInfoNode
  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 KeyInfoNodeTest : TestCase {
  16. public KeyInfoNodeTest () : base ("System.Security.Cryptography.Xml.KeyInfoNode testsuite") {}
  17. public KeyInfoNodeTest (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 (KeyInfoNodeTest));
  23. }
  24. }
  25. public void TestNewKeyNode ()
  26. {
  27. string test = "<Test></Test>";
  28. XmlDocument doc = new XmlDocument ();
  29. doc.LoadXml (test);
  30. KeyInfoNode node1 = new KeyInfoNode ();
  31. node1.Value = doc.DocumentElement;
  32. XmlElement xel = node1.GetXml ();
  33. KeyInfoNode node2 = new KeyInfoNode (node1.Value);
  34. node2.LoadXml (xel);
  35. AssertEquals ("node1==node2", (node1.GetXml ().OuterXml), (node2.GetXml ().OuterXml));
  36. }
  37. public void TestImportKeyNode ()
  38. {
  39. // Note: KeyValue is a valid KeyNode
  40. string value = "<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Mono::</KeyName>";
  41. XmlDocument doc = new XmlDocument ();
  42. doc.LoadXml (value);
  43. KeyInfoNode node1 = new KeyInfoNode ();
  44. node1.LoadXml (doc.DocumentElement);
  45. string s = (node1.GetXml ().OuterXml);
  46. AssertEquals ("Node", value, s);
  47. }
  48. // well there's no invalid value - unless you read the doc ;-)
  49. public void TestInvalidKeyNode ()
  50. {
  51. string bad = "<Test></Test>";
  52. XmlDocument doc = new XmlDocument ();
  53. doc.LoadXml (bad);
  54. KeyInfoNode node1 = new KeyInfoNode ();
  55. // LAMESPEC: No ArgumentNullException is thrown if value == null
  56. node1.LoadXml (null);
  57. AssertNull ("Value==null", node1.Value);
  58. }
  59. }
  60. }