context: //
  // SqlCommandTest.cs - NUnit Test Cases for testing
  // System.Data.SqlClient.SqlCommand
  // 
  // Author:
  // 	Gert Driesen (drieseng@users.sourceforge.net)
  //
  // Copyright (c) 2007 Gert Driesen
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  //
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  //
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
  
  using System;
  using System.Data;
  using System.Data.Sql;
  using System.Data.SqlClient;
  
  using NUnit.Framework;
  
  namespace MonoTests.System.Data.SqlClient
  {
  	[TestFixture]
  	public class SqlCommandTest
  	{
  		const string COMMAND_TEXT = "SELECT * FROM Authors";
  
  		[Test] // SqlCommand ()
  		public void Constructor1 ()
  		{
  			SqlCommand cmd = new SqlCommand ();
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
  			Assert.IsNull (cmd.Connection, "#4");
  			Assert.IsNull (cmd.Container, "#5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#6");
  			Assert.IsNull (cmd.Notification, "#7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#8");
  			Assert.IsNotNull (cmd.Parameters, "#9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#10");
  			Assert.IsNull (cmd.Site, "#11");
  			Assert.IsNull (cmd.Transaction, "#11");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#12");
  		}
  
  		[Test] // SqlCommand (string)
  		public void Constructor2 ()
  		{
  			SqlCommand cmd = new SqlCommand (COMMAND_TEXT);
  			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
  			Assert.IsNull (cmd.Connection, "#A4");
  			Assert.IsNull (cmd.Container, "#A5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
  			Assert.IsNull (cmd.Notification, "#A7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
  			Assert.IsNotNull (cmd.Parameters, "#A9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
  			Assert.IsNull (cmd.Site, "#A11");
  			Assert.IsNull (cmd.Transaction, "#A12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
  
  			cmd = new SqlCommand ((string) null);
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
  			Assert.IsNull (cmd.Connection, "#B4");
  			Assert.IsNull (cmd.Container, "#B5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
  			Assert.IsNull (cmd.Notification, "#B7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
  			Assert.IsNotNull (cmd.Parameters, "#B9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
  			Assert.IsNull (cmd.Site, "#B11");
  			Assert.IsNull (cmd.Transaction, "#B12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
  		}
  
  		[Test] // SqlCommand (string, SqlConnection)
  		public void Constructor3 ()
  		{
  			SqlConnection conn = new SqlConnection ();
  			SqlCommand cmd;
  
  			cmd = new SqlCommand (COMMAND_TEXT, conn);
  			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
  			Assert.AreSame (conn, cmd.Connection, "#A4");
  			Assert.IsNull (cmd.Container, "#A5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
  			Assert.IsNull (cmd.Notification, "#A7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
  			Assert.IsNotNull (cmd.Parameters, "#A9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
  			Assert.IsNull (cmd.Site, "#A11");
  			Assert.IsNull (cmd.Transaction, "#A12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
  
  			cmd = new SqlCommand ((string) null, conn);
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
  			Assert.AreSame (conn, cmd.Connection, "#B4");
  			Assert.IsNull (cmd.Container, "#B5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
  			Assert.IsNull (cmd.Notification, "#B7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
  			Assert.IsNotNull (cmd.Parameters, "#B9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
  			Assert.IsNull (cmd.Site, "#B11");
  			Assert.IsNull (cmd.Transaction, "#B12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
  
  			cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null);
  			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
  			Assert.IsNull (cmd.Connection, "#C4");
  			Assert.IsNull (cmd.Container, "#C5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
  			Assert.IsNull (cmd.Notification, "#C7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
  			Assert.IsNotNull (cmd.Parameters, "#C9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
  			Assert.IsNull (cmd.Site, "#C11");
  			Assert.IsNull (cmd.Transaction, "#C12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
  		}
  
  		[Test] // SqlCommand (string, SqlConnection, SqlTransaction)
  		public void Constructor4 ()
  		{
  			SqlConnection conn = new SqlConnection ();
  			SqlCommand cmd;
  
  			cmd = new SqlCommand (COMMAND_TEXT, conn, (SqlTransaction) null);
  			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
  			Assert.AreSame (conn, cmd.Connection, "#A4");
  			Assert.IsNull (cmd.Container, "#A5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
  			Assert.IsNull (cmd.Notification, "#A7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
  			Assert.IsNotNull (cmd.Parameters, "#A9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
  			Assert.IsNull (cmd.Site, "#A11");
  			Assert.IsNull (cmd.Transaction, "#A12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
  
  			cmd = new SqlCommand ((string) null, conn, (SqlTransaction) null);
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
  			Assert.AreSame (conn, cmd.Connection, "#B4");
  			Assert.IsNull (cmd.Container, "#B5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
  			Assert.IsNull (cmd.Notification, "#B7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
  			Assert.IsNotNull (cmd.Parameters, "#B9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
  			Assert.IsNull (cmd.Site, "#B11");
  			Assert.IsNull (cmd.Transaction, "#B12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
  
  			cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null, (SqlTransaction) null);
  			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
  			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
  			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
  			Assert.IsNull (cmd.Connection, "#C4");
  			Assert.IsNull (cmd.Container, "#C5");
  			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
  			Assert.IsNull (cmd.Notification, "#C7");
  			Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
  			Assert.IsNotNull (cmd.Parameters, "#C9");
  			Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
  			Assert.IsNull (cmd.Site, "#C11");
  			Assert.IsNull (cmd.Transaction, "#C12");
  			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
  		}
  
  		[Test]
  		public void Clone ()
  		{
  			SqlNotificationRequest notificationReq = new SqlNotificationRequest ();
  
  			SqlCommand cmd = new SqlCommand ();
  			cmd.CommandText = "sp_insert";
  			cmd.CommandTimeout = 100;
  			cmd.CommandType = CommandType.StoredProcedure;
  			cmd.DesignTimeVisible = false;
  			cmd.Notification = notificationReq;
  			cmd.NotificationAutoEnlist = false;
  			cmd.Parameters.Add ("@TestPar1", SqlDbType.Int);
  			cmd.Parameters ["@TestPar1"].Value = DBNull.Value;
  			cmd.Parameters.AddWithValue ("@BirthDate", DateTime.Now);
  			cmd.UpdatedRowSource = UpdateRowSource.OutputParameters;
  
  			SqlCommand clone = (((ICloneable) (cmd)).Clone ()) as SqlCommand;
  			Assert.AreEqual ("sp_insert", clone.CommandText, "#1");
  			Assert.AreEqual (100, clone.CommandTimeout, "#2");
  			Assert.AreEqual (CommandType.StoredProcedure, clone.CommandType, "#3");
  			Assert.IsNull (cmd.Connection, "#4");
  			Assert.IsFalse (cmd.DesignTimeVisible, "#5");
  			Assert.AreSame (notificationReq, cmd.Notification, "#6");
  			Assert.IsFalse (cmd.NotificationAutoEnlist, "#7");
  			Assert.AreEqual (2, clone.Parameters.Count, "#8");
  			Assert.AreEqual (100, clone.CommandTimeout, "#9");
  			clone.Parameters.AddWithValue ("@test", DateTime.Now);
  			clone.Parameters [0].ParameterName = "@ClonePar1";
  			Assert.AreEqual (3, clone.Parameters.Count, "#10");
  			Assert.AreEqual (2, cmd.Parameters.Count, "#11");
  			Assert.AreEqual ("@ClonePar1", clone.Parameters [0].ParameterName, "#12");
  			Assert.AreEqual ("@TestPar1", cmd.Parameters [0].ParameterName, "#13");
  			Assert.AreEqual ("@BirthDate", clone.Parameters [1].ParameterName, "#14");
  			Assert.AreEqual ("@BirthDate", cmd.Parameters [1].ParameterName, "#15");
  			Assert.IsNull (clone.Transaction, "#16");
  		}
  
  		[Test]
  		public void CommandText ()
  		{
  			SqlCommand cmd = new SqlCommand ();
  			cmd.CommandText = COMMAND_TEXT;
  			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
  			cmd.CommandText = null;
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
  			cmd.CommandText = COMMAND_TEXT;
  			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
  			cmd.CommandText = string.Empty;
  			Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
  		}
  
  		[Test]
  		public void CommandTimeout ()
  		{
  			SqlCommand cmd = new SqlCommand ();
  			cmd.CommandTimeout = 10;
  			Assert.AreEqual (10, cmd.CommandTimeout, "#1");
  			cmd.CommandTimeout = 25;
  			Assert.AreEqual (25, cmd.CommandTimeout, "#2");
  			cmd.CommandTimeout = 0;
  			Assert.AreEqual (0, cmd.CommandTimeout, "#3");
  		}
  
  		[Test]
  		public void CommandTimeout_Value_Negative ()
  		{
  			SqlCommand cmd = new SqlCommand ();
  			try {
  				cmd.CommandTimeout = -1;
  				Assert.Fail ("#1");
  			} catch (ArgumentException ex) {
  				// Invalid CommandTimeout value -1; the value must be >= 0
  				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  				Assert.IsNull (ex.InnerException, "#3");
  				Assert.IsNotNull (ex.Message, "#4");
  				Assert.AreEqual ("CommandTimeout", ex.ParamName, "#5");
  			}
  		}
  
  		[Test]
  		public void CommandType_Value_Invalid ()
  		{
  
gt: 			SqlCommand cmd = new SqlCommand ();