Exemple #1
0
        public void Properties_Invalid()
        {
            var h = HttpClientTestHelpers.CreateHttpClientHandler();

            try {
                h.MaxAutomaticRedirections = 0;
                Assert.Fail("#1");
            } catch (ArgumentOutOfRangeException) {
            }

            try {
                h.MaxRequestContentBufferSize = -1;
                Assert.Fail("#2");
            } catch (ArgumentOutOfRangeException) {
            }

            if (HttpClientTestHelpers.UsingSocketsHandler)
            {
                Assert.Ignore();
            }

            h.UseProxy = false;
            try {
                h.Proxy = new Proxy();
                Assert.Fail("#3");
            } catch (InvalidOperationException) {
            }
        }
Exemple #2
0
        public void Ctor_RelativeUriString()
        {
            var client = HttpClientTestHelpers.CreateHttpClient();

            client.BaseAddress = new Uri("http://en.wikipedia.org/wiki/");
            var req = new HttpRequestMessage(HttpMethod.Get, "Computer");

            // HttpRequestMessage does not rewrite it here.
            Assert.IsFalse(req.RequestUri.IsAbsoluteUri);
        }
Exemple #3
0
        public void Ctor_RelativeUri()
        {
            var client = HttpClientTestHelpers.CreateHttpClient();

            client.BaseAddress = new Uri("http://en.wikipedia.org/wiki/");
            var uri = new Uri("Computer", UriKind.Relative);
            var req = new HttpRequestMessage(HttpMethod.Get, uri);

            // HttpRequestMessage does not rewrite it here.
            Assert.AreEqual(req.RequestUri, uri);
        }
Exemple #4
0
        public void Properties_AfterClientCreation()
        {
            var h = HttpClientTestHelpers.CreateHttpClientHandler();

            h.AllowAutoRedirect = true;

            // We may modify properties after creating the HttpClient.
            using (var c = new HttpClient(h, true)) {
                h.AllowAutoRedirect = false;
            }
        }
Exemple #5
0
        public void Disposed()
        {
            var h = HttpClientTestHelpers.CreateHttpClientHandler();

            h.Dispose();
            var c = new HttpClient(h);

            try {
                c.GetAsync("http://www.example.com").Wait();
                Assert.Fail("#1");
            } catch (AggregateException e) {
                Assert.IsTrue(e.InnerException is ObjectDisposedException, "#2");
                Assert.IsFalse(HttpClientTestHelpers.IsSocketsHandler(h), "#3");
            } catch (ObjectDisposedException) {
                Assert.IsTrue(HttpClientTestHelpers.IsSocketsHandler(h), "#4");
            }
        }
Exemple #6
0
        public void Properties_Defaults()
        {
            var h = HttpClientTestHelpers.CreateHttpClientHandler();

            Assert.IsTrue(h.AllowAutoRedirect, "#1");
            Assert.AreEqual(DecompressionMethods.None, h.AutomaticDecompression, "#2");
            Assert.AreEqual(0, h.CookieContainer.Count, "#3");
            Assert.AreEqual(4096, h.CookieContainer.MaxCookieSize, "#3b");
            Assert.AreEqual(null, h.Credentials, "#4");
            Assert.AreEqual(50, h.MaxAutomaticRedirections, "#5");
            Assert.IsFalse(h.PreAuthenticate, "#7");
            Assert.IsNull(h.Proxy, "#8");
            Assert.IsTrue(h.SupportsAutomaticDecompression, "#9");
            Assert.IsTrue(h.SupportsProxy, "#10");
            Assert.IsTrue(h.SupportsRedirectConfiguration, "#11");
            Assert.IsTrue(h.UseCookies, "#12");
            Assert.IsFalse(h.UseDefaultCredentials, "#13");
            Assert.IsTrue(h.UseProxy, "#14");
            Assert.AreEqual(ClientCertificateOption.Manual, h.ClientCertificateOptions, "#15");
        }