public void Should_not_call_fallbackAction_with_the_fault_if_fault_unhandled() { DelegateResult <ResultPrimitive> fallbackOutcome = null; Func <DelegateResult <ResultPrimitive>, Context, CancellationToken, ResultPrimitive> fallbackAction = (outcome, ctx, ct) => { fallbackOutcome = outcome; return(ResultPrimitive.Substitute); }; Action <DelegateResult <ResultPrimitive>, Context> onFallback = (ex, ctx) => { }; FallbackPolicy <ResultPrimitive> fallbackPolicy = Policy <ResultPrimitive> .HandleResult(ResultPrimitive.Fault) .Fallback(fallbackAction, onFallback); fallbackPolicy.Execute(() => { return(ResultPrimitive.FaultAgain); }) .Should().Be(ResultPrimitive.FaultAgain); fallbackOutcome.Should().BeNull(); }
public async Task Should_not_call_fallbackAction_with_the_fault_if_fault_unhandled() { DelegateResult <ResultPrimitive> fallbackOutcome = null; Func <DelegateResult <ResultPrimitive>, Context, CancellationToken, Task <ResultPrimitive> > fallbackAction = (outcome, ctx, ct) => { fallbackOutcome = outcome; return(Task.FromResult(ResultPrimitive.Substitute)); }; Func <DelegateResult <ResultPrimitive>, Context, Task> onFallback = (ex, ctx) => { return(TaskHelper.EmptyTask); }; FallbackPolicy <ResultPrimitive> fallbackPolicy = Policy <ResultPrimitive> .HandleResult(ResultPrimitive.Fault) .FallbackAsync(fallbackAction, onFallback); var result = await fallbackPolicy.ExecuteAsync(() => { return(Task.FromResult(ResultPrimitive.FaultAgain)); }); result.Should().Be(ResultPrimitive.FaultAgain); fallbackOutcome.Should().BeNull(); }
public void Should_call_fallbackAction_with_the_fault() { DelegateResult <ResultPrimitive> fallbackOutcome = null; Func <DelegateResult <ResultPrimitive>, Context, CancellationToken, ResultPrimitive> fallbackAction = (outcome, _, _) => { fallbackOutcome = outcome; return(ResultPrimitive.Substitute); }; Action <DelegateResult <ResultPrimitive>, Context> onFallback = (_, _) => { }; FallbackPolicy <ResultPrimitive> fallbackPolicy = Policy <ResultPrimitive> .HandleResult(ResultPrimitive.Fault) .Fallback(fallbackAction, onFallback); fallbackPolicy.Execute(() => ResultPrimitive.Fault) .Should().Be(ResultPrimitive.Substitute); fallbackOutcome.Should().NotBeNull(); fallbackOutcome.Exception.Should().BeNull(); fallbackOutcome.Result.Should().Be(ResultPrimitive.Fault); }
public async Task Should_call_fallbackAction_with_the_fault() { DelegateResult <ResultPrimitive> fallbackOutcome = null; Func <DelegateResult <ResultPrimitive>, Context, CancellationToken, Task <ResultPrimitive> > fallbackAction = (outcome, _, _) => { fallbackOutcome = outcome; return(Task.FromResult(ResultPrimitive.Substitute)); }; Func <DelegateResult <ResultPrimitive>, Context, Task> onFallback = (_, _) => TaskHelper.EmptyTask; var fallbackPolicy = Policy <ResultPrimitive> .HandleResult(ResultPrimitive.Fault) .FallbackAsync(fallbackAction, onFallback); var result = await fallbackPolicy.ExecuteAsync(() => Task.FromResult(ResultPrimitive.Fault)); result.Should().Be(ResultPrimitive.Substitute); fallbackOutcome.Should().NotBeNull(); fallbackOutcome.Exception.Should().BeNull(); fallbackOutcome.Result.Should().Be(ResultPrimitive.Fault); }
public void Should_call_fallbackAction_with_the_fault_when_execute_and_capture() { DelegateResult <ResultPrimitive> fallbackOutcome = null; Func <DelegateResult <ResultPrimitive>, Context, CancellationToken, ResultPrimitive> fallbackAction = (outcome, ctx, ct) => { fallbackOutcome = outcome; return(ResultPrimitive.Substitute); }; Action <DelegateResult <ResultPrimitive>, Context> onFallback = (ex, ctx) => { }; FallbackPolicy <ResultPrimitive> fallbackPolicy = Policy <ResultPrimitive> .HandleResult(ResultPrimitive.Fault) .Fallback(fallbackAction, onFallback); var result = fallbackPolicy.ExecuteAndCapture(() => { return(ResultPrimitive.Fault); }); result.Should().NotBeNull(); result.Result.Should().Be(ResultPrimitive.Substitute); fallbackOutcome.Should().NotBeNull(); fallbackOutcome.Exception.Should().BeNull(); fallbackOutcome.Result.Should().Be(ResultPrimitive.Fault); }