Exemplo n.º 1
0
 private static void ReplayNoMapping(IMockHttpResponse response)
 {
     response
     .SetStatusCode(HttpStatusCode.NotImplemented)
     .SetStringContent(
         "Proxy works in replay mode and no mapping is specified for this request.",
         Encoding.UTF8,
         "text");
 }
Exemplo n.º 2
0
        private void Replay(IMockHttpResponse rsp, ITestableHttpResponse response)
        {
            rsp.SetStatusCode(response.StatusCode)
            .SetHeaders(response.Headers.Where(kv => !InvalidHeaders.Contains(kv.Key)));

            if (response.Content.ContentLength > 0)
            {
                rsp.SetContent(
                    response.Content.Content,
                    response.Content.ContentEncoding,
                    response.Content.ContentType);
            }
        }
Exemplo n.º 3
0
        private void ReplayResponse(ITestableHttpRequest request, IMockHttpResponse response)
        {
            var expectation = _expectations.FirstOrDefault(e => e.Match(request));

            if (expectation != null)
            {
                Replay(response, expectation.PrepareForReplay(request, _repository));
            }
            else
            {
                ReplayNoMapping(response);
            }
        }
Exemplo n.º 4
0
        private async Task ProxyAndRecordAsync(ITestableHttpRequest req, IMockHttpResponse rsp)
        {
            var request = new HttpRequestMessage(req.Method, req.RelativeUri)
            {
                Content = req.Content.ContentLength >= 0 ? new ByteArrayContent(req.Content.Content) : null
            };

            CopyHeaders(req, request);

            var response = await Proxy.SendAsync(request);

            var content = await response.Content.ReadAsByteArrayAsync();

            var recorded = new TestableHttpResponse(response, content, req);

            _repository.Add(recorded);
            Replay(rsp, recorded);
        }