AccessDataSourceTest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // Tests for System.Web.UI.WebControls.AccessDataSource
  3. //
  4. // Author:
  5. // Chris Toshok ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2006 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.Data.OleDb;
  35. using System.IO;
  36. using System.Globalization;
  37. using System.Web;
  38. using System.Web.UI;
  39. using System.Web.UI.WebControls;
  40. namespace MonoTests.System.Web.UI.WebControls
  41. {
  42. class AccessPoker : AccessDataSource {
  43. public AccessPoker ()
  44. {
  45. TrackViewState ();
  46. }
  47. public object SaveToViewState ()
  48. {
  49. return SaveViewState ();
  50. }
  51. public void LoadFromViewState (object savedState)
  52. {
  53. LoadViewState (savedState);
  54. }
  55. public DbProviderFactory GetFactory ()
  56. {
  57. return GetDbProviderFactory ();
  58. }
  59. }
  60. [TestFixture]
  61. public class AccessDataSourceTest {
  62. [Test]
  63. [ExpectedException (typeof (InvalidOperationException))]
  64. public void ProviderName ()
  65. {
  66. AccessPoker sql = new AccessPoker ();
  67. sql.ProviderName = "foo";
  68. }
  69. [Test]
  70. [ExpectedException (typeof (NotSupportedException))]
  71. public void SqlCacheDependency1 ()
  72. {
  73. AccessPoker sql = new AccessPoker ();
  74. Assert.AreEqual ("", sql.SqlCacheDependency, "A1");
  75. }
  76. [Test]
  77. [ExpectedException (typeof (NotSupportedException))]
  78. public void SqlCacheDependency2 ()
  79. {
  80. AccessPoker sql = new AccessPoker ();
  81. sql.SqlCacheDependency = "hi";
  82. }
  83. [Test]
  84. [ExpectedException (typeof (InvalidOperationException))]
  85. public void ConnectionString1 ()
  86. {
  87. AccessPoker sql = new AccessPoker ();
  88. sql.ConnectionString = "hi";
  89. }
  90. [Test]
  91. public void ConnectionString2 ()
  92. {
  93. AccessPoker sql = new AccessPoker ();
  94. sql.DataFile = "";
  95. Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
  96. }
  97. [Test]
  98. [ExpectedException (typeof (NullReferenceException))]
  99. public void ConnectionString3 ()
  100. {
  101. AccessPoker sql = new AccessPoker ();
  102. sql.DataFile = "hi there";
  103. Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
  104. }
  105. #if notyet
  106. // XXX enable this test once mono gets System.Data.OleDb.OleDbFactory
  107. //
  108. [Test]
  109. public void ProviderFactory ()
  110. {
  111. AccessPoker sql = new AccessPoker ();
  112. Assert.AreEqual (typeof (OleDbFactory), sql.GetFactory ().GetType());
  113. }
  114. #endif
  115. [Test]
  116. [Category ("NotWorking")]
  117. public void Defaults ()
  118. {
  119. AccessPoker sql = new AccessPoker ();
  120. Assert.AreEqual ("", sql.CacheKeyDependency, "A1");
  121. Assert.IsTrue (sql.CancelSelectOnNullParameter, "A2");
  122. Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A3");
  123. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.DeleteCommandType, "A4");
  124. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.InsertCommandType, "A5");
  125. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.SelectCommandType, "A6");
  126. Assert.AreEqual (SqlDataSourceCommandType.StoredProcedure, sql.UpdateCommandType, "A7");
  127. Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A8");
  128. // SqlCacheDependency access should raise an exception
  129. // Assert.AreEqual ("", sql.SqlCacheDependency, "A9");
  130. Assert.AreEqual ("", sql.SortParameterName, "A10");
  131. Assert.AreEqual (0, sql.CacheDuration, "A11");
  132. Assert.AreEqual (DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "A12");
  133. Assert.IsFalse (sql.EnableCaching, "A13");
  134. Assert.AreEqual ("System.Data.OleDb", sql.ProviderName, "A14");
  135. Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A15");
  136. Assert.AreEqual (SqlDataSourceMode.DataSet, sql.DataSourceMode, "A16");
  137. Assert.AreEqual ("", sql.DeleteCommand, "A17");
  138. Assert.IsNotNull (sql.DeleteParameters, "A18");
  139. Assert.AreEqual (0, sql.DeleteParameters.Count, "A18.1");
  140. Assert.IsNotNull (sql.FilterParameters, "A19");
  141. Assert.AreEqual (0, sql.FilterParameters.Count, "A19.1");
  142. Assert.AreEqual ("", sql.InsertCommand, "A20");
  143. Assert.IsNotNull (sql.InsertParameters, "A21");
  144. Assert.AreEqual (0, sql.InsertParameters.Count, "A21.1");
  145. Assert.AreEqual ("", sql.SelectCommand, "A22");
  146. Assert.IsNotNull (sql.SelectParameters, "A23");
  147. Assert.AreEqual (0, sql.SelectParameters.Count, "A23.1");
  148. Assert.AreEqual ("", sql.UpdateCommand, "A24");
  149. Assert.IsNotNull (sql.UpdateParameters, "A25");
  150. Assert.AreEqual (0, sql.UpdateParameters.Count, "A25.1");
  151. Assert.AreEqual ("", sql.FilterExpression, "A26");
  152. Assert.AreEqual ("", sql.DataFile, "A27");
  153. }
  154. }
  155. }
  156. #endif