[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient / OracleCommandTest.cs
1 //
2 // OracleCommandTest.cs -
3 //      NUnit Test Cases for OraclePermissionAttribute
4 //
5 // Author:
6 //      Leszek Ciesielski  <skolima@gmail.com>
7 //
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Data;
32 using System.Data.OracleClient;
33 using System.Data.SqlClient;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Data.OracleClient
38 {
39         [TestFixture]
40         public class OracleCommandTest
41         {
42                 const string COMMAND_TEXT = "SELECT * FROM dual";
43
44                 OracleCommand command;
45                 IDbCommand interface_command;
46
47                 [SetUp]
48                 public void SetUp ()
49                 {
50                         command = new OracleCommand ();
51                         interface_command = command;
52                 }
53
54                 [TearDown]
55                 public void TearDown ()
56                 {
57                         command.Dispose ();
58                 }
59
60                 [Test] // ctor ()
61                 public void Constructor1 ()
62                 {
63                         OracleCommand cmd = new OracleCommand ();
64                         Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
65                         Assert.AreEqual (0, cmd.CommandTimeout, "#2");
66                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
67                         Assert.IsNull (cmd.Connection, "#4");
68                         Assert.IsNull (cmd.Container, "#5");
69                         Assert.IsTrue (cmd.DesignTimeVisible, "#6");
70                         Assert.IsNotNull (cmd.Parameters, "#7");
71                         Assert.AreEqual (0, cmd.Parameters.Count, "#8");
72                         Assert.IsNull (cmd.Site, "#9");
73                         Assert.IsNull (cmd.Transaction, "#10");
74                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#11");
75                 }
76
77                 [Test] // ctor (String)
78                 public void Constructor2 ()
79                 {
80                         OracleCommand cmd = new OracleCommand (COMMAND_TEXT);
81                         Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
82                         Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
83                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
84                         Assert.IsNull (cmd.Connection, "#A4");
85                         Assert.IsNull (cmd.Container, "#A5");
86                         Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
87                         Assert.IsNotNull (cmd.Parameters, "#A7");
88                         Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
89                         Assert.IsNull (cmd.Site, "#A9");
90                         Assert.IsNull (cmd.Transaction, "#A10");
91                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
92
93                         cmd = new OracleCommand ((string) null);
94                         Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
95                         Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
96                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
97                         Assert.IsNull (cmd.Connection, "#B4");
98                         Assert.IsNull (cmd.Container, "#B5");
99                         Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
100                         Assert.IsNotNull (cmd.Parameters, "#B7");
101                         Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
102                         Assert.IsNull (cmd.Site, "#B9");
103                         Assert.IsNull (cmd.Transaction, "#B10");
104                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
105                 }
106
107                 [Test] // ctor (String, OracleConnection)
108                 public void Constructor3 ()
109                 {
110                         OracleConnection conn = new OracleConnection ();
111                         OracleCommand cmd;
112
113                         cmd = new OracleCommand (COMMAND_TEXT, conn);
114                         Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
115                         Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
116                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
117                         Assert.AreSame (conn, cmd.Connection, "#A4");
118                         Assert.IsNull (cmd.Container, "#A5");
119                         Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
120                         Assert.IsNotNull (cmd.Parameters, "#A7");
121                         Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
122                         Assert.IsNull (cmd.Site, "#A9");
123                         Assert.IsNull (cmd.Transaction, "#A10");
124                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
125
126                         cmd = new OracleCommand ((string) null, conn);
127                         Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
128                         Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
129                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
130                         Assert.AreSame (conn, cmd.Connection, "#B4");
131                         Assert.IsNull (cmd.Container, "#B5");
132                         Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
133                         Assert.IsNotNull (cmd.Parameters, "#B7");
134                         Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
135                         Assert.IsNull (cmd.Site, "#B9");
136                         Assert.IsNull (cmd.Transaction, "#B10");
137                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
138
139                         cmd = new OracleCommand (COMMAND_TEXT, (OracleConnection) null);
140                         Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
141                         Assert.AreEqual (0, cmd.CommandTimeout, "#C2");
142                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
143                         Assert.IsNull (cmd.Connection, "#C4");
144                         Assert.IsNull (cmd.Container, "#C5");
145                         Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
146                         Assert.IsNotNull (cmd.Parameters, "#C7");
147                         Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
148                         Assert.IsNull (cmd.Site, "#C9");
149                         Assert.IsNull (cmd.Transaction, "#C10");
150                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
151                 }
152
153                 [Test] // ctor (String, OracleConnection, OracleTransaction)
154                 public void Constructor4 ()
155                 {
156                         OracleConnection conn = new OracleConnection ();
157                         OracleCommand cmd;
158
159                         cmd = new OracleCommand (COMMAND_TEXT, conn, (OracleTransaction) null);
160                         Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
161                         Assert.AreEqual (0, cmd.CommandTimeout, "#A2");
162                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
163                         Assert.AreSame (conn, cmd.Connection, "#A4");
164                         Assert.IsNull (cmd.Container, "#A5");
165                         Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
166                         Assert.IsNotNull (cmd.Parameters, "#A7");
167                         Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
168                         Assert.IsNull (cmd.Site, "#A9");
169                         Assert.IsNull (cmd.Transaction, "#A10");
170                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
171
172                         cmd = new OracleCommand ((string) null, conn, (OracleTransaction) null);
173                         Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
174                         Assert.AreEqual (0, cmd.CommandTimeout, "#B2");
175                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
176                         Assert.AreSame (conn, cmd.Connection, "#B4");
177                         Assert.IsNull (cmd.Container, "#B5");
178                         Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
179                         Assert.IsNotNull (cmd.Parameters, "#B7");
180                         Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
181                         Assert.IsNull (cmd.Site, "#B9");
182                         Assert.IsNull (cmd.Transaction, "#B10");
183                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
184
185                         cmd = new OracleCommand (COMMAND_TEXT, (OracleConnection) null, (OracleTransaction) null);
186                         Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
187                         Assert.AreEqual (0, cmd.CommandTimeout, "#C2");
188                         Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
189                         Assert.IsNull (cmd.Connection, "#C4");
190                         Assert.IsNull (cmd.Container, "#C5");
191                         Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
192                         Assert.IsNotNull (cmd.Parameters, "#C7");
193                         Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
194                         Assert.IsNull (cmd.Site, "#C9");
195                         Assert.IsNull (cmd.Transaction, "#C10");
196                         Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
197                 }
198
199                 [Test] // bug #78765
200                 public void AllowNullTransactionTest ()
201                 {
202                         command.Transaction = null;
203                         interface_command.Transaction = null;
204                 }
205
206                 [Test]
207                 public void CommandText ()
208                 {
209                         OracleCommand cmd = new OracleCommand ();
210                         cmd.CommandText = COMMAND_TEXT;
211                         Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
212                         cmd.CommandText = null;
213                         Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
214                         cmd.CommandText = COMMAND_TEXT;
215                         Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
216                         cmd.CommandText = string.Empty;
217                         Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
218                 }
219
220                 [Test]
221                 public void CommandTimeout ()
222                 {
223                         Assert.AreEqual (0, command.CommandTimeout, "#1");
224                         command.CommandTimeout = 10;
225                         Assert.AreEqual (0, command.CommandTimeout, "#2");
226                         command.CommandTimeout = int.MaxValue;
227                         Assert.AreEqual (0, command.CommandTimeout, "#3");
228                         command.CommandTimeout = int.MinValue;
229                         Assert.AreEqual (0, command.CommandTimeout, "#4");
230                 }
231
232                 [Test]
233                 public void ConnectionTimeout_IDbConnection ()
234                 {
235                         Assert.AreEqual (0, interface_command.CommandTimeout, "#1");
236                         interface_command.CommandTimeout = 10;
237                         Assert.AreEqual (0, interface_command.CommandTimeout, "#2");
238                         interface_command.CommandTimeout = int.MaxValue;
239                         Assert.AreEqual (0, interface_command.CommandTimeout, "#3");
240                         interface_command.CommandTimeout = int.MinValue;
241                         Assert.AreEqual (0, interface_command.CommandTimeout, "#4");
242                 }
243
244                 [Test]
245                 public void Connection ()
246                 {
247                         OracleConnection connection = new OracleConnection ();
248
249                         Assert.IsNull (command.Connection, "#1");
250                         command.Connection = connection;
251                         Assert.AreSame (connection, command.Connection, "#2");
252                         Assert.AreSame (connection, interface_command.Connection, "#3");
253                         command.Connection = null;
254                         Assert.IsNull (command.Connection, "#4");
255                         Assert.IsNull (interface_command.Connection, "#5");
256                 }
257
258                 [Test]
259                 public void Connection_IDbConnection ()
260                 {
261                         OracleConnection connection = new OracleConnection ();
262
263                         Assert.IsNull (interface_command.Connection, "#A1");
264                         interface_command.Connection = connection;
265                         Assert.AreSame (connection, interface_command.Connection, "#A2");
266                         Assert.AreSame (connection, command.Connection, "#A3");
267                         interface_command.Connection = null;
268                         Assert.IsNull (interface_command.Connection, "#A4");
269                         Assert.IsNull (command.Connection, "#A5");
270
271                         try {
272                                 interface_command.Connection = new SqlConnection ();
273                                 Assert.Fail ("#B1");
274                         } catch (InvalidCastException ex) {
275                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
276                                 Assert.IsNull (ex.InnerException, "#B3");
277                                 Assert.IsNotNull (ex.Message, "#B4");
278                         }
279                 }
280         }
281 }