public void HttpClientFromMessageHandlerFactory_Compression()
        {
            int handlerFactoryCalled = 0;
            var clientFactory        = new HttpClientFromMessageHandlerFactory(MessageHandlerFactory);

            Assert.NotNull(clientFactory.CreateHttpClient(new CreateHttpClientArgs {
                GZipEnabled = true
            }));

            ConfiguredHttpMessageHandler MessageHandlerFactory(HttpMessageHandlerOptions options)
            {
                handlerFactoryCalled++;
                if (handlerFactoryCalled == 1)
                {
                    Assert.False(options.MayHandleRedirects);
                    Assert.True(options.MayPerformDecompression);

                    return(new ConfiguredHttpMessageHandler(new MockMessageHandler(), true, false));
                }
                else
                {
                    Assert.False(options.MayHandleRedirects);
                    Assert.False(options.MayPerformDecompression);

                    return(new ConfiguredHttpMessageHandler(new MockMessageHandler(), false, false));
                }
            }

            Assert.Equal(2, handlerFactoryCalled);
        }
        public void HttpClientFromMessageHandlerFactory_BadMessageHandlerFactory(
            Func <HttpMessageHandlerOptions, ConfiguredHttpMessageHandler> handlerFactory, bool gZipEnabled)
        {
            var clientFactory = new HttpClientFromMessageHandlerFactory(handlerFactory);

            Assert.Throws <InvalidOperationException>(() => clientFactory.CreateHttpClient(new CreateHttpClientArgs {
                GZipEnabled = gZipEnabled
            }));
        }