Пример #1
0
 public void Executing_the_synchronous_policies_using_the_asynchronous_execute_and_capture_should_throw_an_invalid_operation_exception(Policy syncPolicy, string description)
 {
     syncPolicy
     .Awaiting(async x => await x.ExecuteAndCaptureAsync(() => TaskHelper.EmptyTask))
     .ShouldThrow <InvalidOperationException>()
     .WithMessage("Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.");
 }
Пример #2
0
 internal void Executing_the_synchronous_policies_using_the_asynchronous_execute_should_throw_an_invalid_operation_exception(Policy <ResultPrimitive> syncPolicy, string description)
 {
     syncPolicy
     .Awaiting(async x => await x.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good)))
     .ShouldThrow <InvalidOperationException>()
     .WithMessage("Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.");
 }
Пример #3
0
 public void Executing_the_synchronous_policies_using_the_asynchronous_execute_and_capture_should_throw_an_invalid_operation_exception(Policy syncPolicy, string description)
 {
     syncPolicy
     .Awaiting(x => x.ExecuteAndCaptureAsync(() => CompletedTask))
     .ShouldThrow <InvalidOperationException>()
     .WithMessage("Please use the asynchronous RetryAsync, RetryForeverAsync, WaitAndRetryAsync or CircuitBreakerAsync methods when calling the asynchronous Execute method.");
 }
Пример #4
0
        public void Executing_the_policy_function_should_throw_when_context_data_is_null()
        {
            Policy <ResultPrimitive> policy = Policy
                                              .HandleResult(ResultPrimitive.Fault)
                                              .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Good), (IDictionary <string, object>)null))
            .ShouldThrow <ArgumentNullException>();
        }
Пример #5
0
        public void Execute_and_capturing_the_policy_function_should_throw_when_context_data_is_null()
        {
            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAndCaptureAsync(() => Task.FromResult(2), (IDictionary <string, object>)null))
            .ShouldThrow <ArgumentNullException>();
        }
Пример #6
0
        public void Executing_the_policy_action_should_throw_when_context_data_is_null()
        {
            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAsync(() => TaskHelper.EmptyTask, (IDictionary <string, object>)null))
            .ShouldThrow <ArgumentNullException>();
        }
Пример #7
0
        public void Execute_and_capturing_the_policy_function_should_throw_when_context_is_null()
        {
            Policy <ResultPrimitive> policy = Policy
                                              .HandleResult(ResultPrimitive.Fault)
                                              .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAndCaptureAsync(() => Task.FromResult(ResultPrimitive.Good), (Context)null))
            .ShouldThrow <ArgumentNullException>().And
            .ParamName.Should().Be("context");
        }
Пример #8
0
        public void Execute_and_capturing_the_policy_action_should_throw_when_context_is_null()
        {
            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAndCaptureAsync(() => TaskHelper.EmptyTask, (Context)null))
            .ShouldThrow <ArgumentNullException>().And
            .ParamName.Should().Be("context");
        }
Пример #9
0
        public void Executing_the_policy_function_should_throw_when_context_is_null()
        {
            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryAsync((_, __, ___) => { });

            policy.Awaiting(async p => await p.ExecuteAsync(() => Task.FromResult(2), (Context)null))
            .ShouldThrow <ArgumentNullException>().And
            .ParamName.Should().Be("context");
        }
Пример #10
0
        public void Context_should_be_empty_if_execute_not_called_with_any_data()
        {
            Context capturedContext = null;

            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryForeverAsync((_, context) => capturedContext = context);

            policy.Awaiting(async x => await x.RaiseExceptionAsync <DivideByZeroException>()).ShouldNotThrow();

            capturedContext.Should()
            .BeEmpty();
        }
Пример #11
0
        public void Should_call_onretry_with_the_passed_context_when_execute_and_capture()
        {
            IDictionary <string, object> contextData = null;

            Policy policy = Policy
                            .Handle <DivideByZeroException>()
                            .RetryAsync((_, __, context) => contextData = context);

            policy.Awaiting(async p => await p.ExecuteAndCaptureAsync(() => { throw new DivideByZeroException(); },
                                                                      new { key1 = "value1", key2 = "value2" }.AsDictionary()))
            .ShouldNotThrow();

            contextData.Should()
            .ContainKeys("key1", "key2").And
            .ContainValues("value1", "value2");
        }
Пример #12
0
 public void Executing_the_synchronous_policies_using_the_asynchronous_execute_and_capture_should_throw_an_invalid_operation_exception(Policy syncPolicy, string description)
 {
     syncPolicy
         .Awaiting(x => x.ExecuteAndCaptureAsync(() => CompletedTask))
         .ShouldThrow<InvalidOperationException>()
         .WithMessage("Please use the asynchronous RetryAsync, RetryForeverAsync, WaitAndRetryAsync or CircuitBreakerAsync methods when calling the asynchronous Execute method.");
 }
Пример #13
0
 public void Executing_the_synchronous_policies_using_the_asynchronous_execute_and_capture_should_throw_an_invalid_operation_exception(Policy syncPolicy, string description)
 {
     syncPolicy
         .Awaiting(async x => await x.ExecuteAndCaptureAsync(() => TaskHelper.EmptyTask))
         .ShouldThrow<InvalidOperationException>()
         .WithMessage("Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.");
 }