public void TestHttpClientAlwaysReturnsNewInstance() { var provider = new HttpClientProvider(); var client1 = provider.Create(); var client2 = provider.Create(); Assert.AreNotSame(client1, client2); }
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()); }
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); }
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); }