Exemple #1
0
        public void ApplyRequestOptionsDisablesKeepAlive()
        {
            var target   = new Uri("http://example.org/");
            var endpoint = new TestEndpoint(target);
            var request  = endpoint.CreateWebRequest();

            request.KeepAlive.Should().BeFalse();
        }
Exemple #2
0
        public void ConstructorSetsTargetUri()
        {
            var target   = new Uri("http://example.org/");
            var endpoint = new TestEndpoint(target);
            var request  = endpoint.CreateWebRequest();

            request.RequestUri.Should().Be(target);
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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;
            }
        }