KeyInfoNameTest.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // KeyInfoNameTest.cs - NUnit Test Cases for KeyInfoName
  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 KeyInfoNameTest : TestCase {
  16. public KeyInfoNameTest () : base ("System.Security.Cryptography.Xml.KeyInfoName testsuite") {}
  17. public KeyInfoNameTest (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 (KeyInfoNameTest));
  23. }
  24. }
  25. public void TestNewKeyValue ()
  26. {
  27. string newKeyValue = "Mono::";
  28. KeyInfoName name1 = new KeyInfoName ();
  29. name1.Value = newKeyValue;
  30. XmlElement xel = name1.GetXml ();
  31. KeyInfoName name2 = new KeyInfoName ();
  32. name2.LoadXml (xel);
  33. AssertEquals ("name1==name2", (name1.GetXml ().OuterXml), (name2.GetXml ().OuterXml));
  34. AssertEquals ("newKeyValue==value", newKeyValue, name1.Value);
  35. }
  36. public void TestImportKeyValue ()
  37. {
  38. string value = "<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Mono::</KeyName>";
  39. XmlDocument doc = new XmlDocument ();
  40. doc.LoadXml (value);
  41. KeyInfoName name1 = new KeyInfoName ();
  42. name1.LoadXml (doc.DocumentElement);
  43. string s = (name1.GetXml ().OuterXml);
  44. AssertEquals ("Name", value, s);
  45. }
  46. public void TestInvalidValue ()
  47. {
  48. string bad = "<Test></Test>";
  49. XmlDocument doc = new XmlDocument ();
  50. doc.LoadXml (bad);
  51. KeyInfoName name1 = new KeyInfoName ();
  52. try {
  53. name1.LoadXml (null);
  54. Fail ("Expected ArgumentNullException but got none");
  55. }
  56. catch (ArgumentNullException) {
  57. // this is what we expect
  58. }
  59. catch (Exception e) {
  60. Fail ("Expected ArgumentNullException but got: " + e.ToString ());
  61. }
  62. name1.LoadXml (doc.DocumentElement);
  63. AssertEquals("invalid", "<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\"></KeyName>", (name1.GetXml ().OuterXml));
  64. }
  65. }
  66. }