コード例 #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Content = await PreventDisposeContentWrapper.CreateWrapperAsync(request.Content);

            actualRequests.Add(request);

            var expected = requestConfigurations.Dequeue();

            if (!request.RequestUri.Equals(new Uri(expected.Uri, UriKind.RelativeOrAbsolute)))
            {
                throw new AssertionFailedException($"expected request to '{expected.Uri}', but got request to '{request.RequestUri}'");
            }

            return(expected.GetResponseMessage());
        }
コード例 #2
0
        public static async Task <PreventDisposeContentWrapper> CreateWrapperAsync(HttpContent wrappedContent)
        {
            if (wrappedContent == null)
            {
                return(new PreventDisposeContentWrapper(new byte[0], null));
            }
            var bytes = await wrappedContent.ReadAsByteArrayAsync();

            var wrapper = new PreventDisposeContentWrapper(bytes, wrappedContent.GetType());

            foreach (var header in wrappedContent.Headers)
            {
                wrapper.Headers.Add(header.Key, header.Value);
            }
            return(wrapper);
        }