XmlDataSourceTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Tests for System.Web.UI.WebControls.XmlDataSource.cs
  3. //
  4. // Author:
  5. // Chris Toshok ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. using System.Xml;
  39. using System.Xml.Xsl;
  40. namespace MonoTests.System.Web.UI.WebControls
  41. {
  42. class DSPoker : XmlDataSource
  43. {
  44. public DSPoker () {
  45. TrackViewState ();
  46. }
  47. public object SaveState () {
  48. return SaveViewState ();
  49. }
  50. public void LoadState (object o) {
  51. LoadViewState (o);
  52. }
  53. }
  54. [TestFixture]
  55. public class XmlDataSourceTest
  56. {
  57. [Test]
  58. public void Defaults ()
  59. {
  60. DSPoker p = new DSPoker ();
  61. Assert.AreEqual ("", p.Data, "A4");
  62. Assert.AreEqual ("", p.DataFile, "A5");
  63. Assert.AreEqual ("", p.Transform, "A9");
  64. Assert.AreEqual ("", p.TransformFile, "A10");
  65. Assert.AreEqual ("", p.XPath, "A11");
  66. Assert.AreEqual (0, p.CacheDuration, "A12");
  67. Assert.AreEqual (DataSourceCacheExpiry.Absolute, p.CacheExpirationPolicy, "A13");
  68. Assert.AreEqual ("", p.CacheKeyDependency, "A14");
  69. Assert.AreEqual (true, p.EnableCaching, "A15");
  70. }
  71. [Test]
  72. public void Attributes ()
  73. {
  74. DSPoker p = new DSPoker ();
  75. p.Data = Test1Document1;
  76. Assert.AreEqual (Test1Document1, p.Data, "A1");
  77. p.Transform = "transform";
  78. Assert.AreEqual ("transform", p.Transform, "A2");
  79. p.XPath = "xpath";
  80. Assert.AreEqual ("xpath", p.XPath, "A3");
  81. }
  82. [Test]
  83. public void ViewState ()
  84. {
  85. // XXX weird... something odd going on with
  86. // ViewState? or are none of these stored?
  87. DSPoker p = new DSPoker ();
  88. p.Data = Test1Document1;
  89. p.Transform = "transform";
  90. p.XPath = "xpath";
  91. object state = p.SaveState();
  92. DSPoker copy = new DSPoker ();
  93. copy.LoadState (state);
  94. Assert.AreEqual ("", copy.Data, "A1");
  95. Assert.AreEqual ("", copy.Transform, "A2");
  96. Assert.AreEqual ("", copy.XPath, "A3");
  97. p = new DSPoker ();
  98. p.DataFile = "DataFile";
  99. p.TransformFile = "TransformFile";
  100. state = p.SaveState();
  101. copy = new DSPoker ();
  102. copy.LoadState (state);
  103. Assert.AreEqual ("", copy.DataFile, "A1");
  104. Assert.AreEqual ("", copy.TransformFile, "A2");
  105. }
  106. const string Test1Document1 =
  107. @"<?xml version=""1.0"" encoding=""utf-8"" ?>
  108. <IranHistoricalPlaces name=""places"">
  109. <Place name=""Taghe Bostan"">
  110. <City>Kermanshah</City>
  111. <Antiquity>2000</Antiquity>
  112. </Place>
  113. <Place name=""Persepolis"">
  114. <City>Shiraz</City>
  115. <Antiquity>2500</Antiquity>
  116. </Place>
  117. </IranHistoricalPlaces>";
  118. }
  119. }