public void CreateClientUsesDefaultsWhenFactoryUsesDefaults() { using StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(); using HttpClient client = httpClientFactory.CreateClient(); HttpMessageHandler handler = GetHandler(client); Assert.IsType <SocketsHttpHandler>(GetHandler(client)); Assert.Equal(StandaloneHttpClientFactory.DefaultConnectionLifetime, ((SocketsHttpHandler)handler).PooledConnectionLifetime); }
public void CreateClientCreatesNewClientWithSameHandler() { using StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(); using HttpClient client1 = httpClientFactory.CreateClient(); using HttpClient client2 = httpClientFactory.CreateClient(); HttpMessageHandler handler1 = GetHandler(client1); HttpMessageHandler handler2 = GetHandler(client2); Assert.NotSame(client1, client2); Assert.Same(handler1, handler2); }
public void CreateClientUsesLoggerToCreateLoggingHandler() { using StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(NullLogger.Instance); using HttpClient client = httpClientFactory.CreateClient(); HttpMessageHandler handler = GetHandler(client); Assert.IsType <LoggingHttpMessageHandler>(GetHandler(client)); LoggingHttpMessageHandler loggingHandler = (LoggingHttpMessageHandler)handler; Assert.IsType <SocketsHttpHandler>(loggingHandler.InnerHandler); }
public void CreateClientUsesProvidedConnectionLifetime() { TimeSpan connectionLifetime = TimeSpan.FromMinutes(1); using StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(connectionLifetime); using HttpClient client = httpClientFactory.CreateClient(); HttpMessageHandler handler = GetHandler(client); Assert.IsType <SocketsHttpHandler>(GetHandler(client)); Assert.Equal(connectionLifetime, ((SocketsHttpHandler)handler).PooledConnectionLifetime); }
public void CreateClientUsesDefaultsWhenFactoryUsesDefaults() { using (StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory()) { using (HttpClient client = httpClientFactory.CreateClient()) { HttpMessageHandler handler = GetHandler(client); Assert.IsType <ServicePointHttpMessageHandler>(GetHandler(client)); Assert.Equal(StandaloneHttpClientFactory.DefaultConnectionLifetime, ((ServicePointHttpMessageHandler)handler).ConnectionLeaseTimeout); } } }
public void CreateClientUsesLoggerToCreateLoggingHandler() { using (StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(NullLogger.Instance)) { using (HttpClient client = httpClientFactory.CreateClient()) { HttpMessageHandler handler = GetHandler(client); Assert.IsType <LoggingHttpMessageHandler>(handler); LoggingHttpMessageHandler loggingHandler = (LoggingHttpMessageHandler)handler; Assert.IsType <ServicePointHttpMessageHandler>(loggingHandler.InnerHandler); } } }
public void CreateClientUsesProvidedConnectionLifetime() { TimeSpan connectionLifetime = TimeSpan.FromMinutes(1); using (StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(connectionLifetime)) { using (HttpClient client = httpClientFactory.CreateClient()) { HttpMessageHandler handler = GetHandler(client); Assert.IsType <ServicePointHttpMessageHandler>(GetHandler(client)); Assert.Equal(connectionLifetime, ((ServicePointHttpMessageHandler)handler).ConnectionLeaseTimeout); } } }
public void CreateClientCreatesHandlerPipeline() { DelegatingHandler foo = A.Fake <DelegatingHandler>(options => options.CallsBaseMethods()); DelegatingHandler bar = A.Fake <DelegatingHandler>(options => options.CallsBaseMethods()); using StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory(foo, bar); using HttpClient client = httpClientFactory.CreateClient(); HttpMessageHandler handler = GetHandler(client); Assert.Same(foo, handler); DelegatingHandler delegatingHandler = (DelegatingHandler)handler; Assert.Same(bar, delegatingHandler.InnerHandler); delegatingHandler = (DelegatingHandler)delegatingHandler.InnerHandler; Assert.IsType <SocketsHttpHandler>(delegatingHandler.InnerHandler); }
public void CreateClientCreatesSameClient() { using (StandaloneHttpClientFactory httpClientFactory = new StandaloneHttpClientFactory()) { using (HttpClient client1 = httpClientFactory.CreateClient()) { using (HttpClient client2 = httpClientFactory.CreateClient()) { HttpMessageHandler handler1 = GetHandler(client1); HttpMessageHandler handler2 = GetHandler(client2); Assert.Same(client1, client2); Assert.Same(handler1, handler2); } } } }