Skip to content

Commit 142a0d5

Browse files
committed
Enable AndroidClientHandler tests without casts
1 parent a7dd119 commit 142a0d5

File tree

1 file changed

+54
-66
lines changed

1 file changed

+54
-66
lines changed

tests/Mono.Android-Tests/Xamarin.Android.Net/AndroidClientHandlerTests.cs

Lines changed: 54 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -70,72 +70,6 @@ public bool IsBypassed (Uri host)
7070
}
7171
}
7272

73-
// [Test]
74-
// public void Properties_Defaults ()
75-
// {
76-
// var obj = CreateHandler ();
77-
// if (obj is not HttpClientHandler h) {
78-
// Assert.Ignore ($"{obj.GetType()} is not a HttpClientHandler.");
79-
// return;
80-
// }
81-
82-
// Assert.IsTrue (h.AllowAutoRedirect, "#1");
83-
// Assert.AreEqual (DecompressionMethods.None, h.AutomaticDecompression, "#2");
84-
// Assert.AreEqual (0, h.CookieContainer.Count, "#3");
85-
// Assert.AreEqual (4096, h.CookieContainer.MaxCookieSize, "#3b");
86-
// Assert.AreEqual (null, h.Credentials, "#4");
87-
// Assert.AreEqual (50, h.MaxAutomaticRedirections, "#5");
88-
// Assert.IsFalse (h.PreAuthenticate, "#7");
89-
// Assert.IsNull (h.Proxy, "#8");
90-
// Assert.IsTrue (h.SupportsAutomaticDecompression, "#9");
91-
// Assert.IsTrue (h.SupportsProxy, "#10");
92-
// Assert.IsTrue (h.SupportsRedirectConfiguration, "#11");
93-
// Assert.IsTrue (h.UseCookies, "#12");
94-
// Assert.IsFalse (h.UseDefaultCredentials, "#13");
95-
// Assert.IsTrue (h.UseProxy, "#14");
96-
// Assert.AreEqual (ClientCertificateOption.Manual, h.ClientCertificateOptions, "#15");
97-
// Assert.IsNull (h.ServerCertificateCustomValidationCallback, "#16");
98-
// }
99-
100-
// [Test]
101-
// public void Properties_Invalid ()
102-
// {
103-
// var obj = CreateHandler ();
104-
// if (obj is not HttpClientHandler h) {
105-
// Assert.Ignore ($"{obj.GetType()} is not a HttpClientHandler.");
106-
// return;
107-
// }
108-
109-
// try {
110-
// h.MaxAutomaticRedirections = 0;
111-
// Assert.Fail ("#1");
112-
// } catch (ArgumentOutOfRangeException) {
113-
// }
114-
115-
// try {
116-
// h.MaxRequestContentBufferSize = -1;
117-
// Assert.Fail ("#2");
118-
// } catch (ArgumentOutOfRangeException) {
119-
// }
120-
// }
121-
122-
// [Test]
123-
// public void Properties_AfterClientCreation ()
124-
// {
125-
// var obj = CreateHandler ();
126-
// if (obj is not HttpClientHandler h) {
127-
// Assert.Ignore ($"{obj.GetType()} is not a HttpClientHandler.");
128-
// return;
129-
// }
130-
131-
// h.AllowAutoRedirect = true;
132-
133-
// // We may modify properties after creating the HttpClient.
134-
// using (var c = new HttpClient (h, true)) {
135-
// h.AllowAutoRedirect = false;
136-
// }
137-
// }
138-
13973
// [Test]
14074
// public void Disposed ()
14175
// {
@@ -415,6 +349,60 @@ protected override HttpMessageHandler CreateHandler ()
415349
{
416350
return new Xamarin.Android.Net.AndroidClientHandler ();
417351
}
352+
353+
[Test]
354+
public void Properties_Defaults ()
355+
{
356+
var h = new Xamarin.Android.Net.AndroidClientHandler ();
357+
358+
Assert.IsTrue (h.AllowAutoRedirect, "#1");
359+
Assert.AreEqual (DecompressionMethods.None, h.AutomaticDecompression, "#2");
360+
Assert.AreEqual (0, h.CookieContainer.Count, "#3");
361+
Assert.AreEqual (4096, h.CookieContainer.MaxCookieSize, "#3b");
362+
Assert.AreEqual (null, h.Credentials, "#4");
363+
Assert.AreEqual (50, h.MaxAutomaticRedirections, "#5");
364+
Assert.IsFalse (h.PreAuthenticate, "#7");
365+
Assert.IsNull (h.Proxy, "#8");
366+
Assert.IsTrue (h.SupportsAutomaticDecompression, "#9");
367+
Assert.IsTrue (h.SupportsProxy, "#10");
368+
Assert.IsTrue (h.SupportsRedirectConfiguration, "#11");
369+
Assert.IsTrue (h.UseCookies, "#12");
370+
Assert.IsFalse (h.UseDefaultCredentials, "#13");
371+
Assert.IsTrue (h.UseProxy, "#14");
372+
Assert.AreEqual (ClientCertificateOption.Manual, h.ClientCertificateOptions, "#15");
373+
Assert.IsNull (h.ServerCertificateCustomValidationCallback, "#16");
374+
}
375+
376+
[Test]
377+
public void Properties_Invalid ()
378+
{
379+
var h = new Xamarin.Android.Net.AndroidClientHandler ();
380+
381+
try {
382+
h.MaxAutomaticRedirections = 0;
383+
Assert.Fail ("#1");
384+
} catch (ArgumentOutOfRangeException) {
385+
}
386+
387+
try {
388+
h.MaxRequestContentBufferSize = -1;
389+
Assert.Fail ("#2");
390+
} catch (ArgumentOutOfRangeException) {
391+
}
392+
}
393+
394+
[Test]
395+
public void Properties_AfterClientCreation ()
396+
{
397+
var h = new Xamarin.Android.Net.AndroidClientHandler ();
398+
399+
h.AllowAutoRedirect = true;
400+
401+
// We may modify properties after creating the HttpClient.
402+
using (var c = new HttpClient (h, true)) {
403+
h.AllowAutoRedirect = false;
404+
}
405+
}
418406
}
419407

420408
[TestFixture]

0 commit comments

Comments
 (0)