[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / AccessDataSourceTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.AccessDataSource
3 //
4 // Author:
5 //      Chris Toshok (toshok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31
32 using NUnit.Framework;
33 using System;
34 using System.Configuration;
35 using System.Data.Common;
36 using System.Data.OleDb;
37 using System.IO;
38 using System.Globalization;
39 using System.Web;
40 using System.Web.UI;
41 using System.Web.UI.WebControls;
42
43 namespace MonoTests.System.Web.UI.WebControls
44 {
45         class AccessPoker : AccessDataSource {
46                 public AccessPoker ()
47                 {
48                         TrackViewState ();
49                 }
50
51                 public object SaveToViewState ()
52                 {
53                         return SaveViewState ();
54                 }
55
56                 public void LoadFromViewState (object savedState)
57                 {
58                         LoadViewState (savedState);
59                 }
60
61                 public DbProviderFactory GetFactory ()
62                 {
63                         return GetDbProviderFactory ();
64                 }
65         }
66
67         [TestFixture]
68         public class AccessDataSourceTest {
69                 [Test]
70                 [ExpectedException (typeof (InvalidOperationException))]
71                 public void ProviderName ()
72                 {
73                         AccessPoker sql = new AccessPoker ();
74                         sql.ProviderName = "foo";
75                 }
76
77                 [Test]
78                 [ExpectedException (typeof (NotSupportedException))]
79                 public void SqlCacheDependency1 ()
80                 {
81                         AccessPoker sql = new AccessPoker ();
82                         Assert.AreEqual ("", sql.SqlCacheDependency, "A1");
83                 }
84
85                 [Test]
86                 [ExpectedException (typeof (NotSupportedException))]
87                 public void SqlCacheDependency2 ()
88                 {
89                         AccessPoker sql = new AccessPoker ();
90                         sql.SqlCacheDependency = "hi";
91                 }
92
93                 [Test]
94                 [ExpectedException (typeof (InvalidOperationException))]
95                 public void ConnectionString1 ()
96                 {
97                         AccessPoker sql = new AccessPoker ();
98                         sql.ConnectionString = "hi";
99                 }
100
101                 [Test]
102                 public void ConnectionString2 ()
103                 {
104                         AccessPoker sql = new AccessPoker ();
105
106                         sql.DataFile = "";
107                         Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
108                 }
109
110                 [Test]
111                 [ExpectedException (typeof (NullReferenceException))]
112                 public void ConnectionString3 ()
113                 {
114                         AccessPoker sql = new AccessPoker ();
115
116                         sql.DataFile = "hi there";
117                         Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
118                 }
119
120 #if notyet
121                 // XXX enable this test once mono gets System.Data.OleDb.OleDbFactory
122                 //
123                 [Test]
124                 public void ProviderFactory ()
125                 {
126                         AccessPoker sql = new AccessPoker ();
127
128                         Assert.AreEqual (typeof (OleDbFactory), sql.GetFactory ().GetType());
129                 }
130 #endif
131
132                 [Test]
133         [Category ("NotWorking")]
134                 public void Defaults ()
135                 {
136                         AccessPoker sql = new AccessPoker ();
137
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");
146
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");
172                 }
173     }
174 }
175