2 // Tests for System.Web.UI.WebControls.AccessDataSource
5 // Chris Toshok (toshok@novell.com)
9 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
34 using System.Configuration;
35 using System.Data.Common;
36 using System.Data.OleDb;
38 using System.Globalization;
41 using System.Web.UI.WebControls;
43 namespace MonoTests.System.Web.UI.WebControls
45 class AccessPoker : AccessDataSource {
51 public object SaveToViewState ()
53 return SaveViewState ();
56 public void LoadFromViewState (object savedState)
58 LoadViewState (savedState);
61 public DbProviderFactory GetFactory ()
63 return GetDbProviderFactory ();
68 public class AccessDataSourceTest {
70 [ExpectedException (typeof (InvalidOperationException))]
71 public void ProviderName ()
73 AccessPoker sql = new AccessPoker ();
74 sql.ProviderName = "foo";
78 [ExpectedException (typeof (NotSupportedException))]
79 public void SqlCacheDependency1 ()
81 AccessPoker sql = new AccessPoker ();
82 Assert.AreEqual ("", sql.SqlCacheDependency, "A1");
86 [ExpectedException (typeof (NotSupportedException))]
87 public void SqlCacheDependency2 ()
89 AccessPoker sql = new AccessPoker ();
90 sql.SqlCacheDependency = "hi";
94 [ExpectedException (typeof (InvalidOperationException))]
95 public void ConnectionString1 ()
97 AccessPoker sql = new AccessPoker ();
98 sql.ConnectionString = "hi";
102 public void ConnectionString2 ()
104 AccessPoker sql = new AccessPoker ();
107 Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
111 [ExpectedException (typeof (NullReferenceException))]
112 public void ConnectionString3 ()
114 AccessPoker sql = new AccessPoker ();
116 sql.DataFile = "hi there";
117 Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
121 // XXX enable this test once mono gets System.Data.OleDb.OleDbFactory
124 public void ProviderFactory ()
126 AccessPoker sql = new AccessPoker ();
128 Assert.AreEqual (typeof (OleDbFactory), sql.GetFactory ().GetType());
133 [Category ("NotWorking")]
134 public void Defaults ()
136 AccessPoker sql = new AccessPoker ();
138 Assert.AreEqual ("", sql.CacheKeyDependency, "A1");
139 Assert.IsTrue (sql.CancelSelectOnNullParameter, "A2");
140 Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A3");
141 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
142 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "A5");
143 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "A6");
144 Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A7");
145 Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A8");
147 // SqlCacheDependency access should raise an exception
148 // Assert.AreEqual ("", sql.SqlCacheDependency, "A9");
149 Assert.AreEqual ("", sql.SortParameterName, "A10");
150 Assert.AreEqual (0, sql.CacheDuration, "A11");
151 Assert.AreEqual (DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "A12");
152 Assert.IsFalse (sql.EnableCaching, "A13");
153 Assert.AreEqual ("System.Data.OleDb", sql.ProviderName, "A14");
154 Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A15");
155 Assert.AreEqual (SqlDataSourceMode.DataSet, sql.DataSourceMode, "A16");
156 Assert.AreEqual ("", sql.DeleteCommand, "A17");
157 Assert.IsNotNull (sql.DeleteParameters, "A18");
158 Assert.AreEqual (0, sql.DeleteParameters.Count, "A18.1");
159 Assert.IsNotNull (sql.FilterParameters, "A19");
160 Assert.AreEqual (0, sql.FilterParameters.Count, "A19.1");
161 Assert.AreEqual ("", sql.InsertCommand, "A20");
162 Assert.IsNotNull (sql.InsertParameters, "A21");
163 Assert.AreEqual (0, sql.InsertParameters.Count, "A21.1");
164 Assert.AreEqual ("", sql.SelectCommand, "A22");
165 Assert.IsNotNull (sql.SelectParameters, "A23");
166 Assert.AreEqual (0, sql.SelectParameters.Count, "A23.1");
167 Assert.AreEqual ("", sql.UpdateCommand, "A24");
168 Assert.IsNotNull (sql.UpdateParameters, "A25");
169 Assert.AreEqual (0, sql.UpdateParameters.Count, "A25.1");
170 Assert.AreEqual ("", sql.FilterExpression, "A26");
171 Assert.AreEqual ("", sql.DataFile, "A27");