示例#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();
        }
示例#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);
        }
示例#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");
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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;
            }
        }