示例#1
0
        public void Repeat_async_with_log_handler_should_log()
        {
            // Arrange
            Func <Task <int> > customMethodReturnWithCustomExceptionAsync = () =>
                                                                            Task.Factory.StartNew <int>(() => throw new CustomException());
            int totalAttempts = 0;
            var callback      = new FlowUtils.RetryCallback((a, e) =>
            {
                totalAttempts = a;
            });

            // Act
            try
            {
                FlowUtils.RetryAsync(
                    customMethodReturnWithCustomExceptionAsync,
                    FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2)).Wait();
            }
            catch (AggregateException)
            {
            }

            // Assert
            Assert.Equal(2, totalAttempts);
        }
示例#2
0
        public void Repeat_with_log_handler_should_log()
        {
            // Arrange
            Action customMethodReturnWithCustomException = () => throw new CustomException();
            int    totalAttempts = 0;
            var    callback      = new FlowUtils.RetryCallback((a, e) =>
            {
                totalAttempts = a;
            });

            // Act
            try
            {
                FlowUtils.Retry(
                    customMethodReturnWithCustomException,
                    FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2)
                    );
            }
            catch (CustomException)
            {
                // suppress our specific exception
            }

            // Assert
            Assert.Equal(2, totalAttempts);
        }
示例#3
0
 public void Repeat_async_with_log_handler_should_log()
 {
     Int32 totalAttempts = 0;
     var callback = new FlowUtils.RetryCallback((a, e) =>
     {
         totalAttempts = a;
     });
     try
     {
         FlowUtils.RetryAsync(
             CustomMethodReturnWithCustomExceptionAsync,
             FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2)).Wait();
     }
     catch (AggregateException)
     {
     }
     Assert.That(totalAttempts, Is.EqualTo(2));
 }
示例#4
0
 public void Repeat_with_log_handler_should_log()
 {
     Int32 totalAttempts = 0;
     var callback = new FlowUtils.RetryCallback((a, e) =>
     {
         totalAttempts = a;
     });
     FlowUtils.Retry(
         CustomMethodReturnWithCustomException,
         FlowUtils.CreateCallbackRetryStrategy(callback) + FlowUtils.CreateFixedDelayRetryStrategy(2)
     );
     Assert.That(totalAttempts, Is.EqualTo(2));
 }