/// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns>The number of <see cref="SqlNonQueryCommand">commands</see> executed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public void ExecuteNonQuery(SqlNonQueryCommand command)
        {
            if (command == null) 
                throw new ArgumentNullException("command");

            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _settings.ConnectionString;
                dbConnection.Open();
                try
                {
                    using (var dbTransaction = dbConnection.BeginTransaction(_isolationLevel))
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection = dbConnection;
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.CommandTimeout = _commandTimeout;

                            dbCommand.CommandType = command.Type;
                            dbCommand.CommandText = command.Text;
                            dbCommand.Parameters.AddRange(command.Parameters);
                            dbCommand.ExecuteNonQuery();
                        }
                        dbTransaction.Commit();
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
Ejemplo n.º 2
0
            public async Task ExecuteNonQueryAsync(SqlNonQueryCommand command, CancellationToken cancellationToken)
            {
                if (command == null)
                {
                    throw new ArgumentNullException("command");
                }

                using (var dbConnection = _connectionFactory())
                {
                    await dbConnection.OpenAsync(cancellationToken);

                    try
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection     = dbConnection;
                            dbCommand.CommandTimeout = _commandTimeout;
                            dbCommand.CommandType    = command.Type;
                            dbCommand.CommandText    = command.Text;
                            dbCommand.Parameters.AddRange(command.Parameters);
                            await dbCommand.ExecuteNonQueryAsync(cancellationToken);
                        }
                    }
                    finally
                    {
                        dbConnection.Close();
                    }
                }
            }
        /// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns>The number of <see cref="SqlNonQueryCommand">commands</see> executed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public void ExecuteNonQuery(SqlNonQueryCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _settings.ConnectionString;
                dbConnection.Open();
                try
                {
                    using (var dbTransaction = dbConnection.BeginTransaction(_isolationLevel))
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection     = dbConnection;
                            dbCommand.Transaction    = dbTransaction;
                            dbCommand.CommandTimeout = _commandTimeout;

                            dbCommand.CommandType = command.Type;
                            dbCommand.CommandText = command.Text;
                            dbCommand.Parameters.AddRange(command.Parameters);
                            dbCommand.ExecuteNonQuery();
                        }
                        dbTransaction.Commit();
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
Ejemplo n.º 4
0
 public Task ExecuteNonQueryAsync(SqlNonQueryCommand command)
 {
     if (command == null)
     {
         throw new ArgumentNullException(nameof(command));
     }
     return(ExecuteNonQueryAsync(command, CancellationToken.None));
 }
