public void ApplyRequestOptionsDisablesKeepAlive() { var target = new Uri("http://example.org/"); var endpoint = new TestEndpoint(target); var request = endpoint.CreateWebRequest(); request.KeepAlive.Should().BeFalse(); }
public void ConstructorSetsTargetUri() { var target = new Uri("http://example.org/"); var endpoint = new TestEndpoint(target); var request = endpoint.CreateWebRequest(); request.RequestUri.Should().Be(target); }
public void ApplyRequestOptionsSetsUserAgentHeader() { var ep = new TestEndpoint(new Uri("http://example.org/")) { UserAgent = "My User Agent String" }; var req = ep.CreateWebRequest(); req.Headers["User-Agent"].Should().Be("My User Agent String"); }
public void ApplyRequestOptionsSetsTimeout() { var target = new Uri("http://example.org/"); var endpoint = new TestEndpoint(target) { Timeout = 1234 }; var request = endpoint.CreateWebRequest(); request.Timeout.Should().Be(1234); }
public void ApplyRequestOptionsSetsCredentials() { var target = new Uri("http://example.org/"); var cred = new NetworkCredential("test", "password"); var endpoint = new TestEndpoint(target) { Credentials = cred }; var request = endpoint.CreateWebRequest(); request.Credentials.Should().Be(cred); }
public void ApplyRequestOptionsSetsWebProxy() { var target = new Uri("http://example.org/"); var proxyUri = new Uri("http://proxy.contoso.com/"); var proxy = new WebProxy("http://proxy.contoso.com/"); var endpoint = new TestEndpoint(target) { Proxy = proxy }; var request = endpoint.CreateWebRequest(); request.Proxy.Should().Be(proxy); request.Proxy.GetProxy(target).Should().Be(proxyUri); }
public void ApplyRequestOptionsSetsWebProxyCredentials() { var target = new Uri("http://example.org/"); var proxyUri = new Uri("http://proxy.contoso.com/"); var cred = new NetworkCredential("test", "password"); var proxy = new WebProxy(proxyUri); var endpoint = new TestEndpoint(target) { Proxy = proxy, Credentials = cred, UseCredentialsForProxy = true }; var request = endpoint.CreateWebRequest(); request.Proxy.GetProxy(target).Should().Be(proxyUri); request.Proxy.Credentials.Should().Be(cred); }
public void ApplyRequestOptionsSetsBasicAuthHeader() { var target = new Uri("http://example.org/"); var cred = new NetworkCredential("test", "password"); var endpoint = new TestEndpoint(target) { Credentials = cred }; var expectedAuthorization = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("test:password")); Options.ForceHttpBasicAuth = true; try { var request = endpoint.CreateWebRequest(); request.Credentials.Should().BeNull(); request.Headers[HttpRequestHeader.Authorization].Should().Be(expectedAuthorization); } finally { Options.ForceHttpBasicAuth = false; } }