Ejemplo n.º 1
0
        public void TestHttpClientAlwaysReturnsNewInstance()
        {
            var provider = new HttpClientProvider();

            var client1 = provider.Create();
            var client2 = provider.Create();

            Assert.AreNotSame(client1, client2);
        }
Ejemplo n.º 2
0
        public void TestHttpClientAlwaysReturnsNewInstance()
        {
            var provider = new HttpClientProvider();

            var client1 = provider.Create();
            var client2 = provider.Create();

            Assert.AreNotSame(client1, client2);
        }
Ejemplo n.º 3
0
        public void TestHttpClientWithCustomInitialisation()
        {
            var provider = new HttpClientProvider
            {
                InitialiseWith = c => c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Test", "1.0"))
            };

            var client = provider.Create();

            Assert.AreEqual("Test/1.0", client.DefaultRequestHeaders.UserAgent.ToString());
        }
Ejemplo n.º 4
0
        public void TestHttpClientWithCustomInitialisation()
        {
            var provider = new HttpClientProvider
            {
                InitialiseWith = c => c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Test", "1.0"))
            };

            var client = provider.Create();

            Assert.AreEqual("Test/1.0", client.DefaultRequestHeaders.UserAgent.ToString());
        }
Ejemplo n.º 5
0
        public void TestHttpClientWithRetryInterceptWhenShouldRetry()
        {
            var interceptCount = 0;

            var innerHandler = new FakeHandler();

            var provider = new HttpClientProvider
                           {
                               RetryIntercept = delegate
                                                      {
                                                          interceptCount++;
                                                          return Task.FromResult(true);
                                                      }
                           };

            var client = provider.Create(innerHandler);

            client.GetAsync("http://hello.world/boo");

            Assert.AreEqual(1, interceptCount);
            Assert.AreEqual(2, innerHandler.RequestCount);
        }
Ejemplo n.º 6
0
        public void TestHttpClientWithRetryInterceptWithRetryInterceptSetButShouldNotRetry()
        {
            var interceptCount = 0;

            var innerHandler = new FakeHandler();

            var provider = new HttpClientProvider
            {
                RetryIntercept = delegate
                {
                    interceptCount++;
                    return(Task.FromResult(true));
                }
            };

            var client = provider.Create(innerHandler, false);

            client.GetAsync("http://hello.world/boo");

            Assert.AreEqual(0, interceptCount);
            Assert.AreEqual(1, innerHandler.RequestCount);
        }