2 // SqlCommandTest.cs - NUnit Test Cases for testing the
5 // Umadevi S (sumadevi@novell.com)
6 // Sureshkumar T (tsureshkumar@novell.com)
7 // Senganal T (tsenganal@novell.com)
9 // Copyright (c) 2004 Novell Inc., and the individuals listed
10 // on the ChangeLog entries.
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Data.Common;
35 using System.Data.SqlClient;
37 using NUnit.Framework;
39 namespace MonoTests.System.Data.SqlClient
42 [Category ("sqlserver")]
43 public class SqlCommandTest
46 public SqlConnection conn = null ;
47 SqlCommand cmd = null;
48 string connectionString = ConnectionManager.Singleton.ConnectionString;
56 public void TearDown ()
63 public void ConstructorTest ()
65 // Test Default Constructor
66 cmd = new SqlCommand ();
67 Assert.AreEqual (String.Empty, cmd.CommandText,
68 "#1 Command Test should be empty");
69 Assert.AreEqual (30, cmd.CommandTimeout,
70 "#2 CommandTimeout should be 30");
71 Assert.AreEqual (CommandType.Text, cmd.CommandType,
72 "#3 CommandType should be text");
73 Assert.IsNull (cmd.Connection, "#4 Connection Should be null");
74 Assert.AreEqual (0, cmd.Parameters.Count,
75 "#5 Parameter shud be empty");
77 // Test Overloaded Constructor
78 String cmdText = "select * from tbl1" ;
79 cmd = new SqlCommand (cmdText);
80 Assert.AreEqual (cmdText, cmd.CommandText,
81 "#5 CommandText should be the same as passed");
82 Assert.AreEqual (30, cmd.CommandTimeout,
83 "#6 CommandTimeout should be 30");
84 Assert.AreEqual (CommandType.Text, cmd.CommandType,
85 "#7 CommandType should be text");
86 Assert.IsNull (cmd.Connection , "#8 Connection Should be null");
88 // Test Overloaded Constructor
89 SqlConnection conn = new SqlConnection ();
90 cmd = new SqlCommand (cmdText , conn);
91 Assert.AreEqual (cmdText, cmd.CommandText,
92 "#9 CommandText should be the same as passed");
93 Assert.AreEqual (30, cmd.CommandTimeout,
94 "#10 CommandTimeout should be 30");
95 Assert.AreEqual (CommandType.Text, cmd.CommandType,
96 "#11 CommandType should be text");
97 Assert.AreSame (cmd.Connection, conn, "#12 Connection Should be same");
99 // Test Overloaded Constructor
100 SqlTransaction trans = null ;
102 conn = new SqlConnection (connectionString);
104 trans = conn.BeginTransaction ();
105 cmd = new SqlCommand (cmdText, conn, trans);
106 Assert.AreEqual (cmdText, cmd.CommandText,
107 "#9 CommandText should be the same as passed");
108 Assert.AreEqual (30, cmd.CommandTimeout,
109 "#10 CommandTimeout should be 30");
110 Assert.AreEqual (CommandType.Text, cmd.CommandType,
111 "#11 CommandType should be text");
112 Assert.AreEqual (cmd.Connection, conn,
113 "#12 Connection Should be null");
114 Assert.AreEqual (cmd.Transaction, trans,
115 "#13 Transaction Property should be set");
117 // Test if parameters are reset to Default Values
118 cmd = new SqlCommand ();
119 Assert.AreEqual (String.Empty, cmd.CommandText,
120 "#1 Command Test should be empty");
121 Assert.AreEqual (30, cmd.CommandTimeout,
122 "#2 CommandTimeout should be 30");
123 Assert.AreEqual (CommandType.Text, cmd.CommandType,
124 "#3 CommandType should be text");
125 Assert.IsNull (cmd.Connection, "#4 Connection Should be null");
132 public void ExecuteScalarTest ()
134 conn = new SqlConnection (connectionString);
135 cmd = new SqlCommand ("" , conn);
136 cmd.CommandText = "Select count(*) from numeric_family where id<=4";
138 //Check Exception is thrown when executed on a closed connection
140 cmd.ExecuteScalar ();
141 Assert.Fail ("#1 InvalidOperation Exception must be thrown");
142 }catch (AssertionException e) {
144 }catch (Exception e) {
145 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
146 "#2 Incorrect Exception : " + e.StackTrace);
149 // Check the Return value for a Correct Query
152 result = cmd.ExecuteScalar ();
153 Assert.AreEqual (4, (int)result, "#3 Query Result returned is incorrect");
155 cmd.CommandText = "select id , type_bit from numeric_family order by id asc" ;
156 result = Convert.ToInt32 (cmd.ExecuteScalar ());
157 Assert.AreEqual (1, result,
158 "#4 ExecuteScalar Should return (1,1) the result set" );
160 cmd.CommandText = "select id from numeric_family where id=-1";
161 result = cmd.ExecuteScalar ();
162 Assert.IsNull (result, "#5 Null shud be returned if result set is empty");
164 // Check SqlException is thrown for Invalid Query
165 cmd.CommandText = "select count* from numeric_family";
167 result = cmd.ExecuteScalar ();
168 Assert.Fail ("#6 InCorrect Query should cause an SqlException");
169 }catch (AssertionException e) {
171 }catch (Exception e) {
172 Assert.AreEqual (typeof(SqlException), e.GetType(),
173 "#7 Incorrect Exception : " + e.StackTrace);
178 public void ExecuteNonQuery ()
180 conn = new SqlConnection (connectionString);
181 cmd = new SqlCommand ("", conn);
184 // Test for exceptions
185 // Test exception is thrown if connection is closed
186 cmd.CommandText = "Select id from numeric_family where id=1";
188 cmd.ExecuteNonQuery ();
189 Assert.Fail ("#1 Connextion shud be open");
190 }catch (AssertionException e) {
192 }catch (Exception e) {
193 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
194 "#2 Incorrect Exception : " + e);
197 // Test Exception is thrown if Query is incorrect
199 cmd.CommandText = "Select id1 from numeric_family";
201 cmd.ExecuteNonQuery ();
202 Assert.Fail ("#1 invalid Query");
203 }catch (AssertionException e) {
205 }catch (Exception e) {
206 Assert.AreEqual (typeof(SqlException), e.GetType(),
207 "#2 Incorrect Exception : " + e);
210 // Test Select/Insert/Update/Delete Statements
211 SqlTransaction trans = conn.BeginTransaction ();
212 cmd.Transaction = trans;
215 cmd.CommandText = "Select id from numeric_family where id=1";
216 result = cmd.ExecuteNonQuery ();
217 Assert.AreEqual (-1, result, "#1");
219 cmd.CommandText = "Insert into numeric_family (id,type_int) values (100,200)";
220 result = cmd.ExecuteNonQuery ();
221 Assert.AreEqual (1, result, "#2 One row shud be inserted");
223 cmd.CommandText = "Update numeric_family set type_int=300 where id=100";
224 result = cmd.ExecuteNonQuery ();
225 Assert.AreEqual (1, result, "#3 One row shud be updated");
227 // Test Batch Commands
228 cmd.CommandText = "Select id from numeric_family where id=1;";
229 cmd.CommandText += "update numeric_family set type_int=10 where id=1000";
230 cmd.CommandText += "update numeric_family set type_int=10 where id=100";
231 result = cmd.ExecuteNonQuery ();
232 Assert.AreEqual (1, result, "#4 One row shud be updated");
234 cmd.CommandText = "Delete from numeric_family where id=100";
235 result = cmd.ExecuteNonQuery ();
236 Assert.AreEqual (1, result, "#5 One row shud be deleted");
244 public void ExecuteReaderTest ()
246 SqlDataReader reader = null;
247 conn = new SqlConnection (connectionString);
249 // Test exception is thrown if conn is closed
250 cmd = new SqlCommand ("Select count(*) from numeric_family");
252 reader = cmd.ExecuteReader ();
253 }catch (AssertionException e) {
255 }catch (Exception e) {
256 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
257 "#1 Incorrect Exception");
261 // Test exception is thrown for Invalid Query
262 cmd = new SqlCommand ("InvalidQuery", conn);
264 reader = cmd.ExecuteReader ();
265 Assert.Fail ("#1 Exception shud be thrown");
266 }catch (AssertionException e) {
268 }catch (Exception e) {
269 Assert.AreEqual (typeof(SqlException), e.GetType (),
270 "#2 Incorrect Exception : " + e);
274 // Test SqlException is thrown if a row is locked
275 // should lock a particular row and then modify it
279 // Test Connection cannot be modified when reader is in use
280 // NOTE : msdotnet contradicts documented behavior
281 cmd.CommandText = "select * from numeric_family where id=1";
282 reader = cmd.ExecuteReader ();
284 conn.Close (); // valid operation
285 conn = new SqlConnection (connectionString);
288 // NOTE msdotnet contradcits documented behavior
289 // If the above testcase fails, then this shud be tested
290 // Test connection can be modified once reader is closed
293 conn = new SqlConnection (connectionString); // valid operation
298 public void ExecuteReaderCommandBehaviorTest ()
300 // Test for command behaviors
301 DataTable schemaTable = null;
302 SqlDataReader reader = null;
304 conn = new SqlConnection (connectionString);
306 cmd = new SqlCommand ("", conn);
307 cmd.CommandText = "Select id from numeric_family where id <=4 order by id asc;";
308 cmd.CommandText += "Select type_bit from numeric_family where id <=4 order by id asc";
310 // Test for default command behavior
311 reader = cmd.ExecuteReader ();
315 while (reader.Read ())
317 Assert.AreEqual (4, rows, "#1 Multiple rows shud be returned");
320 }while (reader.NextResult());
321 Assert.AreEqual (2, results, "#2 Multiple result sets shud be returned");
324 // Test if closing reader, closes the connection
325 reader = cmd.ExecuteReader (CommandBehavior.CloseConnection);
327 Assert.AreEqual (ConnectionState.Closed, conn.State,
328 "#3 Command Behavior is not followed");
331 // Test if row info and primary Key info is returned
332 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
333 schemaTable = reader.GetSchemaTable ();
334 Assert.IsTrue(reader.HasRows, "#4 Data Rows shud also be returned");
335 Assert.IsTrue ((bool)schemaTable.Rows[0]["IsKey"],
336 "#5 Primary Key info shud be returned");
339 // Test only column information is returned
340 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
341 schemaTable = reader.GetSchemaTable ();
342 Assert.IsFalse (reader.HasRows, "#6 row data shud not be returned");
343 Assert.AreEqual(DBNull.Value, schemaTable.Rows[0]["IsKey"],
344 "#7 Primary Key info shud not be returned");
345 Assert.AreEqual ("id", schemaTable.Rows[0]["ColumnName"],
346 "#8 Schema Data is Incorrect");
349 // Test only one result set (first) is returned
350 reader = cmd.ExecuteReader (CommandBehavior.SingleResult);
351 schemaTable = reader.GetSchemaTable ();
352 Assert.IsFalse (reader.NextResult(),
353 "#9 Only one result set shud be returned");
354 Assert.AreEqual ("id", schemaTable.Rows[0]["ColumnName"],
355 "#10 The result set returned shud be the first result set");
358 // Test only one row is returned for all result sets
359 // msdotnet doesnt work correctly.. returns only one result set
360 reader = cmd.ExecuteReader (CommandBehavior.SingleRow);
364 while (reader.Read ())
366 Assert.AreEqual (1, rows, "#11 Only one row shud be returned");
369 }while (reader.NextResult());
370 // NOTE msdotnet contradicts documented behavior.
371 // Multiple result sets shud be returned , and in this case : 2
372 //Assert.AreEqual (2, results, "# Multiple result sets shud be returned");
373 Assert.AreEqual (2, results, "#12 Multiple result sets shud be returned");
378 public void PrepareTest_CheckValidStatement ()
380 cmd = new SqlCommand ();
381 conn = new SqlConnection (connectionString);
384 cmd.CommandText = "Select id from numeric_family where id=@ID" ;
385 cmd.Connection = conn ;
387 // Test if Parameters are correctly populated
388 cmd.Parameters.Clear ();
389 cmd.Parameters.Add ("@ID", SqlDbType.TinyInt);
390 cmd.Parameters["@ID"].Value = 2 ;
392 Assert.AreEqual (2, cmd.ExecuteScalar (), "#3 Prepared Stmt not working");
394 cmd.Parameters[0].Value = 3;
395 Assert.AreEqual (3, cmd.ExecuteScalar (), "#4 Prep Stmt not working");
400 public void PrepareTest ()
402 cmd = new SqlCommand ();
403 conn = new SqlConnection (connectionString);
406 cmd.CommandText = "Select id from numeric_family where id=@ID" ;
407 cmd.Connection = conn ;
409 // Test InvalidOperation Exception is thrown if Parameter Type
410 // is not explicitly set
411 cmd.Parameters.Add ("@ID", 2);
414 Assert.Fail ("#1 Parameter Type shud be explicitly Set");
415 }catch (AssertionException e) {
417 }catch (Exception e) {
418 Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
419 "#2 Incorrect Exception : " + e.StackTrace);
422 // Test Exception is thrown for variable size data if precision/scale
424 cmd.CommandText = "select type_varchar from string_family where type_varchar=@p1";
425 cmd.Parameters.Clear ();
426 cmd.Parameters.Add ("@p1", SqlDbType.VarChar);
427 cmd.Parameters["@p1"].Value = "afasasadadada";
430 Assert.Fail ("#5 Exception shud be thrown");
431 }catch (AssertionException e) {
433 }catch (Exception e) {
434 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
435 "#6 Incorrect Exception " + e.StackTrace);
438 // Test Exception is not thrown for Stored Procs
440 cmd.CommandType = CommandType.StoredProcedure;
441 cmd.CommandText = "ABFSDSFSF" ;
443 }catch (Exception e) {
444 Assert.Fail ("#7 Exception shud not be thrown for Stored Procs");
446 cmd.CommandType = CommandType.Text;
449 //Test InvalidOperation Exception is thrown if connection is not set
450 cmd.Connection = null;
453 Assert.Fail ("#8 InvalidOperation Exception shud be thrown");
454 }catch (AssertionException e) {
456 }catch (Exception e) {
457 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
458 "#9 Incorrect Exception : " + e.StackTrace);
461 //Test InvalidOperation Exception is thrown if connection is closed
462 cmd.Connection = conn ;
465 Assert.Fail ("#4 InvalidOperation Exception shud be thrown");
466 }catch (AssertionException e) {
468 }catch (Exception e) {
469 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
470 "Incorrect Exception : " + e.StackTrace);
475 public void ResetTimeOut ()
477 SqlCommand cmd = new SqlCommand ();
478 cmd.CommandTimeout = 50 ;
479 Assert.AreEqual ( cmd.CommandTimeout, 50,
480 "#1 CommandTimeout should be modfiable");
481 cmd.ResetCommandTimeout ();
482 Assert.AreEqual (cmd.CommandTimeout, 30,
483 "#2 Reset Should set the Timeout to default value");
487 [ExpectedException (typeof(ArgumentException))]
488 public void CommandTimeout ()
490 cmd = new SqlCommand ();
491 cmd.CommandTimeout = 10;
492 Assert.AreEqual (10, cmd.CommandTimeout, "#1");
493 cmd.CommandTimeout = -1;
497 [ExpectedException (typeof(ArgumentException))]
498 public void CommandTypeTest ()
500 cmd = new SqlCommand ();
501 Assert.AreEqual (CommandType.Text ,cmd.CommandType,
502 "Default CommandType is text");
503 cmd.CommandType = (CommandType)(-1);
507 [Ignore ("msdotnet contradicts documented behavior")]
508 [ExpectedException (typeof(InvalidOperationException))]
509 public void ConnectionTest ()
511 SqlTransaction trans = null;
513 conn = new SqlConnection (connectionString);
515 trans = conn.BeginTransaction ();
516 cmd = new SqlCommand ("", conn,trans);
517 cmd.CommandText = "Select id from numeric_family where id=1";
518 cmd.Connection = new SqlConnection ();
526 public void TransactionTest ()
528 conn = new SqlConnection (connectionString);
529 cmd = new SqlCommand ("", conn);
530 Assert.IsNull (cmd.Transaction, "#1 Default value is null");
532 SqlConnection conn1 = new SqlConnection (connectionString);
534 SqlTransaction trans1 = conn1.BeginTransaction ();
535 cmd.Transaction = trans1 ;
537 cmd.ExecuteNonQuery ();
538 Assert.Fail ("#2 Connection cannot be different");
539 }catch (Exception e) {
540 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
541 "#3 Incorrect Exception : " + e);
548 // Need to add more tests
550 [ExpectedException (typeof(ArgumentException))]
551 public void UpdatedRowSourceTest ()
553 cmd = new SqlCommand ();
554 Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource,
555 "#1 Default value is both");
556 cmd.UpdatedRowSource = UpdateRowSource.None;
557 Assert.AreEqual (UpdateRowSource.None, cmd.UpdatedRowSource,
560 cmd.UpdatedRowSource = (UpdateRowSource) (-1);
564 public void ExecuteNonQueryTempProcedureTest () {
565 conn = (SqlConnection) ConnectionManager.Singleton.Connection;
567 ConnectionManager.Singleton.OpenConnection ();
568 // create temp sp here, should normally be created in Setup of test
569 // case, but cannot be done right now because of ug #68978
570 DBHelper.ExecuteNonQuery (conn, CREATE_TMP_SP_TEMP_INSERT_PERSON);
571 SqlCommand cmd = new SqlCommand();
572 cmd.Connection = conn;
573 cmd.CommandText = "#sp_temp_insert_employee";
574 cmd.CommandType = CommandType.StoredProcedure;
575 Object TestPar = "test";
576 cmd.Parameters.Add("@fname", SqlDbType.VarChar);
577 cmd.Parameters ["@fname"].Value = TestPar;
578 Assert.AreEqual(1,cmd.ExecuteNonQuery());
580 DBHelper.ExecuteNonQuery (conn, DROP_TMP_SP_TEMP_INSERT_PERSON);
581 DBHelper.ExecuteSimpleSP (conn, "sp_clean_person_table");
582 ConnectionManager.Singleton.CloseConnection ();
586 // Test for bug #76778
587 // Test for a case, when query size is greater than the block size
589 public void LongQueryTest ()
591 SqlConnection conn = new SqlConnection (
592 connectionString + ";Pooling=false");
595 SqlCommand cmd = conn.CreateCommand ();
596 String value = new String ('a', 10000);
597 cmd.CommandText = String.Format ("Select '{0}'", value);
598 cmd.ExecuteNonQuery ();
602 // Test for bug #76778
603 // To make sure RPC (when implemented) works ok..
605 public void LongStoredProcTest()
607 SqlConnection conn = new SqlConnection (
608 connectionString + ";Pooling=false");
611 int size = conn.PacketSize ;
612 SqlCommand cmd = conn.CreateCommand ();
613 // create a temp stored proc ..
614 cmd.CommandText = "Create Procedure #sp_tmp_long_params ";
615 cmd.CommandText += "@p1 nvarchar (4000), ";
616 cmd.CommandText += "@p2 nvarchar (4000), ";
617 cmd.CommandText += "@p3 nvarchar (4000), ";
618 cmd.CommandText += "@p4 nvarchar (4000) out ";
619 cmd.CommandText += "As ";
620 cmd.CommandText += "Begin ";
621 cmd.CommandText += "Set @p4 = N'Hello' ";
622 cmd.CommandText += "Return 2 ";
623 cmd.CommandText += "End";
624 cmd.ExecuteNonQuery ();
627 cmd.CommandType = CommandType.StoredProcedure;
628 cmd.CommandText = "#sp_tmp_long_params";
630 String value = new String ('a', 4000);
631 SqlParameter p1 = new SqlParameter ("@p1",
632 SqlDbType.NVarChar,4000);
635 SqlParameter p2 = new SqlParameter ("@p2",
636 SqlDbType.NVarChar,4000);
639 SqlParameter p3 = new SqlParameter ("@p3",
640 SqlDbType.NVarChar,4000);
643 SqlParameter p4 = new SqlParameter ("@p4",
644 SqlDbType.NVarChar,4000);
645 p4.Direction = ParameterDirection.Output;
647 // for now, name shud be @RETURN_VALUE
648 // can be changed once RPC is implemented
649 SqlParameter p5 = new SqlParameter ("@RETURN_VALUE", SqlDbType.Int);
650 p5.Direction = ParameterDirection.ReturnValue ;
652 cmd.Parameters.Add (p1);
653 cmd.Parameters.Add (p2);
654 cmd.Parameters.Add (p3);
655 cmd.Parameters.Add (p4);
656 cmd.Parameters.Add (p5);
658 cmd.ExecuteNonQuery ();
659 Assert.AreEqual ("Hello", p4.Value, "#1");
660 Assert.AreEqual (2, p5.Value, "#2");
664 // Test for bug #76880
666 public void DateTimeParameterTest ()
668 SqlConnection conn = new SqlConnection (connectionString);
671 SqlCommand cmd = conn.CreateCommand ();
672 cmd.CommandText = "select * from datetime_family where type_datetime=@p1";
673 cmd.Parameters.Add ("@p1", SqlDbType.DateTime).Value= "10-10-2005";
674 // shudnt cause and exception
675 SqlDataReader rdr = cmd.ExecuteReader ();
681 * Verifies whether an enum value is converted to a numeric value when
682 * used as value for a numeric parameter (bug #66630)
685 public void EnumParameterTest() {
686 conn = (SqlConnection) ConnectionManager.Singleton.Connection;
688 ConnectionManager.Singleton.OpenConnection ();
689 // create temp sp here, should normally be created in Setup of test
690 // case, but cannot be done right now because of ug #68978
691 DBHelper.ExecuteNonQuery (conn, "CREATE PROCEDURE #Bug66630 ("
692 + "@Status smallint = 7"
694 + "AS" + Environment.NewLine
695 + "BEGIN" + Environment.NewLine
696 + "SELECT CAST(5 AS int), @Status" + Environment.NewLine
699 SqlCommand cmd = new SqlCommand("#Bug66630", conn);
700 cmd.CommandType = CommandType.StoredProcedure;
701 cmd.Parameters.Add("@Status", SqlDbType.Int).Value = Status.Error;
703 using (SqlDataReader dr = cmd.ExecuteReader()) {
704 // one record should be returned
705 Assert.IsTrue(dr.Read(), "EnumParameterTest#1");
706 // we should get two field in the result
707 Assert.AreEqual(2, dr.FieldCount, "EnumParameterTest#2");
709 Assert.AreEqual("int", dr.GetDataTypeName(0), "EnumParameterTest#3");
710 Assert.AreEqual(5, dr.GetInt32(0), "EnumParameterTest#4");
712 Assert.AreEqual("smallint", dr.GetDataTypeName(1), "EnumParameterTest#5");
713 Assert.AreEqual((short) Status.Error, dr.GetInt16(1), "EnumParameterTest#6");
714 // only one record should be returned
715 Assert.IsFalse(dr.Read(), "EnumParameterTest#7");
718 DBHelper.ExecuteNonQuery (conn, "if exists (select name from sysobjects " +
719 " where name like '#temp_Bug66630' and type like 'P') " +
720 " drop procedure #temp_Bug66630; ");
721 ConnectionManager.Singleton.CloseConnection ();
726 * The below test does not need a connection but since the setup opens
727 * the connection i will need to close it
730 public void CloneTest() {
731 ConnectionManager.Singleton.OpenConnection ();
732 SqlCommand cmd = new SqlCommand();
733 cmd.Connection = null;
734 cmd.CommandText = "sp_insert";
735 cmd.CommandType = CommandType.StoredProcedure;
736 Object TestPar = DBNull.Value;
737 cmd.Parameters.Add("@TestPar1", SqlDbType.Int);
738 cmd.Parameters["@TestPar1"].Value = TestPar;
739 cmd.Parameters.Add("@BirthDate", DateTime.Now);
740 cmd.DesignTimeVisible = true;
741 cmd.CommandTimeout = 100;
742 Object clone1 = ((ICloneable)(cmd)).Clone();
743 SqlCommand cmd1 = (SqlCommand) clone1;
744 Assert.AreEqual(2, cmd1.Parameters.Count);
745 Assert.AreEqual(100, cmd1.CommandTimeout);
746 cmd1.Parameters.Add("@test", DateTime.Now);
747 // to check that it is deep copy and not a shallow copy of the
748 // parameter collection
749 Assert.AreEqual(3, cmd1.Parameters.Count);
750 Assert.AreEqual(2, cmd.Parameters.Count);
753 private enum Status {
758 private readonly string CREATE_TMP_SP_TEMP_INSERT_PERSON = ("create procedure #sp_temp_insert_employee ( " + Environment.NewLine +
759 "@fname varchar (20)) " + Environment.NewLine +
760 "as " + Environment.NewLine +
761 "begin" + Environment.NewLine +
762 "declare @id int;" + Environment.NewLine +
763 "select @id = max (id) from employee;" + Environment.NewLine +
764 "set @id = @id + 6000 + 1;" + Environment.NewLine +
765 "insert into employee (id, fname, dob, doj) values (@id, @fname, '1980-02-11', getdate ());" + Environment.NewLine +
766 "return @id;" + Environment.NewLine +
769 private readonly string DROP_TMP_SP_TEMP_INSERT_PERSON = ("if exists (select name from sysobjects where " + Environment.NewLine +
770 "name = '#sp_temp_insert_employee' and type = 'P') " + Environment.NewLine +
771 "drop procedure #sp_temp_insert_employee; ");