Ejemplo n.º 1
0
        public FluentHttpClient CreateClient(string name, Action <FluentHttpClientBuilder> build)
        {
            var builder = new FluentHttpClientBuilder(name, _httpClientFactory.CreateClient(name));

            build?.Invoke(builder);

            return(builder.Build());
        }
        public async Task WithListener_WhenListenerAutoCreated_ShouldUseListener()
        {
            var httpClientTester = new HttpClientTester()
                                   .SetResponseContent(new Person("James"));

            var client = new FluentHttpClientBuilder("Test", httpClientTester.Client)
                         .AddMessageListener <MessageListener>()
                         .Build();
            var response = await client.Get("url")
                           .ExecuteAsync <Person>();

            response?.StatusCode.Should().Be(200);
        }
        public async Task WithListener_WhenOnFunc_ShouldCallFunc()
        {
            var httpClientTester = new HttpClientTester()
                                   .SetResponseContent(new Person("James"));

            HttpRequestMessage  requestMessage  = null;
            HttpResponseMessage responseMessage = null;

            var client = new FluentHttpClientBuilder("Test", httpClientTester.Client)
                         .OnRequest(r => { requestMessage = r; return(Task.CompletedTask); })
                         .OnResponse(r => { responseMessage = r; return(Task.CompletedTask); })
                         .Build();
            var response = await client.Get("url")
                           .ExecuteAsync <Person>();

            response?.StatusCode.Should().Be(200);
            requestMessage.Should().NotBeNull();
            responseMessage.Should().NotBeNull();
        }
Ejemplo n.º 4
0
 public static FluentHttpClientBuilder WithMockMessageHandler(this FluentHttpClientBuilder builder, MockHttpMessageHandler handler = null)
 {
     handler = handler ?? new MockHttpMessageHandler();
     return(builder.WithMessageHandler(handler));
 }