2
0

XmlDataSourceTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #if NET_2_0
  30. using NUnit.Framework;
  31. using System;
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.IO;
  35. using System.Globalization;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. using System.Xml;
  40. using System.Xml.Xsl;
  41. namespace MonoTests.System.Web.UI.WebControls
  42. {
  43. class DSPoker : XmlDataSource
  44. {
  45. public DSPoker () {
  46. TrackViewState ();
  47. }
  48. public object SaveState () {
  49. return SaveViewState ();
  50. }
  51. public void LoadState (object o) {
  52. LoadViewState (o);
  53. }
  54. }
  55. [TestFixture]
  56. public class XmlDataSourceTest
  57. {
  58. [Test]
  59. public void Defaults ()
  60. {
  61. DSPoker p = new DSPoker ();
  62. Assert.AreEqual ("", p.Data, "A4");
  63. Assert.AreEqual ("", p.DataFile, "A5");
  64. Assert.AreEqual ("", p.Transform, "A9");
  65. Assert.AreEqual ("", p.TransformFile, "A10");
  66. Assert.AreEqual ("", p.XPath, "A11");
  67. Assert.AreEqual (0, p.CacheDuration, "A12");
  68. Assert.AreEqual (DataSourceCacheExpiry.Absolute, p.CacheExpirationPolicy, "A13");
  69. Assert.AreEqual ("", p.CacheKeyDependency, "A14");
  70. Assert.AreEqual (true, p.EnableCaching, "A15");
  71. }
  72. [Test]
  73. public void Attributes ()
  74. {
  75. DSPoker p = new DSPoker ();
  76. p.Data = Test1Document1;
  77. Assert.AreEqual (Test1Document1, p.Data, "A1");
  78. p.Transform = "transform";
  79. Assert.AreEqual ("transform", p.Transform, "A2");
  80. p.XPath = "xpath";
  81. Assert.AreEqual ("xpath", p.XPath, "A3");
  82. }
  83. [Test]
  84. public void ViewState ()
  85. {
  86. // XXX weird... something odd going on with
  87. // ViewState? or are none of these stored?
  88. DSPoker p = new DSPoker ();
  89. p.Data = Test1Document1;
  90. p.Transform = "transform";
  91. p.XPath = "xpath";
  92. object state = p.SaveState();
  93. DSPoker copy = new DSPoker ();
  94. copy.LoadState (state);
  95. Assert.AreEqual ("", copy.Data, "A1");
  96. Assert.AreEqual ("", copy.Transform, "A2");
  97. Assert.AreEqual ("", copy.XPath, "A3");
  98. p = new DSPoker ();
  99. p.DataFile = "DataFile";
  100. p.TransformFile = "TransformFile";
  101. state = p.SaveState();
  102. copy = new DSPoker ();
  103. copy.LoadState (state);
  104. Assert.AreEqual ("", copy.DataFile, "A1");
  105. Assert.AreEqual ("", copy.TransformFile, "A2");
  106. }
  107. const string Test1Document1 =
  108. @"<?xml version=""1.0"" encoding=""utf-8"" ?>
  109. <IranHistoricalPlaces name=""places"">
  110. <Place name=""Taghe Bostan"">
  111. <City>Kermanshah</City>
  112. <Antiquity>2000</Antiquity>
  113. </Place>
  114. <Place name=""Persepolis"">
  115. <City>Shiraz</City>
  116. <Antiquity>2500</Antiquity>
  117. </Place>
  118. </IranHistoricalPlaces>";
  119. }
  120. }
  121. #endif