Ejemplo n.º 5
0
 public void NonQueryProcedureUnlessReturnsExpectedInstance(IEnumerable<SqlNonQueryCommand> actual, SqlNonQueryCommand[] expected)
 {
     var actualArray = actual.ToArray();
     Assert.That(actualArray.Length, Is.EqualTo(expected.Length));
     for (var index = 0; index < actualArray.Length; index++)
     {
         Assert.That(actualArray[index].Text, Is.EqualTo(expected[index].Text));
         Assert.That(actualArray[index].Parameters, Is.EquivalentTo(expected[index].Parameters).Using(new SqlParameterEqualityComparer()));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns>The number of <see cref="SqlNonQueryCommand">commands</see> executed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public void ExecuteNonQuery(SqlNonQueryCommand command)
        {
            if (command == null) 
                throw new ArgumentNullException("command");

            using (var dbCommand = _dbConnection.CreateCommand())
            {
                dbCommand.Connection = _dbConnection;
                dbCommand.CommandTimeout = _commandTimeout;

                dbCommand.CommandType = command.Type;
                dbCommand.CommandText = command.Text;
                dbCommand.Parameters.AddRange(command.Parameters);
                dbCommand.ExecuteNonQuery();
            }
        }
        /// <summary>
        ///     Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns>The number of <see cref="SqlNonQueryCommand">commands</see> executed.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public void ExecuteNonQuery(SqlNonQueryCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            using (var dbCommand = _dbConnection.CreateCommand())
            {
                dbCommand.Connection     = _dbConnection;
                dbCommand.CommandTimeout = _commandTimeout;

                dbCommand.CommandType = command.Type;
                dbCommand.CommandText = command.Text;
                dbCommand.Parameters.AddRange(command.Parameters);
                dbCommand.ExecuteNonQuery();
            }
        }
Ejemplo n.º 8
0
                public WithHandlers()
                {
                    _command      = CommandFactory();
                    _commandArray = new[]
                    {
                        CommandFactory(), CommandFactory()
                    };
                    _commandEnumeration = Enumerable.Repeat(CommandFactory(), 1);

                    var commands = new List <SqlNonQueryCommand>();

                    commands.Add(_command);
                    commands.AddRange(_commandArray);
                    commands.AddRange(_commandEnumeration);
                    _result = commands.ToArray();

                    When <object>(m => _command);
                    When <object>(m => _commandArray);
                    When <object>(m => _commandEnumeration);
                }
            public void SetUp()
            {
                _command      = CommandFactory();
                _commandArray = new[]
                {
                    CommandFactory(), CommandFactory()
                };

                var commands = new List <SqlNonQueryCommand>();

                commands.Add(_command);
                commands.AddRange(_commandArray);
                _result = commands.ToArray();

                _sut = new WithHandlers(new []
                {
                    HandlerFactory(_command),
                    HandlerFactory(_commandArray),
                });
            }
 private static SqlProjectionHandler HandlerFactory(SqlNonQueryCommand command)
 {
     return(new SqlProjectionHandler(typeof(object), o => new[] { command }));
 }
Ejemplo n.º 11
0
        /// <summary>
        ///     Executes the specified command asynchronously.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        ///     A <see cref="Task" /> that will return when the <see cref="SqlNonQueryCommand">command</see>
        ///     was executed.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public async Task ExecuteNonQueryAsync(SqlNonQueryCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            using (var dbCommand = _dbConnection.CreateCommand())
            {
                dbCommand.Connection = _dbConnection;
                dbCommand.CommandTimeout = _commandTimeout;

                dbCommand.CommandType = command.Type;
                dbCommand.CommandText = command.Text;
                dbCommand.Parameters.AddRange(command.Parameters);
                await dbCommand.ExecuteNonQueryAsync(cancellationToken);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 ///     Executes the specified command asynchronously.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns>
 ///     A <see cref="Task" /> that will return when the <see cref="SqlNonQueryCommand">command</see>
 ///     was executed.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
 public Task ExecuteNonQueryAsync(SqlNonQueryCommand command)
 {
     return ExecuteNonQueryAsync(command, CancellationToken.None);
 }
Ejemplo n.º 13
0
 public Task ExecuteNonQueryAsync(SqlNonQueryCommand command)
 {
     return(Task.FromResult <object>(null));
 }
Ejemplo n.º 14
0
 private static SqlProjectionHandler HandlerFactory(SqlNonQueryCommand[] commands)
 {
     return new SqlProjectionHandler(typeof(object), o => commands);
 }
 /// <summary>
 ///     Executes the specified command asynchronously.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns>
 ///     A <see cref="Task" /> that will return when the <see cref="SqlNonQueryCommand">command</see>
 ///     was executed.
 /// </returns>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
 public Task ExecuteNonQueryAsync(SqlNonQueryCommand command)
 {
     return(ExecuteNonQueryAsync(command, CancellationToken.None));
 }
Ejemplo n.º 16
0
 private static Func<object, SqlNonQueryCommand> HandlerFactory(SqlNonQueryCommand command)
 {
     return o => command;
 }
Ejemplo n.º 17
0
        /// <summary>
        ///     Executes the specified command asynchronously.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        ///     A <see cref="Task" /> that will return when the <see cref="SqlNonQueryCommand">command</see>
        ///     was executed.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="command" /> is <c>null</c>.</exception>
        public async Task ExecuteNonQueryAsync(SqlNonQueryCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _settings.ConnectionString;
                await dbConnection.OpenAsync(cancellationToken);
                try
                {
                    using (var dbCommand = dbConnection.CreateCommand())
                    {
                        dbCommand.Connection = dbConnection;
                        dbCommand.CommandTimeout = _commandTimeout;
                        dbCommand.CommandType = command.Type;
                        dbCommand.CommandText = command.Text;
                        dbCommand.Parameters.AddRange(command.Parameters);
                        await dbCommand.ExecuteNonQueryAsync(cancellationToken);
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }
Ejemplo n.º 18
0
 public void ExecuteNonQuery(SqlNonQueryCommand command)
 {
     Commands.Add(command);
 }
Ejemplo n.º 19
0
 public void NonQueryStatementFormatReturnsExpectedInstance(SqlNonQueryCommand actual, SqlNonQueryCommand expected)
 {
     Assert.That(actual.Text, Is.EqualTo(expected.Text));
     Assert.That(actual.Parameters, Is.EquivalentTo(expected.Parameters).Using(new SQLiteParameterEqualityComparer()));
 }
Ejemplo n.º 20
0
 public Task ExecuteNonQueryAsync(SqlNonQueryCommand command, CancellationToken cancellationToken)
 {
     return(Task.FromResult <object>(null));
 }
Ejemplo n.º 21
0
            public void SetUp()
            {
                _command = CommandFactory();
                _commandArray = new[]
                    {
                        CommandFactory(), CommandFactory()
                    };

                var commands = new List<SqlNonQueryCommand>();
                commands.Add(_command);
                commands.AddRange(_commandArray);
                _result = commands.ToArray();

                _sut = new WithHandlers(new []
                {
                    HandlerFactory(_command),
                    HandlerFactory(_commandArray),
                });
            }
Ejemplo n.º 22
0
                public WithHandlers()
                {
                    _command = CommandFactory();
                    _commandArray = new[]
                    {
                        CommandFactory(), CommandFactory()
                    };
                    _commandEnumeration = Enumerable.Repeat(CommandFactory(), 1);

                    var commands = new List<SqlNonQueryCommand>();
                    commands.Add(_command);
                    commands.AddRange(_commandArray);
                    commands.AddRange(_commandEnumeration);
                    _result = commands.ToArray();

                    When<object>(m => _command);
                    When<object>(m => _commandArray);
                    When<object>(m => _commandEnumeration);
                }
Ejemplo n.º 23
0
 private static Func <object, SqlNonQueryCommand> HandlerFactory(SqlNonQueryCommand command)
 {
     return(o => command);
 }
Ejemplo n.º 24
0
 public void NonQueryProcedureReturnsExpectedInstance(SqlNonQueryCommand actual, SqlNonQueryCommand expected)
 {
     Assert.That(actual.Text, Is.EqualTo(expected.Text));
     Assert.That(actual.Parameters, Is.EquivalentTo(expected.Parameters).Using(new SqlParameterEqualityComparer()));
 }
Ejemplo n.º 25
0
 public void ExecuteNonQuery(SqlNonQueryCommand command)
 {
 }
Ejemplo n.º 26
0
 private static SqlProjectionHandler HandlerFactory(SqlNonQueryCommand command)
 {
     return new SqlProjectionHandler(typeof(object), o => new[] {command});
 }