KeyInfoNameTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // KeyInfoNameTest.cs - NUnit Test Cases for KeyInfoName
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. #if !MOBILE
  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 KeyInfoNameTest {
  18. [Test]
  19. public void NewKeyValue ()
  20. {
  21. string newKeyValue = "Mono::";
  22. KeyInfoName name1 = new KeyInfoName ();
  23. name1.Value = newKeyValue;
  24. XmlElement xel = name1.GetXml ();
  25. KeyInfoName name2 = new KeyInfoName ();
  26. name2.LoadXml (xel);
  27. Assert.AreEqual (newKeyValue, name1.Value, "newKeyValue==value");
  28. Assert.AreEqual ((name1.GetXml ().OuterXml), (name2.GetXml ().OuterXml), "name1==name2");
  29. }
  30. [Test]
  31. public void ImportKeyValue ()
  32. {
  33. string value = "<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Mono::</KeyName>";
  34. XmlDocument doc = new XmlDocument ();
  35. doc.LoadXml (value);
  36. KeyInfoName name = new KeyInfoName ();
  37. name.LoadXml (doc.DocumentElement);
  38. Assert.AreEqual ("Mono::", name.Value, "import.Name");
  39. Assert.AreEqual (value, name.GetXml ().OuterXml, "import.GetXml");
  40. }
  41. [Test]
  42. [ExpectedException (typeof (ArgumentNullException))]
  43. public void InvalidValue1 ()
  44. {
  45. string bad = "<Test></Test>";
  46. XmlDocument doc = new XmlDocument ();
  47. doc.LoadXml (bad);
  48. KeyInfoName name = new KeyInfoName ();
  49. name.LoadXml (null);
  50. }
  51. [Test]
  52. public void InvalidValue2 ()
  53. {
  54. string bad = "<Test></Test>";
  55. XmlDocument doc = new XmlDocument ();
  56. doc.LoadXml (bad);
  57. KeyInfoName name = new KeyInfoName ();
  58. name.LoadXml (doc.DocumentElement);
  59. Assert.AreEqual ("", name.Value, "invalid.Name");
  60. Assert.AreEqual ("<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\"></KeyName>", (name.GetXml ().OuterXml), "invalid.GetXml");
  61. }
  62. }
  63. }
  64. #endif