SqlDataSourceTest.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // Tests for System.Web.UI.WebControls.SqlDataSource
  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.Configuration;
  33. using System.Data.Common;
  34. using System.IO;
  35. using System.Globalization;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.WebControls;
  39. namespace MonoTests.System.Web.UI.WebControls
  40. {
  41. class SqlPoker : SqlDataSource {
  42. public SqlPoker ()
  43. {
  44. TrackViewState ();
  45. }
  46. public object SaveToViewState ()
  47. {
  48. return SaveViewState ();
  49. }
  50. public void LoadFromViewState (object savedState)
  51. {
  52. LoadViewState (savedState);
  53. }
  54. }
  55. [TestFixture]
  56. public class SqlDataSourceTest {
  57. [Test]
  58. public void Defaults ()
  59. {
  60. SqlPoker sql = new SqlPoker ();
  61. Assert.AreEqual ("", sql.CacheKeyDependency, "A1");
  62. Assert.IsTrue (sql.CancelSelectOnNullParameter, "A2");
  63. Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A3");
  64. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.DeleteCommandType, "A4");
  65. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.InsertCommandType, "A5");
  66. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.SelectCommandType, "A6");
  67. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.UpdateCommandType, "A7");
  68. Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A8");
  69. Assert.AreEqual ("", sql.SqlCacheDependency, "A9");
  70. Assert.AreEqual ("", sql.SortParameterName, "A10");
  71. Assert.AreEqual (0, sql.CacheDuration, "A11");
  72. Assert.AreEqual (DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "A12");
  73. Assert.IsFalse (sql.EnableCaching, "A13");
  74. Assert.AreEqual ("", sql.ProviderName, "A14");
  75. Assert.AreEqual ("", sql.ConnectionString, "A15");
  76. Assert.AreEqual (SqlDataSourceMode.DataSet, sql.DataSourceMode, "A16");
  77. Assert.AreEqual ("", sql.DeleteCommand, "A17");
  78. Assert.IsNotNull (sql.DeleteParameters, "A18");
  79. Assert.AreEqual (0, sql.DeleteParameters.Count, "A18.1");
  80. Assert.IsNotNull (sql.FilterParameters, "A19");
  81. Assert.AreEqual (0, sql.FilterParameters.Count, "A19.1");
  82. Assert.AreEqual ("", sql.InsertCommand, "A20");
  83. Assert.IsNotNull (sql.InsertParameters, "A21");
  84. Assert.AreEqual (0, sql.InsertParameters.Count, "A21.1");
  85. Assert.AreEqual ("", sql.SelectCommand, "A22");
  86. Assert.IsNotNull (sql.SelectParameters, "A23");
  87. Assert.AreEqual (0, sql.SelectParameters.Count, "A23.1");
  88. Assert.AreEqual ("", sql.UpdateCommand, "A24");
  89. Assert.IsNotNull (sql.UpdateParameters, "A25");
  90. Assert.AreEqual (0, sql.UpdateParameters.Count, "A25.1");
  91. Assert.AreEqual ("", sql.FilterExpression, "A26");
  92. }
  93. // WARNING!!!!!! This information will be saved into viewstate only in mono implementation .
  94. [Test]
  95. [Category ("NotWorking")]
  96. public void ViewState ()
  97. {
  98. SqlPoker sql = new SqlPoker ();
  99. sql.CacheKeyDependency = "hi";
  100. sql.CancelSelectOnNullParameter = false;
  101. sql.ConflictDetection = ConflictOptions.CompareAllValues;
  102. sql.DeleteCommandType = SqlDataSourceCommandType.Text;
  103. sql.InsertCommandType = SqlDataSourceCommandType.Text;
  104. sql.SelectCommandType = SqlDataSourceCommandType.Text;
  105. sql.UpdateCommandType = SqlDataSourceCommandType.Text;
  106. sql.OldValuesParameterFormatString = "{1}";
  107. sql.SqlCacheDependency = "hi";
  108. sql.SortParameterName = "hi";
  109. sql.CacheDuration = 1;
  110. sql.CacheExpirationPolicy = DataSourceCacheExpiry.Sliding;
  111. sql.EnableCaching = true;
  112. sql.DataSourceMode = SqlDataSourceMode.DataReader;
  113. sql.DeleteCommand = "DELETE foo";
  114. sql.InsertCommand = "INSERT foo";
  115. sql.SelectCommand = "SELECT foo";
  116. sql.UpdateCommand = "UPDATE foo";
  117. sql.FilterExpression = "hi";
  118. Assert.AreEqual ("hi", sql.CacheKeyDependency, "A1");
  119. Assert.IsFalse (sql.CancelSelectOnNullParameter, "A2");
  120. Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "A3");
  121. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
  122. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A5");
  123. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A6");
  124. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A7");
  125. Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "A8");
  126. Assert.AreEqual ("hi", sql.SqlCacheDependency, "A9");
  127. Assert.AreEqual ("hi", sql.SortParameterName, "A10");
  128. Assert.AreEqual (1, sql.CacheDuration, "A11");
  129. Assert.AreEqual (DataSourceCacheExpiry.Sliding, sql.CacheExpirationPolicy, "A12");
  130. Assert.IsTrue (sql.EnableCaching, "A13");
  131. Assert.AreEqual (SqlDataSourceMode.DataReader, sql.DataSourceMode, "A16");
  132. Assert.AreEqual ("DELETE foo", sql.DeleteCommand, "A17");
  133. Assert.AreEqual ("INSERT foo", sql.InsertCommand, "A20");
  134. Assert.AreEqual ("SELECT foo", sql.SelectCommand, "A22");
  135. Assert.AreEqual ("UPDATE foo", sql.UpdateCommand, "A24");
  136. Assert.AreEqual ("hi", sql.FilterExpression, "A26");
  137. object state = sql.SaveToViewState();
  138. sql = new SqlPoker ();
  139. sql.LoadFromViewState (state);
  140. Assert.AreEqual ("hi", sql.CacheKeyDependency, "B1");
  141. Assert.IsFalse (sql.CancelSelectOnNullParameter, "B2");
  142. Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "B3");
  143. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B4");
  144. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "B5");
  145. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "B6");
  146. Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B7");
  147. Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "B8");
  148. Assert.AreEqual ("hi", sql.SqlCacheDependency, "B9");
  149. Assert.AreEqual ("hi", sql.SortParameterName, "B10");
  150. Assert.AreEqual (1, sql.CacheDuration, "B11");
  151. Assert.AreEqual (DataSourceCacheExpiry.Sliding, sql.CacheExpirationPolicy, "B12");
  152. Assert.IsTrue (sql.EnableCaching, "B13");
  153. Assert.AreEqual (SqlDataSourceMode.DataReader, sql.DataSourceMode, "B16");
  154. Assert.AreEqual ("DELETE foo", sql.DeleteCommand, "B17");
  155. Assert.AreEqual ("INSERT foo", sql.InsertCommand, "B20");
  156. Assert.AreEqual ("SELECT foo", sql.SelectCommand, "B22");
  157. Assert.AreEqual ("UPDATE foo", sql.UpdateCommand, "B24");
  158. Assert.AreEqual ("hi", sql.FilterExpression, "B26");
  159. }
  160. }
  161. }
  162. #endif