public override async Task <HttpResponseMessage> SendAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken) { int nextRequestIndex = IncrementIfLessThan(ref _requestIndex, _responseSequence.Count - 1); // TODO: if Reset() has been called from other thread, this can result in IndexOutOfRangeException. Have to handle this is some way and make it thread safe. IResponseStrategy responseStrategy = nextRequestIndex >= 0 ? _responseSequence[nextRequestIndex] : null; if (responseStrategy is null) { // TODO: clarify which mock. throw new HttpMockException("No response configured for mock."); } try { cancellationToken.ThrowIfCancellationRequested(); Callback?.Invoke(requestContext.Request); HttpResponseMessage responseMessage = await responseStrategy.ProduceResponseAsync(requestContext, cancellationToken).ConfigureAwait(false); responseMessage.RequestMessage = requestContext.Request; return(responseMessage); } finally { IsInvoked = true; } }
public virtual async Task <HttpResponseMessage> SendAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken) { IsInvoked = true; if (_responseStrategy is null) { // TODO: clarify which mock. throw new HttpMockException("No response configured for mock."); } cancellationToken.ThrowIfCancellationRequested(); Callback?.Invoke(requestContext.Request); HttpResponseMessage responseMessage = await _responseStrategy.ProduceResponseAsync(requestContext, cancellationToken).ConfigureAwait(false); responseMessage.RequestMessage = requestContext.Request; return(responseMessage); }