Exemplo n.º 1
0
        public void Should_report_faulting_from_faulting_last_retry_execution_when_user_delegate_does_not_observe_cancellation_raised_during_last_retry()
        {
            RetryPolicy <ResultPrimitive> policy = Policy
                                                   .HandleResult(ResultPrimitive.Fault)
                                                   .Retry(3);

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

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

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

            policy.RaiseResultSequenceAndOrCancellation(scenario, cancellationTokenSource, onExecute,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Good)
            .Should().Be(ResultPrimitive.Fault);

            attemptsInvoked.Should().Be(1 + 3);
        }
Exemplo n.º 2
0
        public void Should_execute_all_tries_when_faulting_and_cancellationToken_not_cancelled()
        {
            RetryPolicy <ResultPrimitive> policy = Policy
                                                   .HandleResult(ResultPrimitive.Fault)
                                                   .Retry(3);

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

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

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

            policy.RaiseResultSequenceAndOrCancellation(scenario, cancellationTokenSource, onExecute,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Fault,
                                                        ResultPrimitive.Good)
            .Should().Be(ResultPrimitive.Good);

            attemptsInvoked.Should().Be(1 + 3);
        }