@@ -19,7 +19,7 @@ public RetryDelegatingHandlerTests()
1919 {
2020 reliabilitySettings = new ReliabilitySettings
2121 {
22- RetryCount = 2
22+ RetryCount = 1
2323 } ;
2424 innerHandler = new RetryTestBehaviourDelegatingHandler ( ) ;
2525 client = new HttpClient ( new RetryDelegatingHandler ( innerHandler , reliabilitySettings ) )
@@ -31,7 +31,7 @@ public RetryDelegatingHandlerTests()
3131 [ Fact ]
3232 public async Task Invoke_ShouldReturnHttpResponseAndNotRetryWhenSuccessful ( )
3333 {
34- innerHandler . ConfigureBehaviour ( innerHandler . OK ) ;
34+ innerHandler . AddBehaviour ( innerHandler . OK ) ;
3535
3636 var result = await client . SendAsync ( new HttpRequestMessage ( ) ) ;
3737
@@ -42,7 +42,7 @@ public async Task Invoke_ShouldReturnHttpResponseAndNotRetryWhenSuccessful()
4242 [ Fact ]
4343 public async Task Invoke_ShouldReturnHttpResponseAndNotRetryWhenUnauthorised ( )
4444 {
45- innerHandler . ConfigureBehaviour ( innerHandler . AuthenticationError ) ;
45+ innerHandler . AddBehaviour ( innerHandler . AuthenticationError ) ;
4646
4747 var result = await client . SendAsync ( new HttpRequestMessage ( ) ) ;
4848
@@ -53,43 +53,45 @@ public async Task Invoke_ShouldReturnHttpResponseAndNotRetryWhenUnauthorised()
5353 [ Fact ]
5454 public async Task Invoke_ShouldReturnErrorWithoutRetryWhenErrorIsNotTransient ( )
5555 {
56- innerHandler . ConfigureBehaviour ( innerHandler . NonTransientException ) ;
56+ innerHandler . AddBehaviour ( innerHandler . NonTransientException ) ;
5757
58- await Assert . ThrowsAsync < InvalidOperationException > (
59- ( ) =>
60- {
61- return client . SendAsync ( new HttpRequestMessage ( ) ) ;
62- } ) ;
58+ await Assert . ThrowsAsync < InvalidOperationException > ( ( ) => client . SendAsync ( new HttpRequestMessage ( ) ) ) ;
6359
6460 Assert . Equal ( 1 , innerHandler . InvocationCount ) ;
6561 }
6662
63+ [ Fact ]
64+ public async Task Invoke_ShoulddRetryOnceWhenFailedOnFirstAttemptThenSuccessful ( )
65+ {
66+ innerHandler . AddBehaviour ( innerHandler . TaskCancelled ) ;
67+ innerHandler . AddBehaviour ( innerHandler . OK ) ;
68+
69+ var result = await client . SendAsync ( new HttpRequestMessage ( ) ) ;
70+
71+ Assert . Equal ( result . StatusCode , HttpStatusCode . OK ) ;
72+ Assert . Equal ( 2 , innerHandler . InvocationCount ) ;
73+ }
74+
6775 [ Fact ]
6876 public async Task Invoke_ShouldRetryTheExpectedAmountOfTimesAndReturnTimeoutExceptionWhenTasksCancelled ( )
6977 {
70- innerHandler . ConfigureBehaviour ( innerHandler . TaskCancelled ) ;
78+ innerHandler . AddBehaviour ( innerHandler . TaskCancelled ) ;
79+ innerHandler . AddBehaviour ( innerHandler . TaskCancelled ) ;
7180
72- await Assert . ThrowsAsync < TimeoutException > (
73- ( ) =>
74- {
75- return client . SendAsync ( new HttpRequestMessage ( ) ) ;
76- } ) ;
81+ await Assert . ThrowsAsync < TimeoutException > ( ( ) => client . SendAsync ( new HttpRequestMessage ( ) ) ) ;
7782
78- Assert . Equal ( 3 , innerHandler . InvocationCount ) ;
83+ Assert . Equal ( 2 , innerHandler . InvocationCount ) ;
7984 }
8085
8186 [ Fact ]
8287 public async Task Invoke_ShouldRetryTheExpectedAmountOfTimesAndReturnExceptionWhenInternalServerErrorsEncountered ( )
8388 {
84- innerHandler . ConfigureBehaviour ( innerHandler . InternalServerError ) ;
89+ innerHandler . AddBehaviour ( innerHandler . InternalServerError ) ;
90+ innerHandler . AddBehaviour ( innerHandler . InternalServerError ) ;
8591
86- await Assert . ThrowsAsync < HttpRequestException > (
87- ( ) =>
88- {
89- return client . SendAsync ( new HttpRequestMessage ( ) ) ;
90- } ) ;
92+ await Assert . ThrowsAsync < HttpRequestException > ( ( ) => client . SendAsync ( new HttpRequestMessage ( ) ) ) ;
9193
92- Assert . Equal ( 3 , innerHandler . InvocationCount ) ;
94+ Assert . Equal ( 2 , innerHandler . InvocationCount ) ;
9395 }
9496
9597 [ Fact ]
0 commit comments