public void Factory_MultipleCalls_CachesHandler()
        {
            // Arrange
            var count = 0;

            Options.CurrentValue.HttpMessageHandlerBuilderActions.Add(b =>
            {
                count++;
            });

            var factory = new DefaultHttpClientFactory(Services, Options, EmptyFilters);

            // Act 1
            var client1 = factory.CreateClient();

            // Act 2
            var client2 = factory.CreateClient();

            // Assert
            Assert.Equal(1, count);
            Assert.NotSame(client1, client2);
        }
        public void Factory_MultipleCalls_DoesNotCacheHttpClient()
        {
            // Arrange
            var count = 0;

            Options.CurrentValue.HttpClientActions.Add(c =>
            {
                count++;
            });

            var factory = new DefaultHttpClientFactory(Services, Options, EmptyFilters);

            // Act 1
            var client1 = factory.CreateClient();

            // Act 2
            var client2 = factory.CreateClient();

            // Assert
            Assert.Equal(2, count);
            Assert.NotSame(client1, client2);
        }
        public void Factory_CreateClient_WithName_UsesNamedOptions()
        {
            // Arrange
            var count = 0;

            Options.Get("github").HttpClientActions.Add(b =>
            {
                count++;
            });

            var factory = new DefaultHttpClientFactory(Services, Options, EmptyFilters);

            // Act
            var client = factory.CreateClient("github");

            // Assert
            Assert.Equal(1, count);
        }
        public void Factory_CreateClient_WithoutName_UsesDefaultOptions()
        {
            // Arrange
            var count = 0;

            Options.CurrentValue.HttpClientActions.Add(b =>
            {
                count++;
            });

            var factory = new DefaultHttpClientFactory(Services, Options, EmptyFilters);

            // Act
            var client = factory.CreateClient();

            // Assert
            Assert.Equal(1, count);
        }
        public void Factory_DisposeClient_DoesNotDisposeHandler()
        {
            // Arrange
            Options.CurrentValue.HttpMessageHandlerBuilderActions.Add(b =>
            {
                var mockHandler = new Mock <HttpMessageHandler>();
                mockHandler
                .Protected()
                .Setup("Dispose", true)
                .Throws(new Exception("Dispose should not be called"));

                b.PrimaryHandler = mockHandler.Object;
            });

            var factory = new DefaultHttpClientFactory(Services, Options, EmptyFilters);

            // Act
            using (factory.CreateClient())
            {
            }

            // Assert (does not throw)
        }