示例#1
0
 public Task <HttpResponseMessage> ProduceResponseAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken)
 {
     // It is somewhat unintuitive to throw TaskCanceledException but this is what HttpClient does atm,
     // so we simulate same behavior.
     // https://github.com/dotnet/corefx/issues/20296
     return(Task.Delay(_timeoutAfter, cancellationToken)
            .ContinueWith(_ =>
     {
         var tcs = new TaskCompletionSource <HttpResponseMessage>();
         tcs.TrySetCanceled();
         return tcs.Task;
     }, TaskScheduler.Current)
            .Unwrap());
 }
示例#2
0
        public Task <HttpResponseMessage> ProduceResponseAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken)
        {
            Stream stream = _content();

            if (!stream.CanRead)
            {
                throw new IOException("Cannot read from stream.");
            }

            return(Task.FromResult(new HttpResponseMessage(_statusCode)
            {
                Content = new StreamContent(stream)
                {
                    Headers =
                    {
                        ContentType = _mediaType
                    }
                }
            }));
        }
示例#3
0
 public Task <HttpResponseMessage> ProduceResponseAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken)
 {
     return(_responseFunc?.Invoke(requestContext.Request, cancellationToken) ?? Task.FromResult <HttpResponseMessage>(null));
 }
示例#4
0
 public Task <HttpResponseMessage> ProduceResponseAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken)
 {
     throw _exceptionFactory() ?? new HttpMockException("The configured exception cannot be null.");
 }
 /// <inheritdoc />
 public abstract Task <HttpResponseMessage> ProduceResponseAsync(MockHttpRequestContext requestContext, CancellationToken cancellationToken);