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

            _tapes.TryGetValue(key, out tapedResponse);
            return(tapedResponse);
        }
Esempio 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);
            }
        }
Esempio n. 3
0
 protected TapedResponse(RequestKey requestKey)
 {
     RequestKey = requestKey;
 }
Esempio n. 4
0
 public HttpClientTapedResponse(RequestKey requestKey, HttpResponseMessage responseMessage, byte[] body) : base(requestKey)
 {
     _responseMessage = responseMessage;
     _body            = body;
 }