public TestableHttpResponse(HttpResponseMessage response, byte[] content, ITestableHttpRequest request)
 {
     Content      = new MockHttpContent(response.Content, content);
     Request      = request;
     ReasonPhrase = response.ReasonPhrase;
     Headers      = response.Headers.ToDictionary(h => h.Key, h => h.Value.FirstOrDefault());
     StatusCode   = response.StatusCode;
 }
Пример #2
0
 internal MockHttpRequest(HttpListenerRequest request, byte[] content, Uri baseAddress)
 {
     Uri         = request.Url;
     Method      = new HttpMethod(request.HttpMethod);
     RelativeUri = "/" + baseAddress.MakeRelativeUri(request.Url);
     Headers     = request.Headers.AllKeys.ToDictionary(key => key, key => request.Headers[key]);
     Content     = new MockHttpContent(content, request.ContentEncoding, request.ContentType, new Dictionary <string, string>());
     BaseUri     = baseAddress;
 }
Пример #3
0
        private ITestableHttpResponse ApplyReplacements(ITestableHttpResponse response)
        {
            var content = response.ToStringContent();
            var headers = response.Headers.ToDictionary(kv => kv.Key, kv => kv.Value);

            foreach (var replacement in _replacements)
            {
                ReplaceIf(replacement, ref content, ReplacementOptions.Content);
                ReplaceHeaders(replacement, headers);
            }

            var httpContent = new MockHttpContent(response.Content.ContentEncoding.GetBytes(content), response.Content.ContentEncoding, response.Content.ContentType, response.Content.Headers);

            return(new TestableHttpResponse(response.Request, response.StatusCode, response.ReasonPhrase, httpContent, headers));
        }
Пример #4
0
        private ITestableHttpRequest ApplyReplacements(ITestableHttpRequest request)
        {
            var content     = request.GetContentAsString();
            var relativeUri = request.RelativeUri;
            var headers     = request.Headers.ToDictionary(kv => kv.Key, kv => kv.Value);

            foreach (var replacement in _replacements)
            {
                ReplaceIf(replacement, ref content, ReplacementOptions.Content);
                ReplaceIf(replacement, ref relativeUri, ReplacementOptions.Uri);
                ReplaceHeaders(replacement, headers);
            }

            var httpContent = new MockHttpContent(request.Content.ContentEncoding.GetBytes(content), request.Content.ContentEncoding, request.Content.ContentType, request.Content.Headers);

            return(new MockHttpRequest(request.BaseUri, request.Method, relativeUri, httpContent, headers));
        }