XmlDsigExcC14NWithCommentsTransformTest.cs 3.8 KB

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