public async Task Reactive_policy_should_be_able_to_ignore_unhandled_result() { ResultPrimitive?handled = null; AsyncAddBehaviourIfHandlePolicy <ResultPrimitive> policy = Policy .HandleResult <ResultPrimitive>(ResultPrimitive.Fault) .WithBehaviourAsync(async outcome => { handled = outcome.Result; await Task.CompletedTask; }); ResultPrimitive toReturn = ResultPrimitive.FaultYetAgain; bool executed = false; (await policy.ExecuteAsync(async() => { executed = true; await Task.CompletedTask; return(toReturn); })) .Should().Be(toReturn); executed.Should().BeTrue(); handled.Should().Be(null); }
public async Task Reactive_policy_should_handle_result() { ResultPrimitive handled = ResultPrimitive.Undefined; AsyncAddBehaviourIfHandlePolicy <ResultPrimitive> policy = Policy .HandleResult <ResultPrimitive>(ResultPrimitive.Fault) .WithBehaviourAsync(async outcome => { handled = outcome.Result; await Task.CompletedTask; }); ResultPrimitive toReturn = ResultPrimitive.Fault; bool executed = false; (await policy.ExecuteAsync(async() => { executed = true; await Task.CompletedTask; return(toReturn); })) .Should().Be(toReturn); executed.Should().BeTrue(); handled.Should().Be(toReturn); }