Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public async Task PostResponseIsDisposedWhenWrapperDisposed()
        {
            var testHandler    = new TestHttpMessageHandler();
            var client         = new TestHttpClient(new HttpClient(testHandler));
            var requestTracker = new DisposeTrackingHttpRequestMessage();
            var response       = new DisposeTrackingHttpResponseMessage(HttpStatusCode.OK)
            {
                RequestMessage = requestTracker,
            };

            testHandler.OnPost("/test", (r, ct) => Task.FromResult <HttpResponseMessage>(response));

            var resp = await client.Post("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);
        }