コード例 #1
0
        public HttpDiagnosticsHandlerTests()
        {
            _request = new HttpRequestMessage
            {
                Content = new StringContent("test data")
            };

            _logger = Substitute.For <ILogger>();

            _innerHandler          = Substitute.For <HttpMessageHandler>();
            _mockInternalSendAsync = _innerHandler.Protected("SendAsync", Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>());
            _mockInternalSendAsync.Returns(Task.FromResult(new HttpResponseMessage()));
        }
コード例 #2
0
ファイル: TestingHttpClient.cs プロジェクト: georgepinca/src
        private static void PrepareHttpClient(ref HttpMessageHandler httpMessageHandler, ref HttpClient httpClient, ref IHttpClientFactory httpClientFactory, bool failingClient = false)
        {
            httpMessageHandler = Substitute.ForPartsOf <HttpMessageHandler>();

            object sendCall = httpMessageHandler.Protected("SendAsync", Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>());

            if (failingClient)
            {
                sendCall.ThrowsForAnyArgs(new HttpRequestException("failed"));
            }
            else
            {
                sendCall.Returns(Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)));
            }

            httpClient        = new HttpClient(httpMessageHandler);
            httpClientFactory = Substitute.For <IHttpClientFactory>();
            httpClientFactory.CreateClient(Arg.Any <string>()).Returns(httpClient);
        }