public async Task GetResponseIsDisposedIfResponseIsNonSuccessful() { var testHandler = new TestHttpMessageHandler(); var client = new TestHttpClient(new HttpClient(testHandler)); var requestTracker = new DisposeTrackingHttpRequestMessage(); var response = new DisposeTrackingHttpResponseMessage(HttpStatusCode.NotFound) { RequestMessage = requestTracker, }; testHandler.OnGet("/test", (r, ct) => Task.FromResult <HttpResponseMessage>(response)); await Assert.ThrowsAsync <HttpClientException>(() => client.Get("http://example.com/test", r => { }, isLongRunning: false)); Assert.True(response.Disposed); Assert.True(requestTracker.Disposed); }
public async Task GetResponseIsDisposedWhenWrapperDisposed() { var testHandler = new TestHttpMessageHandler(); var client = new TestHttpClient(new HttpClient(testHandler)); var requestTracker = new DisposeTrackingHttpRequestMessage(); var response = new DisposeTrackingHttpResponseMessage(HttpStatusCode.OK) { RequestMessage = requestTracker, }; testHandler.OnGet("/test", (r, ct) => Task.FromResult <HttpResponseMessage>(response)); var resp = await client.Get("http://example.com/test", r => { }, isLongRunning : false); Assert.False(response.Disposed); Assert.False(requestTracker.Disposed); resp.Dispose(); Assert.True(response.Disposed); Assert.True(requestTracker.Disposed); }