[System.Data] Fixes tests build with mobile profiles
[mono.git] / mcs / class / System.Data / Test / System.Data.OleDb / OleDbConnectionTest.cs
1 //
2 // OleDbConnectionTest.cs - NUnit Test Cases for testing the
3 //                          OleDbConnectionTest class
4 // Author:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2007 Gert Driesen
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if !NO_OLEDB
30 using System;
31 using System.Data;
32 using System.Data.OleDb;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Data.OleDb
37 {
38         [TestFixture]
39         public class OleDbConnectionTest
40         {
41                 const string CONNECTION_STRING = "Provider=sqloledb;Data Source=SQLSRV;Initial Catalog=Mono;";
42
43                 [Test] // OleDbConnection ()
44                 public void Constructor1 ()
45                 {
46                         OleDbConnection cn = new OleDbConnection ();
47
48                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
49                         Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
50                         Assert.IsNull (cn.Container, "#3");
51                         Assert.AreEqual (string.Empty, cn.Database, "#4");
52                         Assert.AreEqual (string.Empty, cn.DataSource, "#5");
53                         Assert.AreEqual (string.Empty, cn.Provider, "#6");
54                         Assert.IsNull (cn.Site, "#7");
55                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#8");
56                 }
57
58                 [Test] // OleDbConnection (string)
59                 public void Constructor2 ()
60                 {
61                         OleDbConnection cn = new OleDbConnection (CONNECTION_STRING);
62                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#A1");
63                         Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
64                         Assert.IsNull (cn.Container, "#A3");
65                         //Assert.AreEqual ("Mono", cn.Database, "#A4");
66                         //Assert.AreEqual ("SQLSRV", cn.DataSource, "#A5");
67                         //Assert.AreEqual ("sqloledb", cn.Provider, "#A6");
68                         Assert.IsNull (cn.Site, "#A7");
69                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#A8");
70
71                         cn = new OleDbConnection ((string) null);
72                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
73                         Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
74                         Assert.IsNull (cn.Container, "#B3");
75                         Assert.AreEqual (string.Empty, cn.Database, "#B4");
76                         Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
77                         Assert.AreEqual (string.Empty, cn.Provider, "#B6");
78                         Assert.IsNull (cn.Site, "#B7");
79                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#B8");
80                 }
81
82                 [Test]
83                 public void BeginTransaction_Connection_Closed ()
84                 {
85                         OleDbConnection cn = new OleDbConnection ();
86
87                         try {
88                                 cn.BeginTransaction ();
89                                 Assert.Fail ("#A1");
90                         } catch (InvalidOperationException ex) {
91                                 // Invalid operation. The connection is closed
92                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
93                                 Assert.IsNull (ex.InnerException, "#A3");
94                                 Assert.IsNotNull (ex.Message, "#A4");
95                         }
96
97                         try {
98                                 cn.BeginTransaction ((IsolationLevel) 666);
99                                 Assert.Fail ("#B1");
100                         } catch (InvalidOperationException ex) {
101                                 // Invalid operation. The connection is closed
102                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
103                                 Assert.IsNull (ex.InnerException, "#B3");
104                                 Assert.IsNotNull (ex.Message, "#B4");
105                         }
106
107                         try {
108                                 cn.BeginTransaction (IsolationLevel.Serializable);
109                                 Assert.Fail ("#C1");
110                         } catch (InvalidOperationException ex) {
111                                 // Invalid operation. The connection is closed
112                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
113                                 Assert.IsNull (ex.InnerException, "#C3");
114                                 Assert.IsNotNull (ex.Message, "#C4");
115                         }
116                 }
117
118                 [Test]
119                 public void ConnectionString ()
120                 {
121                         OleDbConnection cn = new OleDbConnection ();
122                         cn.ConnectionString = CONNECTION_STRING;
123                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#1");
124                         cn.ConnectionString = null;
125                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
126                         cn.ConnectionString = CONNECTION_STRING;
127                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#3");
128                         cn.ConnectionString = string.Empty;
129                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
130                 }
131
132                 [Test]
133                 public void GetSchema_Connection_Closed ()
134                 {
135                         OleDbConnection cn = new OleDbConnection ();
136
137                         try {
138                                 cn.GetSchema ();
139                                 Assert.Fail ("#A1");
140                         } catch (InvalidOperationException ex) {
141                                 // Invalid operation. The connection is closed
142                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
143                                 Assert.IsNull (ex.InnerException, "#B3");
144                                 Assert.IsNotNull (ex.Message, "#B4");
145                         }
146
147                         try {
148                                 cn.GetSchema ("Tables");
149                                 Assert.Fail ("#B1");
150                         } catch (InvalidOperationException ex) {
151                                 // Invalid operation. The connection is closed
152                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
153                                 Assert.IsNull (ex.InnerException, "#B3");
154                                 Assert.IsNotNull (ex.Message, "#B4");
155                         }
156
157                         try {
158                                 cn.GetSchema ((string) null);
159                                 Assert.Fail ("#C1");
160                         } catch (InvalidOperationException ex) {
161                                 // Invalid operation. The connection is closed
162                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
163                                 Assert.IsNull (ex.InnerException, "#C3");
164                                 Assert.IsNotNull (ex.Message, "#C4");
165                         }
166
167                         try {
168                                 cn.GetSchema ("Tables", new string [] { "master" });
169                                 Assert.Fail ("#D1");
170                         } catch (InvalidOperationException ex) {
171                                 // Invalid operation. The connection is closed
172                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
173                                 Assert.IsNull (ex.InnerException, "#D3");
174                                 Assert.IsNotNull (ex.Message, "#D4");
175                         }
176
177                         try {
178                                 cn.GetSchema ((string) null, new string [] { "master" });
179                                 Assert.Fail ("#E1");
180                         } catch (InvalidOperationException ex) {
181                                 // Invalid operation. The connection is closed
182                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
183                                 Assert.IsNull (ex.InnerException, "#E3");
184                                 Assert.IsNotNull (ex.Message, "#E4");
185                         }
186
187                         try {
188                                 cn.GetSchema ("Tables", (string []) null);
189                                 Assert.Fail ("#F1");
190                         } catch (InvalidOperationException ex) {
191                                 // Invalid operation. The connection is closed
192                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
193                                 Assert.IsNull (ex.InnerException, "#F3");
194                                 Assert.IsNotNull (ex.Message, "#F4");
195                         }
196
197                         try {
198                                 cn.GetSchema ((string) null, (string []) null);
199                                 Assert.Fail ("#G1");
200                         } catch (InvalidOperationException ex) {
201                                 // Invalid operation. The connection is closed
202                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
203                                 Assert.IsNull (ex.InnerException, "#G3");
204                                 Assert.IsNotNull (ex.Message, "#G4");
205                         }
206                 }
207
208                 [Test]
209                 public void ServerVersion_Connection_Closed ()
210                 {
211                         OleDbConnection cn = new OleDbConnection ();
212                         try {
213                                 Assert.Fail ("#A1:" + cn.ServerVersion);
214                         } catch (InvalidOperationException ex) {
215                                 // Invalid operation. The connection is closed
216                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
217                                 Assert.IsNull (ex.InnerException, "#A3");
218                                 Assert.IsNotNull (ex.Message, "#A4");
219                         }
220
221                         cn = new OleDbConnection (CONNECTION_STRING);
222                         try {
223                                 Assert.Fail ("#B1:" + cn.ServerVersion);
224                         } catch (InvalidOperationException ex) {
225                                 // Invalid operation. The connection is closed
226                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
227                                 Assert.IsNull (ex.InnerException, "#B3");
228                                 Assert.IsNotNull (ex.Message, "#B4");
229                         }
230                 }
231         }
232 }
233
234 #endif