public void SetUp() { var fakeResponseDelegatingHandler = new FakeResponseDelegatingHandler(); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.OK)); httpClient = new HttpClient(new CircuitBreakingDelegatingHandler(EXCEPTIONS_ALLOWED_BEFORE_BREAKING, circuitOpenDuration, fakeResponseDelegatingHandler)); // trigger circuit break response1 = httpClient.GetAsync(TEST_URI).Result; response2 = httpClient.GetAsync(TEST_URI).Result; // circuit should be open try { var response3 = httpClient.GetAsync(TEST_URI).Result; } catch (BrokenCircuitException brokenCircuitException) { httpClientException = brokenCircuitException; } WaitCircuitToBeClosed(); response4 = httpClient.GetAsync(TEST_URI).Result; }
public void SetUp() { var fakeResponseDelegatingHandler = new FakeResponseDelegatingHandler(); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.OK)); httpClient = new HttpClient(new RetryingDelegatingHandler(RETRY_COUNT, fakeResponseDelegatingHandler)); response = httpClient.GetAsync(TEST_URI).Result; }