XslTransformTests.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // System.Xml.Xsl.XslTransformTests.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2002 Atsushi Enomoto
  8. //
  9. using System;
  10. using System.Xml;
  11. using System.Xml.XPath;
  12. using System.Xml.Xsl;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Xml.Xsl
  15. {
  16. [TestFixture]
  17. public class XslTransformTests : Assertion
  18. {
  19. XmlDocument doc;
  20. XslTransform xslt;
  21. XmlDocument result;
  22. [SetUp]
  23. public void GetReady()
  24. {
  25. doc = new XmlDocument ();
  26. xslt = new XslTransform ();
  27. result = new XmlDocument ();
  28. }
  29. [Test]
  30. public void TestBasicTransform ()
  31. {
  32. doc.LoadXml ("<root/>");
  33. xslt.Load ("Test/XmlFiles/xsl/empty.xsl");
  34. xslt.Transform ("Test/XmlFiles/xsl/empty.xsl", "Test/XmlFiles/xsl/result.xml");
  35. result.Load ("Test/XmlFiles/xsl/result.xml");
  36. AssertEquals ("count", 2, result.ChildNodes.Count);
  37. }
  38. [Test]
  39. [ExpectedException (typeof (XsltCompileException))]
  40. public void InvalidStylesheet ()
  41. {
  42. XmlDocument doc = new XmlDocument ();
  43. doc.LoadXml ("<xsl:element xmlns:xsl='http://www.w3.org/1999/XSL/Transform' />");
  44. XslTransform t = new XslTransform ();
  45. t.Load (doc);
  46. }
  47. [Test]
  48. [ExpectedException (typeof (XsltCompileException))]
  49. public void EmptyStylesheet ()
  50. {
  51. XmlDocument doc = new XmlDocument ();
  52. XslTransform t = new XslTransform ();
  53. t.Load (doc);
  54. }
  55. [Test]
  56. [ExpectedException (typeof (XsltCompileException))]
  57. public void InvalidStylesheet2 ()
  58. {
  59. string xml = @"<root>text</root>";
  60. string xsl = @"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
  61. <xsl:template match='/root'>
  62. <xsl:call-template name='foo'>
  63. <xsl:with-param name='name' value='text()' />
  64. </xsl:call-template>
  65. </xsl:template>
  66. <xsl:template name='foo'>
  67. <xsl:param name='name' />
  68. <result>
  69. <xsl:if test='1'>
  70. <xsl:variable name='last' value='text()' />
  71. <xsl:value-of select='$last' />
  72. </xsl:if>
  73. </result>
  74. </xsl:template>
  75. </xsl:stylesheet>
  76. ";
  77. XslTransform xslt = new XslTransform ();
  78. xslt.Load (new XPathDocument (new XmlTextReader (xsl, XmlNodeType.Document, null)));
  79. }
  80. }
  81. }