Ejemplo n.º 1
0
        public int Execute()
        {
            try
            {
                CommandInfo commandInfo = FindCommand(_arguments[0]);
                try
                {
                    commandInfo.Execute(_arguments.Skip(1).ToArray());
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("{0} execution failed, Error: {1}", commandInfo.Name, ex.Message);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Error: " + ex.Message);
                Console.WriteLine("Bad command, ? for command list");
                return(-1);
            }
            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes command returns number of affected records.
        /// </summary>
        /// <param name="sqlStatement">Command text</param>
        /// <param name="dataParameters">Command parameters</param>
        /// <returns>Number of records, affected by command execution.</returns>
        public int ExecuteNonQuery(string sqlStatement, params DataParameter[] dataParameters)
        {
            using var dataContext = CreateDataConnection();
            var command         = new CommandInfo(dataContext, sqlStatement, dataParameters);
            var affectedRecords = command.Execute();

            UpdateOutputParameters(dataContext, dataParameters);

            return(affectedRecords);
        }
Ejemplo n.º 3
0
      public void TestExecuteWhenCanExecuteIsFalse()
      {
         Mock<ICommand> testCommand = new Mock<ICommand>();
         testCommand.Setup(c => c.CanExecute()).Returns(false);

         CommandInfo ci = new CommandInfo();
         ci.Executor(testCommand.Object);
         ci.Execute();

         testCommand.Verify(c => c.Execute(), Times.Never());
      }
Ejemplo n.º 4
0
      public void TestExecute()
      {
         Mock<ICommand> testCommand = new Mock<ICommand>();
         testCommand.Setup(c => c.CanExecute()).Returns(true);

         CommandInfo ci = new CommandInfo();
         ci.Executor(testCommand.Object);
         ci.Execute();

         testCommand.Verify(c => c.Execute(), Times.Once());
      }
        /// <summary>
        /// Executes command returns number of affected records.
        /// </summary>
        /// <param name="sqlStatement">Command text</param>
        /// <param name="dataParameters">Command parameters</param>
        /// <returns>Number of records, affected by command execution.</returns>
        public int ExecuteNonQuery(string sqlStatement, params DataParameter[] dataParameters)
        {
            using (new ReaderWriteLockDisposable(_locker, ReaderWriteLockType.Read))
            {
                var command         = new CommandInfo(DataContext, sqlStatement, dataParameters);
                var affectedRecords = command.Execute();

                UpdateOutputParameters(DataContext, dataParameters);

                return(affectedRecords);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Executes command asynchronously and returns number of affected records
        /// </summary>
        /// <param name="sql">Command text</param>
        /// <param name="dataParameters">Command parameters</param>
        /// <returns>Number of records, affected by command execution.</returns>
        public Task <int> ExecuteNonQueryAsync(string sql, params DataParameter[] dataParameters)
        {
            using (new ReaderWriteLockDisposable(_locker, ReaderWriteLockType.Read))
            {
                var command         = new CommandInfo(DataContext, sql, dataParameters);
                var affectedRecords = command.Execute();

                UpdateOutputParameters(DataContext, dataParameters);

                return(Task.FromResult <int>(affectedRecords));
            }
        }
Ejemplo n.º 7
0
        public void TestExecuteWhenCanExecuteIsFalse()
        {
            Mock <ICommand> testCommand = new Mock <ICommand>();

            testCommand.Setup(c => c.CanExecute()).Returns(false);

            CommandInfo ci = new CommandInfo();

            ci.Executor(testCommand.Object);
            ci.Execute();

            testCommand.Verify(c => c.Execute(), Times.Never());
        }
Ejemplo n.º 8
0
        public void TestExecute()
        {
            Mock <ICommand> testCommand = new Mock <ICommand>();

            testCommand.Setup(c => c.CanExecute()).Returns(true);

            CommandInfo ci = new CommandInfo();

            ci.Executor(testCommand.Object);
            ci.Execute();

            testCommand.Verify(c => c.Execute(), Times.Once());
        }
Ejemplo n.º 9
0
        private bool TableExists(DatabaseConnection databaseConnection, string tableName)
        {
            var command = new CommandInfo(databaseConnection, @$ " IF EXISTS (SELECT * FROM sys.tables WHERE name = '{tableName}') SELECT 1 ELSE SELECT 0 ");

            return(command.Execute <int>() == 1);
        }
Ejemplo n.º 10
0
 public void TestExecuteWithoutExecutor()
 {
    CommandInfo ci = new CommandInfo();
    ci.Execute();
 }
Ejemplo n.º 11
0
        public void TestExecuteWithoutExecutor()
        {
            CommandInfo ci = new CommandInfo();

            ci.Execute();
        }