Execute() public method

Executes this script.
public Execute ( SqlTransaction transaction ) : int
transaction System.Data.SqlClient.SqlTransaction
return int
示例#1
0
 public void ExecuteThrowsScriptExceptionForBadSql()
 {
     var script = new Script("SELECT * FROM BLAHBLAH");
     using(var connection = new SqlConnection(Config.ConnectionString))
     {
         connection.Open();
         UnitTestHelper.AssertThrows<SqlScriptExecutionException>(() => script.Execute(connection.BeginTransaction()));
     }
 }
示例#2
0
 public void ExecuteThrowsScriptExceptionForBadSql()
 {
     Script script = new Script("SELECT * FROM BLAHBLAH");
     using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
     {
         connection.Open();
         script.Execute(connection.BeginTransaction());
     }
 }
示例#3
0
        public void ExecuteThrowsProperScriptExceptionForBadSql()
        {
            var script = new Script("SELECT * FROM BLAHBLAH");
            using(var connection = new SqlConnection(Config.ConnectionString))
            {
                connection.Open();

                var e = UnitTestHelper.AssertThrows<SqlScriptExecutionException>(() => script.Execute(connection.BeginTransaction()));

                Assert.IsTrue(e.Message.Length > 0);
                Assert.AreEqual(0, e.ReturnValue);
                Assert.AreEqual("SELECT * FROM BLAHBLAH", e.Script.ScriptText);
            }
        }
示例#4
0
 public void ExecuteThrowsProperScriptExceptionForBadSql()
 {
     Script script = new Script("SELECT * FROM BLAHBLAH");
     using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
     {
         connection.Open();
         try
         {
             script.Execute(connection.BeginTransaction());
         }
         catch(SqlScriptExecutionException e)
         {
             Assert.IsTrue(e.Message.Length > 0);
             Assert.AreEqual(0, e.ReturnValue);
             Assert.AreEqual("SELECT * FROM BLAHBLAH", e.Script.ScriptText);
             throw;
         }
     }
 }
示例#5
0
        public void ExecuteThrowsArgumentExceptionForNullTransaction()
        {
            var script = new Script("");

            UnitTestHelper.AssertThrowsArgumentNullException(() => script.Execute(null));
        }
示例#6
0
 /// <summary>
 /// Temporarily set NOCOUNT OFF on the connection. We must do this b/c the SqlScriptRunner 
 /// depends on all CRUD statements returning the number of effected rows to determine if an 
 /// error occured. This isn't a perfect solution, but it's what we've got.
 /// </summary>
 /// <param name="transaction"></param>
 private static void SetNoCountOff(SqlTransaction transaction)
 {
     Script noCount = new Script("SET NOCOUNT OFF");
     noCount.Execute(transaction);
 }
        /// <summary>
        /// Temporarily set NOCOUNT OFF on the connection. We must do this b/c the SqlScriptRunner
        /// depends on all CRUD statements returning the number of effected rows to determine if an
        /// error occured. This isn't a perfect solution, but it's what we've got.
        /// </summary>
        /// <param name="transaction"></param>
        private static void SetNoCountOff(SqlTransaction transaction)
        {
            var noCount = new Script("SET NOCOUNT OFF");

            noCount.Execute(transaction);
        }
示例#8
0
 public void ExecuteThrowsArgumentExceptionForNullTransaction()
 {
     Script script = new Script("");
     script.Execute(null);
 }