XmlDsigExcC14NWithCommentsTransformTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // XmlDsigExcC14NWithCommentsTransformTest.cs - NUnit Test Cases for
  3. // XmlDsigExcC14NWithCommentsTransform
  4. //
  5. // Author:
  6. // original:
  7. // Sebastien Pouliot <[email protected]>
  8. // Aleksey Sanin ([email protected])
  9. // this file:
  10. // Gert Driesen <[email protected]>
  11. //
  12. // (C) 2003 Aleksey Sanin ([email protected])
  13. // (C) 2004 Novell (http://www.novell.com)
  14. // (C) 2008 Gert Driesen
  15. //
  16. using System;
  17. using System.IO;
  18. using System.Security.Cryptography.Xml;
  19. using System.Text;
  20. using System.Xml;
  21. using NUnit.Framework;
  22. namespace MonoTests.System.Security.Cryptography.Xml {
  23. public class UnprotectedXmlDsigExcC14NWithCommentsTransform : XmlDsigExcC14NWithCommentsTransform {
  24. public UnprotectedXmlDsigExcC14NWithCommentsTransform ()
  25. {
  26. }
  27. public UnprotectedXmlDsigExcC14NWithCommentsTransform (string inclusiveNamespacesPrefixList)
  28. : base (inclusiveNamespacesPrefixList)
  29. {
  30. }
  31. public XmlNodeList UnprotectedGetInnerXml ()
  32. {
  33. return base.GetInnerXml ();
  34. }
  35. }
  36. [TestFixture]
  37. public class XmlDsigExcC14NWithCommentsTransformTest {
  38. private UnprotectedXmlDsigExcC14NWithCommentsTransform transform;
  39. [SetUp]
  40. public void SetUp ()
  41. {
  42. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform ();
  43. }
  44. [Test] // ctor ()
  45. public void Constructor1 ()
  46. {
  47. CheckProperties (transform);
  48. Assert.IsNull (transform.InclusiveNamespacesPrefixList);
  49. }
  50. [Test] // ctor (Boolean)
  51. public void Constructor2 ()
  52. {
  53. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform (null);
  54. CheckProperties (transform);
  55. Assert.IsNull (transform.InclusiveNamespacesPrefixList);
  56. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform (string.Empty);
  57. CheckProperties (transform);
  58. Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList);
  59. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform ("#default xsd");
  60. CheckProperties (transform);
  61. Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList);
  62. }
  63. void CheckProperties (XmlDsigExcC14NWithCommentsTransform transform)
  64. {
  65. Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments",
  66. transform.Algorithm, "Algorithm");
  67. Type[] input = transform.InputTypes;
  68. Assert.AreEqual (3, input.Length, "Input #");
  69. // check presence of every supported input types
  70. bool istream = false;
  71. bool ixmldoc = false;
  72. bool ixmlnl = false;
  73. foreach (Type t in input) {
  74. if (t == typeof (Stream))
  75. istream = true;
  76. if (t == typeof (XmlDocument))
  77. ixmldoc = true;
  78. if (t == typeof (XmlNodeList))
  79. ixmlnl = true;
  80. }
  81. Assert.IsTrue (istream, "Input Stream");
  82. Assert.IsTrue (ixmldoc, "Input XmlDocument");
  83. Assert.IsTrue (ixmlnl, "Input XmlNodeList");
  84. Type[] output = transform.OutputTypes;
  85. Assert.AreEqual (1, output.Length, "Output #");
  86. Assert.AreEqual (typeof (Stream), output [0], "Output Type");
  87. }
  88. [Test]
  89. public void InputTypes ()
  90. {
  91. Type [] input = transform.InputTypes;
  92. input [0] = null;
  93. input [1] = null;
  94. input [2] = null;
  95. // property does not return a clone
  96. foreach (Type t in transform.InputTypes)
  97. Assert.IsNull (t);
  98. // it's not a static array
  99. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform ();
  100. foreach (Type t in transform.InputTypes)
  101. Assert.IsNotNull (t);
  102. }
  103. [Test]
  104. public void GetInnerXml ()
  105. {
  106. XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
  107. Assert.IsNull (xnl, "Default InnerXml");
  108. }
  109. [Test]
  110. public void OutputTypes ()
  111. {
  112. // property does not return a clone
  113. transform.OutputTypes [0] = null;
  114. Assert.IsNull (transform.OutputTypes [0]);
  115. // it's not a static array
  116. transform = new UnprotectedXmlDsigExcC14NWithCommentsTransform ();
  117. Assert.IsNotNull (transform.OutputTypes [0]);
  118. }
  119. }
  120. }