public void RetryHandlerRetriesWith500Errors() { var fakeClient = new FakeServiceClient(new FakeHttpHandler()); int attemptsFailed = 0; fakeClient.SetRetryPolicy(new RetryPolicy<DefaultHttpErrorDetectionStrategy>(2)); var retryHandler = fakeClient.GetHttpPipeline().OfType<RetryHandler>().FirstOrDefault(); retryHandler.Retrying += (sender, args) => { attemptsFailed++; }; var result = fakeClient.DoStuff(); Assert.Equal(HttpStatusCode.InternalServerError, result.Result.StatusCode); Assert.Equal(2, attemptsFailed); }
public void RetryHandlerDoesntRetryFor400Errors() { var fakeClient = new FakeServiceClient(new FakeHttpHandler() { StatusCodeToReturn = HttpStatusCode.Conflict }); int attemptsFailed = 0; fakeClient.SetRetryPolicy(new RetryPolicy<DefaultHttpErrorDetectionStrategy>(2)); var retryHandler = fakeClient.GetHttpPipeline().OfType<RetryHandler>().FirstOrDefault(); retryHandler.Retrying += (sender, args) => { attemptsFailed++; }; var result = fakeClient.DoStuff(); Assert.Equal(HttpStatusCode.Conflict, result.Result.StatusCode); Assert.Equal(0, attemptsFailed); }
public void RetryHandlerRetriesWith500Errors() { var fakeClient = new FakeServiceClient(new FakeHttpHandler()); int attemptsFailed = 0; fakeClient.SetRetryPolicy(new RetryPolicy <DefaultHttpErrorDetectionStrategy>(2)); var retryHandler = fakeClient.GetHttpPipeline().OfType <RetryHandler>().FirstOrDefault(); retryHandler.Retrying += (sender, args) => { attemptsFailed++; }; var result = fakeClient.DoStuff(); Assert.Equal(HttpStatusCode.InternalServerError, result.Result.StatusCode); Assert.Equal(2, attemptsFailed); }
public void RetryHandlerDoesntRetryFor400Errors() { var fakeClient = new FakeServiceClient(new FakeHttpHandler() { StatusCodeToReturn = HttpStatusCode.Conflict }); int attemptsFailed = 0; fakeClient.SetRetryPolicy(new RetryPolicy <DefaultHttpErrorDetectionStrategy>(2)); var retryHandler = fakeClient.GetHttpPipeline().OfType <RetryHandler>().FirstOrDefault(); retryHandler.Retrying += (sender, args) => { attemptsFailed++; }; var result = fakeClient.DoStuff(); Assert.Equal(HttpStatusCode.Conflict, result.Result.StatusCode); Assert.Equal(0, attemptsFailed); }