XmlDsigC14NWithCommentsTransformTest.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // XmlDsigC14NWithCommentsTransformTest.cs
  3. // - NUnit Test Cases for XmlDsigC14NWithCommentsTransform
  4. //
  5. // Author:
  6. // Sebastien Pouliot ([email protected])
  7. //
  8. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  9. //
  10. using System;
  11. using System.IO;
  12. using System.Security.Cryptography.Xml;
  13. using System.Text;
  14. using System.Xml;
  15. using NUnit.Framework;
  16. namespace MonoTests.System.Security.Cryptography.Xml {
  17. [TestFixture]
  18. public class XmlDsigC14NWithCommentsTransformTest : Assertion {
  19. protected XmlDsigC14NWithCommentsTransform transform;
  20. [SetUp]
  21. protected void SetUp ()
  22. {
  23. transform = new XmlDsigC14NWithCommentsTransform ();
  24. }
  25. [Test]
  26. public void Properties ()
  27. {
  28. AssertEquals ("Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", transform.Algorithm);
  29. Type[] input = transform.InputTypes;
  30. Assert ("Input #", (input.Length == 3));
  31. // check presence of every supported input types
  32. bool istream = false;
  33. bool ixmldoc = false;
  34. bool ixmlnl = false;
  35. foreach (Type t in input) {
  36. if (t.ToString () == "System.IO.Stream")
  37. istream = true;
  38. if (t.ToString () == "System.Xml.XmlDocument")
  39. ixmldoc = true;
  40. if (t.ToString () == "System.Xml.XmlNodeList")
  41. ixmlnl = true;
  42. }
  43. Assert ("Input Stream", istream);
  44. Assert ("Input XmlDocument", ixmldoc);
  45. Assert ("Input XmlNodeList", ixmlnl);
  46. Type[] output = transform.OutputTypes;
  47. Assert ("Output #", (output.Length == 1));
  48. // check presence of every supported output types
  49. bool ostream = false;
  50. foreach (Type t in input) {
  51. if (t.ToString () == "System.IO.Stream")
  52. ostream = true;
  53. }
  54. Assert ("Output Stream", ostream);
  55. }
  56. [Test]
  57. public void LoadInputWithUnsupportedType ()
  58. {
  59. byte[] bad = { 0xBA, 0xD };
  60. // LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)
  61. transform.LoadInput (bad);
  62. }
  63. [Test]
  64. [ExpectedException (typeof (ArgumentException))]
  65. public void UnsupportedOutput ()
  66. {
  67. XmlDocument doc = new XmlDocument();
  68. object o = transform.GetOutput (doc.GetType ());
  69. }
  70. }
  71. }