示例#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.");
 }
 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.");
 }
        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>();
        }
        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>();
        }
        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>();
        }
        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");
        }
        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");
        }
        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.");
 }