public async Task RetryDelegatingHandler_OpenAsyncRetries()
        {
            // arrange
            int callCounter = 0;

            var             ct          = CancellationToken.None;
            PipelineContext contextMock = Substitute.For <PipelineContext>();

            contextMock.ConnectionStatusChangesHandler = new ConnectionStatusChangesHandler(delegate(ConnectionStatus status, ConnectionStatusChangeReason reason) { });
            IDelegatingHandler innerHandlerMock = Substitute.For <IDelegatingHandler>();

            innerHandlerMock
            .OpenAsync(ct)
            .Returns(t =>
            {
                return(++callCounter == 1
                            ? throw new IotHubException("Test transient exception", isTransient: true)
                            : TaskHelpers.CompletedTask);
            });
            innerHandlerMock.WaitForTransportClosedAsync().Returns(Task.Delay(TimeSpan.FromSeconds(10)));

            var retryDelegatingHandler = new RetryDelegatingHandler(contextMock, innerHandlerMock);

            // act
            await retryDelegatingHandler.OpenAsync(ct).ConfigureAwait(false);

            // assert
            callCounter.Should().Be(2);
        }
Esempio n. 2
0
        public async Task RetryDelegatingHandler_OpenAsyncRetries()
        {
            // arrange
            int callCounter = 0;

            IPipelineContext   contextMock      = Substitute.For <IPipelineContext>();
            IDelegatingHandler innerHandlerMock = Substitute.For <IDelegatingHandler>();

            innerHandlerMock.OpenAsync(Arg.Any <CancellationToken>()).Returns(t =>
            {
                return(++callCounter == 1
                    ? throw new IotHubException("Test transient exception", isTransient: true)
                    : TaskHelpers.CompletedTask);
            });
            innerHandlerMock.WaitForTransportClosedAsync().Returns(Task.Delay(TimeSpan.FromSeconds(10)));

            var retryDelegatingHandler = new RetryDelegatingHandler(contextMock, innerHandlerMock);

            // act
            await retryDelegatingHandler.OpenAsync(new CancellationToken()).ConfigureAwait(false);

            // assert
            Assert.AreEqual(2, callCounter);
        }