/// <inheritdoc />
 public Action <HttpMessageHandlerBuilder> Configure(Action <HttpMessageHandlerBuilder> next)
 {
     return((builder) =>
     {
         next(builder);
         builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler());
     });
 }
            /// <inheritdoc/>
            public Action <HttpMessageHandlerBuilder> Configure(Action <HttpMessageHandlerBuilder> next)
            {
                return((builder) =>
                {
                    // Run any actions the application has configured for itself
                    next(builder);

                    // Add the interceptor as the last message handler
                    builder.AdditionalHandlers.Add(_options.CreateHttpMessageHandler());
                });
            }
Esempio n. 3
0
        public HttpServerFixture()
        {
            _interceptor = new HttpClientInterceptorOptions()
            {
                ThrowOnMissingRegistration = true
            };

            // Self-host the application, configuring the use of HTTP interception
            _server = new WebHostBuilder()
                      .UseStartup <TestStartup>()
                      .ConfigureServices((p) => p.AddTransient((_) => _interceptor.CreateHttpMessageHandler()))
                      .UseKestrel()
                      .UseUrls(ServerUrl)
                      .Build();

            _server.Start();
        }
Esempio n. 4
0
    public static async Task SendAsync_Throws_If_Registration_Missing_Post()
    {
        // Arrange
        var options = new HttpClientInterceptorOptions()
                      .ThrowsOnMissingRegistration();

        var mock = new Mock <HttpMessageHandler>();

        using var handler = options.CreateHttpMessageHandler();
        using var target  = new HttpClient(handler);
        using var content = new StringContent(string.Empty);

        // Act
        var exception = await Should.ThrowAsync <HttpRequestNotInterceptedException>(
            () => target.PostAsync("https://google.com/", content));

        // Assert
        exception.Message.ShouldBe("No HTTP response is configured for POST https://google.com/.");
        exception.Request.ShouldNotBeNull();
        exception.Request.RequestUri.ShouldBe(new Uri("https://google.com/"));
    }