public async Task RequestContentIsNotDisposedOnSend()
        {
            var requests            = new List <HttpRequestMessage>();
            var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);

            var mockHandler = new MockHttpClientHandler(httpRequestMessage =>
            {
                requests.Add(httpRequestMessage);
                return(Task.FromResult(httpResponseMessage));
            });

            DisposeTrackingContent disposeTrackingContent = new DisposeTrackingContent();
            var transport = new HttpClientTransport(new HttpClient(mockHandler));

            using (Request request = transport.CreateRequest())
            {
                request.Content = disposeTrackingContent;
                request.Method  = RequestMethod.Get;
                request.Uri.Reset(new Uri("https://example.com:340"));

                await ExecuteRequest(request, transport);

                Assert.False(disposeTrackingContent.IsDisposed);
            }

            Assert.True(disposeTrackingContent.IsDisposed);
        }
示例#2
0
        public async Task RequestContentIsNotDisposedOnSend()
        {
            using TestServer testServer = new TestServer(context => {});

            DisposeTrackingContent disposeTrackingContent = new DisposeTrackingContent();
            var transport = GetTransport();

            using (Request request = transport.CreateRequest())
            {
                request.Content = disposeTrackingContent;
                request.Method  = RequestMethod.Post;
                request.Uri.Reset(testServer.Address);

                await ExecuteRequest(request, transport);

                Assert.False(disposeTrackingContent.IsDisposed);
            }

            Assert.True(disposeTrackingContent.IsDisposed);
        }