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 void Reset() { Uninvoke(); IsVerified = false; IsVerifiable = false; _verifiableBecause = null; _responseStrategy = null; Callback = null; _matchers = null; }
public TResponseResult RespondUsing(IResponseStrategy responseStrategy) { if (responseStrategy is null) { throw new ArgumentNullException(nameof(responseStrategy)); } Setup.SetResponse(responseStrategy); return((TResponseResult)(object)this); }
public override void SetResponse(IResponseStrategy responseStrategy) { _responseSequence.Add(responseStrategy); }
public virtual void SetResponse(IResponseStrategy responseStrategy) { _responseStrategy = responseStrategy; }