diff options
author | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-04-10 16:03:09 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-04-10 16:03:50 +0300 |
commit | 183b22b4dbad954565fba2859897f7efdf330d52 (patch) | |
tree | b9f173179da7710935aa95133d070656675ad6db /mcs/class/System.Net.Http | |
parent | 22c6ed3f1c5e3588489a5ca20ac92a3140d98e1f (diff) |
[System.Net.Http] Make some tests specific to HttpClientHandler
Otherwise they throw PNSE on e.g. WatchOS.
(cherry picked from commit 0b6dbfa34965351b3e0a3fd52739479df62896a0)
Diffstat (limited to 'mcs/class/System.Net.Http')
3 files changed, 33 insertions, 27 deletions
diff --git a/mcs/class/System.Net.Http/Test/HttpClientTestHelpers.cs b/mcs/class/System.Net.Http/Test/HttpClientTestHelpers.cs index 72382819ab6..32e858eac16 100644 --- a/mcs/class/System.Net.Http/Test/HttpClientTestHelpers.cs +++ b/mcs/class/System.Net.Http/Test/HttpClientTestHelpers.cs @@ -22,7 +22,7 @@ namespace MonoTests.System.Net.Http internal static bool IsSocketsHandler (HttpClientHandler handler) => UsingSocketsHandler; - internal static HttpClient CreateHttpClient () + internal static HttpClient CreateHttpClientWithHttpClientHandler () { return new HttpClient (CreateHttpClientHandler ()); } diff --git a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs index 1b05575a6e6..8853242a6dd 100644 --- a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs +++ b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs @@ -188,9 +188,12 @@ namespace MonoTests.System.Net.Http } [Test] - public void Ctor_Default () +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif + public void Ctor_HttpClientHandler () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); Assert.IsNull (client.BaseAddress, "#1"); Assert.IsNotNull (client.DefaultRequestHeaders, "#2"); // TODO: full check Assert.AreEqual (int.MaxValue, client.MaxResponseContentBufferSize, "#3"); @@ -292,7 +295,7 @@ namespace MonoTests.System.Net.Http [Test] public void Properties () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = new HttpClient (); client.BaseAddress = null; client.MaxResponseContentBufferSize = int.MaxValue; client.Timeout = Timeout.InfiniteTimeSpan; @@ -305,7 +308,7 @@ namespace MonoTests.System.Net.Http [Test] public void Properties_Invalid () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = new HttpClient (); try { client.MaxResponseContentBufferSize = 0; Assert.Fail ("#1"); @@ -446,7 +449,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Default/"); var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result; @@ -496,7 +499,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Version_1_0/"); request.Version = HttpVersion.Version10; var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result; @@ -670,7 +673,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.Add("User-Agent", "MLK Android Phone 1.1.9"); @@ -706,7 +709,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.Add("Host", "customhost"); @@ -741,7 +744,7 @@ namespace MonoTests.System.Net.Http try { try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.TransferEncodingChunked = true; client.GetAsync ($"http://localhost:{port}/Send_Transfer_Encoding_Chunked_Needs_Content/").Wait (); // fails with @@ -783,7 +786,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.TransferEncodingChunked = true; client.GetAsync ($"http://localhost:{port}/Send_Transfer_Encoding_Chunked/").Wait (); @@ -813,7 +816,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.TransferEncoding.Add (new TransferCodingHeaderValue ("chunked2")); var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Transfer_Encoding_Custom/"); @@ -845,7 +848,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Content/"); Assert.IsTrue (request.Headers.TryAddWithoutValidation ("aa", "vv"), "#0"); var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result; @@ -876,7 +879,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.MaxResponseContentBufferSize = 1000; var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Content_MaxResponseContentBufferSize/"); var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result; @@ -902,7 +905,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.MaxResponseContentBufferSize = 1000; var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Content_MaxResponseContentBufferSize_Error/"); @@ -998,7 +1001,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var request = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Complete_Error/"); var response = client.SendAsync (request, HttpCompletionOption.ResponseHeadersRead).Result; @@ -1022,7 +1025,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var r = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Content_Get/"); var response = client.SendAsync (r).Result; @@ -1050,7 +1053,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var r = new HttpRequestMessage (HttpMethod.Get, $"http://localhost:{port}/Send_Content_BomEncoding/"); var response = client.SendAsync (r).Result; @@ -1076,7 +1079,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var r = new HttpRequestMessage (HttpMethod.Put, $"http://localhost:{port}/Send_Content_Put/"); r.Content = new StringContent ("my text"); var response = client.SendAsync (r).Result; @@ -1141,9 +1144,12 @@ namespace MonoTests.System.Net.Http } [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif public void Send_Invalid () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); try { client.SendAsync (null).Wait (WaitTimeout); Assert.Fail ("#1"); @@ -1237,7 +1243,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); client.DefaultRequestHeaders.TransferEncodingChunked = true; @@ -1291,7 +1297,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var imageContent = new StreamContent (new MemoryStream ()); @@ -1326,7 +1332,7 @@ namespace MonoTests.System.Net.Http AddListenerContext (listener, context); // add another request handler for the second request try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); var t1 = client.GetStringAsync ($"http://localhost:{port}/GetString_Many/"); var t2 = client.GetStringAsync ($"http://localhost:{port}/GetString_Many/"); Assert.IsTrue (Task.WaitAll (new [] { t1, t2 }, WaitTimeout)); @@ -1352,7 +1358,7 @@ namespace MonoTests.System.Net.Http }); try { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler (); try { client.GetByteArrayAsync ($"http://localhost:{port}/GetByteArray_ServerError/").Wait (WaitTimeout); Assert.Fail ("#1"); @@ -1511,7 +1517,7 @@ namespace MonoTests.System.Net.Http Assert.Ignore ("Throws System.NullReferenceException"); try { - using (var client = HttpClientTestHelpers.CreateHttpClient ()) { + using (var client = HttpClientTestHelpers.CreateHttpClientWithHttpClientHandler ()) { client.GetAsync ("http://255.255.255.255").Wait (WaitTimeout); } } catch (AggregateException e) { diff --git a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpRequestMessageTest.cs b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpRequestMessageTest.cs index e0cbfd2c823..735fe2919dd 100644 --- a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpRequestMessageTest.cs +++ b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpRequestMessageTest.cs @@ -95,7 +95,7 @@ namespace MonoTests.System.Net.Http [Test] public void Ctor_RelativeUri () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = new HttpClient (); client.BaseAddress = new Uri ("http://en.wikipedia.org/wiki/"); var uri = new Uri ("Computer", UriKind.Relative); var req = new HttpRequestMessage (HttpMethod.Get, uri); @@ -120,7 +120,7 @@ namespace MonoTests.System.Net.Http [Test] public void Ctor_RelativeUriString () { - var client = HttpClientTestHelpers.CreateHttpClient (); + var client = new HttpClient (); client.BaseAddress = new Uri ("http://en.wikipedia.org/wiki/"); var req = new HttpRequestMessage (HttpMethod.Get, "Computer"); // HttpRequestMessage does not rewrite it here. |