[System.Data] Fixes tests build with mobile profiles
[mono.git] / mcs / class / System.Data / Test / System.Data.Odbc / OdbcConnectionTest.cs
1 //
2 // OdbcConnectionTest.cs - NUnit Test Cases for testing the
3 //                          OdbcConnectionTest 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_ODBC
30
31 using System;
32 using System.Data;
33 using System.Data.Odbc;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Data.Odbc
38 {
39         [TestFixture]
40         public class OdbcConnectionTest
41         {
42                 const string CONNECTION_STRING = "Driver={SQL Server};Server=SQLSRV;Database=Mono;";
43
44                 [Test] // OdbcConnection ()
45                 public void Constructor1 ()
46                 {
47                         OdbcConnection cn = new OdbcConnection ();
48
49                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
50                         Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
51                         Assert.IsNull (cn.Container, "#3");
52                         Assert.AreEqual (string.Empty, cn.Database, "#4");
53                         Assert.AreEqual (string.Empty, cn.DataSource, "#5");
54                         Assert.AreEqual (string.Empty, cn.Driver, "#6");
55                         Assert.IsNull (cn.Site, "#7");
56                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#8");
57                 }
58
59                 [Test] // OdbcConnection (string)
60                 public void Constructor2 ()
61                 {
62                         OdbcConnection cn = new OdbcConnection (CONNECTION_STRING);
63                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#A1");
64                         Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
65                         Assert.IsNull (cn.Container, "#A3");
66                         Assert.AreEqual (string.Empty, cn.Database, "#A4");
67                         Assert.AreEqual (string.Empty, cn.DataSource, "#A5");
68                         Assert.AreEqual (string.Empty, cn.Driver, "#A6");
69                         Assert.IsNull (cn.Site, "#A7");
70                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#A8");
71
72                         cn = new OdbcConnection ((string) null);
73                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
74                         Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
75                         Assert.IsNull (cn.Container, "#B3");
76                         Assert.AreEqual (string.Empty, cn.Database, "#B4");
77                         Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
78                         Assert.AreEqual (string.Empty, cn.Driver, "#B6");
79                         Assert.IsNull (cn.Site, "#B7");
80                         Assert.AreEqual (ConnectionState.Closed, cn.State, "#B8");
81                 }
82
83                 [Test]
84                 public void BeginTransaction_Connection_Closed ()
85                 {
86                         OdbcConnection cn = new OdbcConnection ();
87
88                         try {
89                                 cn.BeginTransaction ();
90                                 Assert.Fail ("#A1");
91                         } catch (InvalidOperationException ex) {
92                                 // Invalid operation. The connection is closed
93                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
94                                 Assert.IsNull (ex.InnerException, "#A3");
95                                 Assert.IsNotNull (ex.Message, "#A4");
96                         }
97
98                         try {
99                                 cn.BeginTransaction ((IsolationLevel) 666);
100                                 Assert.Fail ("#B1");
101                         } catch (InvalidOperationException ex) {
102                                 // Invalid operation. The connection is closed
103                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
104                                 Assert.IsNull (ex.InnerException, "#B3");
105                                 Assert.IsNotNull (ex.Message, "#B4");
106                         }
107
108                         try {
109                                 cn.BeginTransaction (IsolationLevel.Serializable);
110                                 Assert.Fail ("#C1");
111                         } catch (InvalidOperationException ex) {
112                                 // Invalid operation. The connection is closed
113                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
114                                 Assert.IsNull (ex.InnerException, "#C3");
115                                 Assert.IsNotNull (ex.Message, "#C4");
116                         }
117                 }
118
119                 [Test]
120                 public void ConnectionString ()
121                 {
122                         OdbcConnection cn = new OdbcConnection ();
123                         cn.ConnectionString = CONNECTION_STRING;
124                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#1");
125                         cn.ConnectionString = null;
126                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
127                         cn.ConnectionString = CONNECTION_STRING;
128                         Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#3");
129                         cn.ConnectionString = string.Empty;
130                         Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
131                 }
132
133                 [Test]
134                 public void GetSchema_Connection_Closed ()
135                 {
136                         OdbcConnection cn = new OdbcConnection ();
137
138                         try {
139                                 cn.GetSchema ();
140                                 Assert.Fail ("#A1");
141                         } catch (InvalidOperationException ex) {
142                                 // Invalid operation. The connection is closed
143                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
144                                 Assert.IsNull (ex.InnerException, "#B3");
145                                 Assert.IsNotNull (ex.Message, "#B4");
146                         }
147
148                         try {
149                                 cn.GetSchema ("Tables");
150                                 Assert.Fail ("#B1");
151                         } catch (InvalidOperationException ex) {
152                                 // Invalid operation. The connection is closed
153                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
154                                 Assert.IsNull (ex.InnerException, "#B3");
155                                 Assert.IsNotNull (ex.Message, "#B4");
156                         }
157
158                         try {
159                                 cn.GetSchema ((string) null);
160                                 Assert.Fail ("#C1");
161                         } catch (InvalidOperationException ex) {
162                                 // Invalid operation. The connection is closed
163                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
164                                 Assert.IsNull (ex.InnerException, "#C3");
165                                 Assert.IsNotNull (ex.Message, "#C4");
166                         }
167
168                         try {
169                                 cn.GetSchema ("Tables", new string [] { "master" });
170                                 Assert.Fail ("#D1");
171                         } catch (InvalidOperationException ex) {
172                                 // Invalid operation. The connection is closed
173                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
174                                 Assert.IsNull (ex.InnerException, "#D3");
175                                 Assert.IsNotNull (ex.Message, "#D4");
176                         }
177
178                         try {
179                                 cn.GetSchema ((string) null, new string [] { "master" });
180                                 Assert.Fail ("#E1");
181                         } catch (InvalidOperationException ex) {
182                                 // Invalid operation. The connection is closed
183                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
184                                 Assert.IsNull (ex.InnerException, "#E3");
185                                 Assert.IsNotNull (ex.Message, "#E4");
186                         }
187
188                         try {
189                                 cn.GetSchema ("Tables", (string []) null);
190                                 Assert.Fail ("#F1");
191                         } catch (InvalidOperationException ex) {
192                                 // Invalid operation. The connection is closed
193                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
194                                 Assert.IsNull (ex.InnerException, "#F3");
195                                 Assert.IsNotNull (ex.Message, "#F4");
196                         }
197
198                         try {
199                                 cn.GetSchema ((string) null, (string []) null);
200                                 Assert.Fail ("#G1");
201                         } catch (InvalidOperationException ex) {
202                                 // Invalid operation. The connection is closed
203                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
204                                 Assert.IsNull (ex.InnerException, "#G3");
205                                 Assert.IsNotNull (ex.Message, "#G4");
206                         }
207                 }
208
209                 [Test]
210                 public void ServerVersion_Connection_Closed ()
211                 {
212                         OdbcConnection cn = new OdbcConnection ();
213                         try {
214                                 Assert.Fail ("#A1:" + cn.ServerVersion);
215                         } catch (InvalidOperationException ex) {
216                                 // Invalid operation. The connection is closed
217                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
218                                 Assert.IsNull (ex.InnerException, "#A3");
219                                 Assert.IsNotNull (ex.Message, "#A4");
220                         }
221
222                         cn = new OdbcConnection (CONNECTION_STRING);
223                         try {
224                                 Assert.Fail ("#B1:" + cn.ServerVersion);
225                         } catch (InvalidOperationException ex) {
226                                 // Invalid operation. The connection is closed
227                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
228                                 Assert.IsNull (ex.InnerException, "#B3");
229                                 Assert.IsNotNull (ex.Message, "#B4");
230                         }
231                 }
232         }
233 }
234
235 #endif