2 // OleDbConnectionTest.cs - NUnit Test Cases for testing the
3 // OleDbConnectionTest class
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // Copyright (c) 2007 Gert Driesen
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System.Data.OleDb;
33 using NUnit.Framework;
35 namespace MonoTests.System.Data.OleDb
38 public class OleDbConnectionTest
40 const string CONNECTION_STRING = "Provider=sqloledb;Data Source=SQLSRV;Initial Catalog=Mono;";
42 [Test] // OleDbConnection ()
43 public void Constructor1 ()
45 OleDbConnection cn = new OleDbConnection ();
47 Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
48 Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
49 Assert.IsNull (cn.Container, "#3");
50 Assert.AreEqual (string.Empty, cn.Database, "#4");
51 Assert.AreEqual (string.Empty, cn.DataSource, "#5");
52 Assert.AreEqual (string.Empty, cn.Provider, "#6");
53 Assert.IsNull (cn.Site, "#7");
54 Assert.AreEqual (ConnectionState.Closed, cn.State, "#8");
57 [Test] // OleDbConnection (string)
58 public void Constructor2 ()
60 OleDbConnection cn = new OleDbConnection (CONNECTION_STRING);
61 Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#A1");
62 Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
63 Assert.IsNull (cn.Container, "#A3");
64 //Assert.AreEqual ("Mono", cn.Database, "#A4");
65 //Assert.AreEqual ("SQLSRV", cn.DataSource, "#A5");
66 //Assert.AreEqual ("sqloledb", cn.Provider, "#A6");
67 Assert.IsNull (cn.Site, "#A7");
68 Assert.AreEqual (ConnectionState.Closed, cn.State, "#A8");
70 cn = new OleDbConnection ((string) null);
71 Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
72 Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
73 Assert.IsNull (cn.Container, "#B3");
74 Assert.AreEqual (string.Empty, cn.Database, "#B4");
75 Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
76 Assert.AreEqual (string.Empty, cn.Provider, "#B6");
77 Assert.IsNull (cn.Site, "#B7");
78 Assert.AreEqual (ConnectionState.Closed, cn.State, "#B8");
82 public void BeginTransaction_Connection_Closed ()
84 OleDbConnection cn = new OleDbConnection ();
87 cn.BeginTransaction ();
89 } catch (InvalidOperationException ex) {
90 // Invalid operation. The connection is closed
91 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
92 Assert.IsNull (ex.InnerException, "#A3");
93 Assert.IsNotNull (ex.Message, "#A4");
97 cn.BeginTransaction ((IsolationLevel) 666);
99 } catch (InvalidOperationException ex) {
100 // Invalid operation. The connection is closed
101 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
102 Assert.IsNull (ex.InnerException, "#B3");
103 Assert.IsNotNull (ex.Message, "#B4");
107 cn.BeginTransaction (IsolationLevel.Serializable);
109 } catch (InvalidOperationException ex) {
110 // Invalid operation. The connection is closed
111 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
112 Assert.IsNull (ex.InnerException, "#C3");
113 Assert.IsNotNull (ex.Message, "#C4");
118 public void ConnectionString ()
120 OleDbConnection cn = new OleDbConnection ();
121 cn.ConnectionString = CONNECTION_STRING;
122 Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#1");
123 cn.ConnectionString = null;
124 Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
125 cn.ConnectionString = CONNECTION_STRING;
126 Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#3");
127 cn.ConnectionString = string.Empty;
128 Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
132 public void GetSchema_Connection_Closed ()
134 OleDbConnection cn = new OleDbConnection ();
139 } catch (InvalidOperationException ex) {
140 // Invalid operation. The connection is closed
141 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
142 Assert.IsNull (ex.InnerException, "#B3");
143 Assert.IsNotNull (ex.Message, "#B4");
147 cn.GetSchema ("Tables");
149 } catch (InvalidOperationException ex) {
150 // Invalid operation. The connection is closed
151 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
152 Assert.IsNull (ex.InnerException, "#B3");
153 Assert.IsNotNull (ex.Message, "#B4");
157 cn.GetSchema ((string) null);
159 } catch (InvalidOperationException ex) {
160 // Invalid operation. The connection is closed
161 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
162 Assert.IsNull (ex.InnerException, "#C3");
163 Assert.IsNotNull (ex.Message, "#C4");
167 cn.GetSchema ("Tables", new string [] { "master" });
169 } catch (InvalidOperationException ex) {
170 // Invalid operation. The connection is closed
171 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
172 Assert.IsNull (ex.InnerException, "#D3");
173 Assert.IsNotNull (ex.Message, "#D4");
177 cn.GetSchema ((string) null, new string [] { "master" });
179 } catch (InvalidOperationException ex) {
180 // Invalid operation. The connection is closed
181 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
182 Assert.IsNull (ex.InnerException, "#E3");
183 Assert.IsNotNull (ex.Message, "#E4");
187 cn.GetSchema ("Tables", (string []) null);
189 } catch (InvalidOperationException ex) {
190 // Invalid operation. The connection is closed
191 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
192 Assert.IsNull (ex.InnerException, "#F3");
193 Assert.IsNotNull (ex.Message, "#F4");
197 cn.GetSchema ((string) null, (string []) null);
199 } catch (InvalidOperationException ex) {
200 // Invalid operation. The connection is closed
201 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
202 Assert.IsNull (ex.InnerException, "#G3");
203 Assert.IsNotNull (ex.Message, "#G4");
208 public void ServerVersion_Connection_Closed ()
210 OleDbConnection cn = new OleDbConnection ();
212 Assert.Fail ("#A1:" + cn.ServerVersion);
213 } catch (InvalidOperationException ex) {
214 // Invalid operation. The connection is closed
215 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
216 Assert.IsNull (ex.InnerException, "#A3");
217 Assert.IsNotNull (ex.Message, "#A4");
220 cn = new OleDbConnection (CONNECTION_STRING);
222 Assert.Fail ("#B1:" + cn.ServerVersion);
223 } catch (InvalidOperationException ex) {
224 // Invalid operation. The connection is closed
225 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
226 Assert.IsNull (ex.InnerException, "#B3");
227 Assert.IsNotNull (ex.Message, "#B4");