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.
32 using System.Data.OleDb;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data.OleDb
39 public class OleDbConnectionTest
41 const string CONNECTION_STRING = "Provider=sqloledb;Data Source=SQLSRV;Initial Catalog=Mono;";
43 [Test] // OleDbConnection ()
44 public void Constructor1 ()
46 OleDbConnection cn = new OleDbConnection ();
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");
58 [Test] // OleDbConnection (string)
59 public void Constructor2 ()
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");
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");
83 public void BeginTransaction_Connection_Closed ()
85 OleDbConnection cn = new OleDbConnection ();
88 cn.BeginTransaction ();
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");
98 cn.BeginTransaction ((IsolationLevel) 666);
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");
108 cn.BeginTransaction (IsolationLevel.Serializable);
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");
119 public void ConnectionString ()
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");
133 public void GetSchema_Connection_Closed ()
135 OleDbConnection cn = new OleDbConnection ();
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");
148 cn.GetSchema ("Tables");
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");
158 cn.GetSchema ((string) null);
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");
168 cn.GetSchema ("Tables", new string [] { "master" });
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");
178 cn.GetSchema ((string) null, new string [] { "master" });
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");
188 cn.GetSchema ("Tables", (string []) null);
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");
198 cn.GetSchema ((string) null, (string []) null);
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");
209 public void ServerVersion_Connection_Closed ()
211 OleDbConnection cn = new OleDbConnection ();
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");
221 cn = new OleDbConnection (CONNECTION_STRING);
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");