示例#1
0
        public void TestHttpClientAlwaysReturnsNewInstance()
        {
            var provider = new HttpClientProvider();

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

            Assert.AreNotSame(client1, client2);
        }
示例#2
0
        public void TestHttpClientAlwaysReturnsNewInstance()
        {
            var provider = new HttpClientProvider();

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

            Assert.AreNotSame(client1, client2);
        }
示例#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());
        }
示例#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());
        }
示例#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);
        }
示例#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);
        }