public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry(
                                                               SqlCommand command,
                                                               CommandBehavior behavior,
                                                               IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteReaderAsync(behavior));
 }
 public static Task<int> ExecuteNonQueryAsyncWithRetry(
                                                       SqlCommand command,
                                                       CancellationToken cancellationToken,
                                                       IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteNonQueryAsync(cancellationToken));
 }
 public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry(
                                                               SqlCommand command,
                                                               CancellationToken cancellationToken,
                                                               IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteReaderAsync(cancellationToken));
 }
 public static Task OpenAsyncWithRetry(
                                       this SqlConnection connection,
                                       CancellationToken cancellationToken,
                                       IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => connection.OpenAsync(cancellationToken));
 }
        private static async Task TestSqlRetryPolicy(IRetryPolicy retryPolicy, int interval)
        {
            var retryCount = 0;
            retryPolicy.Retry += (sender, args) =>
            {
                retryCount++;

                // Assert
                Assert.Equal(typeof(TimeoutException), args.Exception.GetType());
                Assert.Equal(retryCount, args.RetryCount);
                Assert.Equal(retryCount * interval, args.Delay.TotalMilliseconds);
            };

            var taskFunction = TaskFunctionTestFactory.GetTaskFunctionTResultWithRetry();

            // Act
            await retryPolicy.ExecuteAsyncWithRetry(taskFunction);
        }
 public static Task<object> ExecuteScalarAsyncWithRetry(
                                                        SqlCommand command,
                                                        IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(command.ExecuteScalarAsync);
 }
 public static Task<SqlDataReader> ExecuteReaderAsyncWithRetry(SqlCommand command, IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(command.ExecuteReaderAsync);
 }
 public static Task<int> ExecuteNonQueryAsyncWithRetry(SqlCommand command, IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(command.ExecuteNonQueryAsync);
 }
 public static Task<object> ExecuteScalarAsyncWithRetry(
                                                        SqlCommand command,
                                                        CancellationToken cancellationToken,
                                                        IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(() => command.ExecuteScalarAsync(cancellationToken));
 }
 public static Task OpenAsyncWithRetry(this SqlConnection connection, IRetryPolicy retryPolicy)
 {
     return retryPolicy.ExecuteAsyncWithRetry(connection.OpenAsync);
 }