public object ExecuteScalar(RelationalCommandParameterObject parameterObject)
            {
                var connection  = parameterObject.Connection;
                var errorNumber = PreExecution(connection);

                var result = _realRelationalCommand.ExecuteScalar(parameterObject);

                if (errorNumber.HasValue)
                {
                    connection.DbConnection.Close();
                    throw OleDbExceptionFactory.CreateOleDbException(errorNumber.Value);
                }

                return(result);
            }
            public RelationalDataReader ExecuteReader(RelationalCommandParameterObject parameterObject)
            {
                var connection  = parameterObject.Connection;
                var errorNumber = PreExecution(connection);

                var result = _realRelationalCommand.ExecuteReader(parameterObject);

                if (errorNumber.HasValue)
                {
                    connection.DbConnection.Close();
                    result.Dispose(); // Normally, in non-test case, reader is disposed by using in caller code
                    throw OleDbExceptionFactory.CreateOleDbException(errorNumber.Value);
                }

                return(result);
            }
            public async Task <object> ExecuteScalarAsync(
                RelationalCommandParameterObject parameterObject,
                CancellationToken cancellationToken = new CancellationToken())
            {
                var connection  = parameterObject.Connection;
                var errorNumber = PreExecution(connection);

                var result = await _realRelationalCommand.ExecuteScalarAsync(parameterObject, cancellationToken);

                if (errorNumber.HasValue)
                {
                    connection.DbConnection.Close();
                    throw OleDbExceptionFactory.CreateOleDbException(errorNumber.Value);
                }

                return(result);
            }
            public async Task <RelationalDataReader> ExecuteReaderAsync(
                RelationalCommandParameterObject parameterObject,
                CancellationToken cancellationToken = new CancellationToken())
            {
                var connection  = parameterObject.Connection;
                var errorNumber = PreExecution(connection);

                var result = await _realRelationalCommand.ExecuteReaderAsync(parameterObject, cancellationToken);

                if (errorNumber.HasValue)
                {
                    connection.DbConnection.Close();
                    result.Dispose(); // Normally, in non-test case, reader is disposed by using in caller code
                    throw OleDbExceptionFactory.CreateOleDbException(errorNumber.Value);
                }

                return(result);
            }
        private void PreOpen()
        {
            if (DbConnection.State == ConnectionState.Open)
            {
                return;
            }

            OpenCount++;
            if (OpenFailures.Count <= 0)
            {
                return;
            }

            var fail = OpenFailures.Dequeue();

            if (fail.HasValue)
            {
                throw OleDbExceptionFactory.CreateOleDbException(ErrorNumber);
            }
        }
            private int?PreExecution(IRelationalConnection connection)
            {
                int?errorNumber    = null;
                var testConnection = (TestJetConnection)connection;

                testConnection.ExecutionCount++;
                if (testConnection.ExecutionFailures.Count > 0)
                {
                    var fail = testConnection.ExecutionFailures.Dequeue();
                    if (fail.HasValue)
                    {
                        if (fail.Value)
                        {
                            testConnection.DbConnection.Close();
                            throw OleDbExceptionFactory.CreateOleDbException(testConnection.ErrorNumber);
                        }

                        errorNumber = testConnection.ErrorNumber;
                    }
                }

                return(errorNumber);
            }
        public override void Commit()
        {
            if (_testConnection.CommitFailures.Count > 0)
            {
                var fail = _testConnection.CommitFailures.Dequeue();
                if (fail.HasValue)
                {
                    if (fail.Value)
                    {
                        this.GetDbTransaction().Rollback();
                    }
                    else
                    {
                        this.GetDbTransaction().Commit();
                    }

                    _testConnection.DbConnection.Close();
                    throw OleDbExceptionFactory.CreateOleDbException(_testConnection.ErrorNumber, _testConnection.ConnectionId);
                }
            }

            base.Commit();
        }