public async Task Should_handle_handled_fault_and_execute_fallback_following_faulting_action_execution_when_user_delegate_does_not_observe_cancellationtoken()
        {
            bool fallbackActionExecuted = false;
            Func <CancellationToken, Task <ResultPrimitive> > fallbackAction = ct => { fallbackActionExecuted = true; return(Task.FromResult(ResultPrimitive.Substitute)); };

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            FallbackPolicy <ResultPrimitive> policy = Policy
                                                      .HandleResult(ResultPrimitive.Fault)
                                                      .OrResult(ResultPrimitive.FaultAgain)
                                                      .FallbackAsync(fallbackAction);

            int    attemptsInvoked = 0;
            Action onExecute       = () => attemptsInvoked++;

            Scenario scenario = new Scenario
            {
                AttemptDuringWhichToCancel = 1,
                ActionObservesCancellation = false
            };

            (await policy.RaiseResultSequenceAndOrCancellationAsync(scenario, cancellationTokenSource, onExecute, ResultPrimitive.Fault).ConfigureAwait(false))
            .Should().Be(ResultPrimitive.Substitute);
            attemptsInvoked.Should().Be(1);

            fallbackActionExecuted.Should().BeTrue();
        }
        public async Task Should_execute_action_when_non_faulting_and_cancellationtoken_not_cancelled()
        {
            bool fallbackActionExecuted = false;
            Func <CancellationToken, Task <ResultPrimitive> > fallbackAction = ct => { fallbackActionExecuted = true; return(Task.FromResult(ResultPrimitive.Substitute)); };

            FallbackPolicy <ResultPrimitive> policy = Policy
                                                      .HandleResult(ResultPrimitive.Fault)
                                                      .OrResult(ResultPrimitive.FaultAgain)
                                                      .FallbackAsync(fallbackAction);

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            int    attemptsInvoked = 0;
            Action onExecute       = () => attemptsInvoked++;

            Scenario scenario = new Scenario
            {
                AttemptDuringWhichToCancel = null,
            };

            (await policy.RaiseResultSequenceAndOrCancellationAsync(scenario, cancellationTokenSource, onExecute, ResultPrimitive.Good).ConfigureAwait(false))
            .Should().Be(ResultPrimitive.Good);
            attemptsInvoked.Should().Be(1);

            fallbackActionExecuted.Should().BeFalse();
        }