Exemplo n.º 1
0
        public TapedResponse Get(RequestKey key)
        {
            TapedResponse tapedResponse;

            _tapes.TryGetValue(key, out tapedResponse);
            return(tapedResponse);
        }
Exemplo n.º 2
0
        // ReSharper disable once UnusedMember.Global
        public async Task Invoke(HttpContext context)
        {
            var incomingRequest = context.Request;
            var requestKey      = new RequestKey(incomingRequest);

            var tapedResponse = _tapeRepository.Get(requestKey);

            if (tapedResponse != null)
            {
                _logger.LogInformation("request was previously recorded, playing back tape");
                tapedResponse.WriteTo(context.Response);
            }
            else
            {
                _logger.LogInformation("could not find recorded tape for request, passing through, and recording it");

                var incomingResponse = await ProxyRequestAsync(incomingRequest, context.RequestAborted);

                tapedResponse = await requestKey.CreateTapeFromAsync(incomingResponse);

                tapedResponse.WriteTo(context.Response);

                _tapeRepository.Store(tapedResponse);
            }
        }
Exemplo n.º 3
0
 protected TapedResponse(RequestKey requestKey)
 {
     RequestKey = requestKey;
 }
Exemplo n.º 4
0
 public HttpClientTapedResponse(RequestKey requestKey, HttpResponseMessage responseMessage, byte[] body) : base(requestKey)
 {
     _responseMessage = responseMessage;
     _body            = body;
 }