2 // SqlCommandTest.cs - NUnit Test Cases for testing
3 // System.Data.SqlClient.SqlCommand
6 // Gert Driesen (drieseng@users.sourceforge.net)
8 // Copyright (c) 2007 Gert Driesen
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Data.Sql;
33 using System.Data.SqlClient;
35 using NUnit.Framework;
37 namespace MonoTests.System.Data.SqlClient
40 public class SqlCommandTest
42 const string COMMAND_TEXT = "SELECT * FROM Authors";
44 [Test] // SqlCommand ()
45 #if FEATURE_NO_BSD_SOCKETS
46 [ExpectedException (typeof (PlatformNotSupportedException))]
48 public void Constructor1 ()
50 SqlCommand cmd = new SqlCommand ();
51 Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
52 Assert.AreEqual (30, cmd.CommandTimeout, "#2");
53 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
54 Assert.IsNull (cmd.Connection, "#4");
55 Assert.IsNull (cmd.Container, "#5");
56 Assert.IsTrue (cmd.DesignTimeVisible, "#6");
57 Assert.IsNull (cmd.Notification, "#7");
58 Assert.IsTrue (cmd.NotificationAutoEnlist, "#8");
59 Assert.IsNotNull (cmd.Parameters, "#9");
60 Assert.AreEqual (0, cmd.Parameters.Count, "#10");
61 Assert.IsNull (cmd.Site, "#11");
62 Assert.IsNull (cmd.Transaction, "#11");
63 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#12");
66 [Test] // SqlCommand (string)
67 #if FEATURE_NO_BSD_SOCKETS
68 [ExpectedException (typeof (PlatformNotSupportedException))]
70 public void Constructor2 ()
72 SqlCommand cmd = new SqlCommand (COMMAND_TEXT);
73 Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
74 Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
75 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
76 Assert.IsNull (cmd.Connection, "#A4");
77 Assert.IsNull (cmd.Container, "#A5");
78 Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
79 Assert.IsNull (cmd.Notification, "#A7");
80 Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
81 Assert.IsNotNull (cmd.Parameters, "#A9");
82 Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
83 Assert.IsNull (cmd.Site, "#A11");
84 Assert.IsNull (cmd.Transaction, "#A12");
85 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
87 cmd = new SqlCommand ((string) null);
88 Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
89 Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
90 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
91 Assert.IsNull (cmd.Connection, "#B4");
92 Assert.IsNull (cmd.Container, "#B5");
93 Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
94 Assert.IsNull (cmd.Notification, "#B7");
95 Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
96 Assert.IsNotNull (cmd.Parameters, "#B9");
97 Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
98 Assert.IsNull (cmd.Site, "#B11");
99 Assert.IsNull (cmd.Transaction, "#B12");
100 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
103 [Test] // SqlCommand (string, SqlConnection)
104 #if FEATURE_NO_BSD_SOCKETS
105 [ExpectedException (typeof (PlatformNotSupportedException))]
107 public void Constructor3 ()
109 SqlConnection conn = new SqlConnection ();
112 cmd = new SqlCommand (COMMAND_TEXT, conn);
113 Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
114 Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
115 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
116 Assert.AreSame (conn, cmd.Connection, "#A4");
117 Assert.IsNull (cmd.Container, "#A5");
118 Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
119 Assert.IsNull (cmd.Notification, "#A7");
120 Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
121 Assert.IsNotNull (cmd.Parameters, "#A9");
122 Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
123 Assert.IsNull (cmd.Site, "#A11");
124 Assert.IsNull (cmd.Transaction, "#A12");
125 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
127 cmd = new SqlCommand ((string) null, conn);
128 Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
129 Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
130 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
131 Assert.AreSame (conn, cmd.Connection, "#B4");
132 Assert.IsNull (cmd.Container, "#B5");
133 Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
134 Assert.IsNull (cmd.Notification, "#B7");
135 Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
136 Assert.IsNotNull (cmd.Parameters, "#B9");
137 Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
138 Assert.IsNull (cmd.Site, "#B11");
139 Assert.IsNull (cmd.Transaction, "#B12");
140 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
142 cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null);
143 Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
144 Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
145 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
146 Assert.IsNull (cmd.Connection, "#C4");
147 Assert.IsNull (cmd.Container, "#C5");
148 Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
149 Assert.IsNull (cmd.Notification, "#C7");
150 Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
151 Assert.IsNotNull (cmd.Parameters, "#C9");
152 Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
153 Assert.IsNull (cmd.Site, "#C11");
154 Assert.IsNull (cmd.Transaction, "#C12");
155 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
158 [Test] // SqlCommand (string, SqlConnection, SqlTransaction)
159 #if FEATURE_NO_BSD_SOCKETS
160 [ExpectedException (typeof (PlatformNotSupportedException))]
162 public void Constructor4 ()
164 SqlConnection conn = new SqlConnection ();
167 cmd = new SqlCommand (COMMAND_TEXT, conn, (SqlTransaction) null);
168 Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
169 Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
170 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
171 Assert.AreSame (conn, cmd.Connection, "#A4");
172 Assert.IsNull (cmd.Container, "#A5");
173 Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
174 Assert.IsNull (cmd.Notification, "#A7");
175 Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
176 Assert.IsNotNull (cmd.Parameters, "#A9");
177 Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
178 Assert.IsNull (cmd.Site, "#A11");
179 Assert.IsNull (cmd.Transaction, "#A12");
180 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
182 cmd = new SqlCommand ((string) null, conn, (SqlTransaction) null);
183 Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
184 Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
185 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
186 Assert.AreSame (conn, cmd.Connection, "#B4");
187 Assert.IsNull (cmd.Container, "#B5");
188 Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
189 Assert.IsNull (cmd.Notification, "#B7");
190 Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
191 Assert.IsNotNull (cmd.Parameters, "#B9");
192 Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
193 Assert.IsNull (cmd.Site, "#B11");
194 Assert.IsNull (cmd.Transaction, "#B12");
195 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
197 cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null, (SqlTransaction) null);
198 Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
199 Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
200 Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
201 Assert.IsNull (cmd.Connection, "#C4");
202 Assert.IsNull (cmd.Container, "#C5");
203 Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
204 Assert.IsNull (cmd.Notification, "#C7");
205 Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
206 Assert.IsNotNull (cmd.Parameters, "#C9");
207 Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
208 Assert.IsNull (cmd.Site, "#C11");
209 Assert.IsNull (cmd.Transaction, "#C12");
210 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
214 #if FEATURE_NO_BSD_SOCKETS
215 [ExpectedException (typeof (PlatformNotSupportedException))]
219 SqlNotificationRequest notificationReq = new SqlNotificationRequest ();
221 SqlCommand cmd = new SqlCommand ();
222 cmd.CommandText = "sp_insert";
223 cmd.CommandTimeout = 100;
224 cmd.CommandType = CommandType.StoredProcedure;
225 cmd.DesignTimeVisible = false;
226 cmd.Notification = notificationReq;
227 cmd.NotificationAutoEnlist = false;
228 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
229 cmd.Parameters ["@TestPar1"].Value = DBNull.Value;
230 cmd.Parameters.AddWithValue ("@BirthDate", DateTime.Now);
231 cmd.UpdatedRowSource = UpdateRowSource.OutputParameters;
233 SqlCommand clone = (((ICloneable) (cmd)).Clone ()) as SqlCommand;
234 Assert.AreEqual ("sp_insert", clone.CommandText, "#1");
235 Assert.AreEqual (100, clone.CommandTimeout, "#2");
236 Assert.AreEqual (CommandType.StoredProcedure, clone.CommandType, "#3");
237 Assert.IsNull (cmd.Connection, "#4");
238 Assert.IsFalse (cmd.DesignTimeVisible, "#5");
239 Assert.AreSame (notificationReq, cmd.Notification, "#6");
240 Assert.IsFalse (cmd.NotificationAutoEnlist, "#7");
241 Assert.AreEqual (2, clone.Parameters.Count, "#8");
242 Assert.AreEqual (100, clone.CommandTimeout, "#9");
243 clone.Parameters.AddWithValue ("@test", DateTime.Now);
244 clone.Parameters [0].ParameterName = "@ClonePar1";
245 Assert.AreEqual (3, clone.Parameters.Count, "#10");
246 Assert.AreEqual (2, cmd.Parameters.Count, "#11");
247 Assert.AreEqual ("@ClonePar1", clone.Parameters [0].ParameterName, "#12");
248 Assert.AreEqual ("@TestPar1", cmd.Parameters [0].ParameterName, "#13");
249 Assert.AreEqual ("@BirthDate", clone.Parameters [1].ParameterName, "#14");
250 Assert.AreEqual ("@BirthDate", cmd.Parameters [1].ParameterName, "#15");
251 Assert.IsNull (clone.Transaction, "#16");
255 #if FEATURE_NO_BSD_SOCKETS
256 [ExpectedException (typeof (PlatformNotSupportedException))]
258 public void CommandText ()
260 SqlCommand cmd = new SqlCommand ();
261 cmd.CommandText = COMMAND_TEXT;
262 Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
263 cmd.CommandText = null;
264 Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
265 cmd.CommandText = COMMAND_TEXT;
266 Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
267 cmd.CommandText = string.Empty;
268 Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
272 #if FEATURE_NO_BSD_SOCKETS
273 [ExpectedException (typeof (PlatformNotSupportedException))]
275 public void CommandTimeout ()
277 SqlCommand cmd = new SqlCommand ();
278 cmd.CommandTimeout = 10;
279 Assert.AreEqual (10, cmd.CommandTimeout, "#1");
280 cmd.CommandTimeout = 25;
281 Assert.AreEqual (25, cmd.CommandTimeout, "#2");
282 cmd.CommandTimeout = 0;
283 Assert.AreEqual (0, cmd.CommandTimeout, "#3");
287 #if FEATURE_NO_BSD_SOCKETS
288 [ExpectedException (typeof (PlatformNotSupportedException))]
290 public void CommandTimeout_Value_Negative ()
292 SqlCommand cmd = new SqlCommand ();
294 cmd.CommandTimeout = -1;
296 } catch (ArgumentException ex) {
297 // Invalid CommandTimeout value -1; the value must be >= 0
298 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
299 Assert.IsNull (ex.InnerException, "#3");
300 Assert.IsNotNull (ex.Message, "#4");
301 Assert.AreEqual ("CommandTimeout", ex.ParamName, "#5");
306 #if FEATURE_NO_BSD_SOCKETS
307 [ExpectedException (typeof (PlatformNotSupportedException))]
309 public void CommandType_Value_Invalid ()
311 SqlCommand cmd = new SqlCommand ();
313 cmd.CommandType = (CommandType) (666);
315 } catch (ArgumentOutOfRangeException ex) {
316 // The CommandType enumeration value, 666, is invalid
317 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
318 Assert.IsNull (ex.InnerException, "#3");
319 Assert.IsNotNull (ex.Message, "#4");
320 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#5");
321 Assert.AreEqual ("CommandType", ex.ParamName, "#6");
325 [Test] // bug #324386
326 #if FEATURE_NO_BSD_SOCKETS
327 [ExpectedException (typeof (PlatformNotSupportedException))]
329 public void Dispose ()
331 string connectionString = "Initial Catalog=a;Server=b;User ID=c;"
333 SqlConnection connection = new SqlConnection (connectionString);
334 SqlCommand command = connection.CreateCommand ();
336 Assert.AreEqual (connectionString, connection.ConnectionString);
340 #if FEATURE_NO_BSD_SOCKETS
341 [ExpectedException (typeof (PlatformNotSupportedException))]
343 public void ExecuteNonQuery_Connection_Closed ()
345 string connectionString = "Initial Catalog=a;Server=b;User ID=c;"
347 SqlConnection cn = new SqlConnection (connectionString);
349 SqlCommand cmd = new SqlCommand ("delete from whatever", cn);
351 cmd.ExecuteNonQuery ();
353 } catch (InvalidOperationException ex) {
354 // ExecuteNonQuery requires an open and available
355 // Connection. The connection's current state is
357 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
358 Assert.IsNull (ex.InnerException, "#3");
359 Assert.IsNotNull (ex.Message, "#4");
360 Assert.IsTrue (ex.Message.IndexOf ("ExecuteNonQuery") != -1, "#5");
365 #if FEATURE_NO_BSD_SOCKETS
366 [ExpectedException (typeof (PlatformNotSupportedException))]
368 public void ExecuteNonQuery_Connection_Null ()
370 SqlCommand cmd = new SqlCommand ("delete from whatever");
372 cmd.ExecuteNonQuery ();
374 } catch (InvalidOperationException ex) {
375 // ExecuteNonQuery: Connection property has not
377 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
378 Assert.IsNull (ex.InnerException, "#3");
379 Assert.IsNotNull (ex.Message, "#4");
380 Assert.IsTrue (ex.Message.StartsWith ("ExecuteNonQuery:"), "#5");
385 #if FEATURE_NO_BSD_SOCKETS
386 [ExpectedException (typeof (PlatformNotSupportedException))]
388 public void ExecuteReader_Connection_Closed ()
390 string connectionString = "Initial Catalog=a;Server=b;User ID=c;"
392 SqlConnection cn = new SqlConnection (connectionString);
394 SqlCommand cmd = new SqlCommand ("Select count(*) from whatever", cn);
396 cmd.ExecuteReader ();
398 } catch (InvalidOperationException ex) {
399 // ExecuteReader requires an open and available
400 // Connection. The connection's current state is
402 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
403 Assert.IsNull (ex.InnerException, "#3");
404 Assert.IsNotNull (ex.Message, "#4");
405 Assert.IsTrue (ex.Message.IndexOf ("ExecuteReader") != -1, "#5");
410 #if FEATURE_NO_BSD_SOCKETS
411 [ExpectedException (typeof (PlatformNotSupportedException))]
413 public void ExecuteReader_Connection_Null ()
415 SqlCommand cmd = new SqlCommand ("select * from whatever");
417 cmd.ExecuteReader ();
419 } catch (InvalidOperationException ex) {
420 // ExecuteReader: Connection property has not
422 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
423 Assert.IsNull (ex.InnerException, "#3");
424 Assert.IsNotNull (ex.Message, "#4");
425 Assert.IsTrue (ex.Message.StartsWith ("ExecuteReader:"), "#5");
430 #if FEATURE_NO_BSD_SOCKETS
431 [ExpectedException (typeof (PlatformNotSupportedException))]
433 public void ExecuteScalar_Connection_Closed ()
435 string connectionString = "Initial Catalog=a;Server=b;User ID=c;"
437 SqlConnection cn = new SqlConnection (connectionString);
439 SqlCommand cmd = new SqlCommand ("Select count(*) from whatever", cn);
441 cmd.ExecuteScalar ();
443 } catch (InvalidOperationException ex) {
444 // ExecuteScalar requires an open and available
445 // Connection. The connection's current state is
447 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
448 Assert.IsNull (ex.InnerException, "#3");
449 Assert.IsNotNull (ex.Message, "#4");
450 Assert.IsTrue (ex.Message.IndexOf ("ExecuteScalar") != -1, "#5");
454 [Test] // bug #412584
455 #if FEATURE_NO_BSD_SOCKETS
456 [ExpectedException (typeof (PlatformNotSupportedException))]
458 public void ExecuteScalar_Connection_Null ()
460 SqlCommand cmd = new SqlCommand ("select count(*) from whatever");
462 cmd.ExecuteScalar ();
464 } catch (InvalidOperationException ex) {
465 // ExecuteScalar: Connection property has not
467 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
468 Assert.IsNull (ex.InnerException, "#3");
469 Assert.IsNotNull (ex.Message, "#4");
470 Assert.IsTrue (ex.Message.StartsWith ("ExecuteScalar:"), "#5");
474 // FIXME: this actually doesn't match .NET behavior. It shouldn't throw NRE.
476 #if FEATURE_NO_BSD_SOCKETS
477 [ExpectedException (typeof (PlatformNotSupportedException))]
479 public void Prepare_Connection_Null ()
483 // Text, without parameters
484 cmd = new SqlCommand ("select count(*) from whatever");
488 } catch (NullReferenceException) {
491 // Text, with parameters
492 cmd = new SqlCommand ("select count(*) from whatever");
493 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
497 } catch (NullReferenceException) {
500 // Text, without parameters
501 cmd = new SqlCommand ("select count(*) from whatever");
502 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
503 cmd.Parameters.Clear ();
507 } catch (NullReferenceException) {
510 // StoredProcedure, without parameters
511 cmd = new SqlCommand ("FindCustomer");
512 cmd.CommandType = CommandType.StoredProcedure;
516 } catch (NullReferenceException) {
519 // StoredProcedure, with parameters
520 cmd = new SqlCommand ("FindCustomer");
521 cmd.CommandType = CommandType.StoredProcedure;
522 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
526 } catch (NullReferenceException) {
530 [Test] // bug #412586
531 #if FEATURE_NO_BSD_SOCKETS
532 [ExpectedException (typeof (PlatformNotSupportedException))]
534 public void Prepare_Connection_Closed ()
536 string connectionString = "Initial Catalog=a;Server=b;User ID=c;"
538 SqlConnection cn = new SqlConnection (connectionString);
542 // Text, without parameters
543 cmd = new SqlCommand ("select count(*) from whatever", cn);
546 // Text, with parameters
547 cmd = new SqlCommand ("select count(*) from whatever", cn);
548 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
552 } catch (InvalidOperationException ex) {
553 // Prepare requires an open and available
554 // Connection. The connection's current state
556 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
557 Assert.IsNull (ex.InnerException, "#A3");
558 Assert.IsNotNull (ex.Message, "#A4");
559 Assert.IsTrue (ex.Message.IndexOf ("Prepare") != -1, "#A5");
562 // Text, parameters cleared
563 cmd = new SqlCommand ("select count(*) from whatever", cn);
564 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
565 cmd.Parameters.Clear ();
568 // StoredProcedure, without parameters
569 cmd = new SqlCommand ("FindCustomer", cn);
570 cmd.CommandType = CommandType.StoredProcedure;
573 // StoredProcedure, with parameters
574 cmd = new SqlCommand ("FindCustomer", cn);
575 cmd.CommandType = CommandType.StoredProcedure;
576 cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
579 // ensure connection was not implictly opened
580 Assert.AreEqual (ConnectionState.Closed, cn.State, "#B");
584 #if FEATURE_NO_BSD_SOCKETS
585 [ExpectedException (typeof (PlatformNotSupportedException))]
587 public void ResetCommandTimeout ()
589 SqlCommand cmd = new SqlCommand ();
590 cmd.CommandTimeout = 50;
591 Assert.AreEqual (cmd.CommandTimeout, 50, "#1");
592 cmd.ResetCommandTimeout ();
593 Assert.AreEqual (cmd.CommandTimeout, 30, "#2");
597 #if FEATURE_NO_BSD_SOCKETS
598 [ExpectedException (typeof (PlatformNotSupportedException))]
600 public void UpdatedRowSource ()
602 SqlCommand cmd = new SqlCommand ();
603 cmd.UpdatedRowSource = UpdateRowSource.None;
604 Assert.AreEqual (UpdateRowSource.None, cmd.UpdatedRowSource, "#1");
605 cmd.UpdatedRowSource = UpdateRowSource.OutputParameters;
606 Assert.AreEqual (UpdateRowSource.OutputParameters, cmd.UpdatedRowSource, "#2");
610 #if FEATURE_NO_BSD_SOCKETS
611 [ExpectedException (typeof (PlatformNotSupportedException))]
613 public void UpdatedRowSource_Value_Invalid ()
615 SqlCommand cmd = new SqlCommand ();
617 cmd.UpdatedRowSource = (UpdateRowSource) 666;
619 } catch (ArgumentOutOfRangeException ex) {
620 // The UpdateRowSource enumeration value,666,
622 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
623 Assert.IsNull (ex.InnerException, "#3");
624 Assert.IsNotNull (ex.Message, "#4");
625 Assert.AreEqual ("UpdateRowSource", ex.ParamName, "#5");
630 [Test] // bug #381100
631 #if FEATURE_NO_BSD_SOCKETS
632 [ExpectedException (typeof (PlatformNotSupportedException))]
634 public void ParameterCollectionTest ()
636 SqlCommand cmd = new SqlCommand();
637 cmd.Parameters.AddRange(new SqlParameter[] { });