Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@ -11,8 +11,10 @@
//
using NUnit.Framework;
using MonoTests.Helpers;
using System;
using System.Net;
using System.Threading;
using System.Collections;
using System.Runtime.Serialization;
using Socks = System.Net.Sockets;
@ -191,6 +193,9 @@ namespace MonoTests.System.Net {
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void All ()
{
WebRequest req = WebRequest.Create ("http://www.contoso.com");
@ -262,6 +267,9 @@ namespace MonoTests.System.Net {
}
[Test]
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void DefaultWebProxy ()
{
WebProxy proxy = new WebProxy ("proxy.intern.com", 83);
@ -316,14 +324,18 @@ namespace MonoTests.System.Net {
}
[Test] //BNC#323452
// Throws exception with Status == Timeout. The same code behaves as the test expects when run from a regular app.
// Might be an issue with the test suite. To investigate.
[Category("AndroidNotWorking")]
// Throws exception with Status == Timeout. The same code behaves as the test expects when run from a regular app.
// Might be an issue with the test suite. To investigate.
[Category("AndroidNotWorking")]
public void TestFailedConnection ()
{
try {
WebRequest.Create ("http://127.0.0.1:0/non-existant.txt").GetResponse ();
Assert.Fail ("Should have raised an exception");
#if FEATURE_NO_BSD_SOCKETS
} catch (PlatformNotSupportedException) {
// Expected
#endif
} catch (Exception e) {
Assert.IsTrue (e is WebException, "Got " + e.GetType ().Name + ": " + e.Message);
//#if NET_2_0 e.Message == "Unable to connect to the remote server"
@ -340,7 +352,7 @@ namespace MonoTests.System.Net {
}
[Test] //BNC#323452
[Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
[Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
public void TestFailedResolution ()
{
try {
@ -357,6 +369,10 @@ namespace MonoTests.System.Net {
Assert.Ignore ("Misbehaving DNS server.");
Assert.Fail ("Should have raised an exception");
#if FEATURE_NO_BSD_SOCKETS
} catch (PlatformNotSupportedException) {
// Expected
#endif
} catch (Exception e) {
Assert.IsTrue (e is WebException);
//#if NET_2_0 e.Message == "The underlying connection was closed: The remote name could not be resolved."
@ -410,6 +426,55 @@ namespace MonoTests.System.Net {
{
internal TestWebRequest3 () { }
}
[Test] // Covers #41477
#if FEATURE_NO_BSD_SOCKETS
[ExpectedException (typeof (PlatformNotSupportedException))]
#endif
public void TestReceiveCancelation ()
{
var uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
HttpListener listener = new HttpListener ();
listener.Prefixes.Add (uri);
listener.Start ();
try {
for (var i = 0; i < 10; i++) {
var request = WebRequest.CreateHttp (uri);
request.Method = "GET";
var tokenSource = new CancellationTokenSource ();
tokenSource.Token.Register(() => request.Abort ());
var responseTask = request.GetResponseAsync ();
var context = listener.GetContext ();
byte[] outBuffer = new byte[8 * 1024];
context.Response.OutputStream.WriteAsync (outBuffer, 0, outBuffer.Length);
Assert.IsTrue (responseTask.Wait (1000), "Timeout #1");
WebResponse response = responseTask.Result;
var stream = response.GetResponseStream ();
byte[] buffer = new byte[8 * 1024];
var taskRead = stream.ReadAsync (buffer, 0, buffer.Length, tokenSource.Token);
tokenSource.Cancel ();
Assert.IsTrue (taskRead.Wait (1000), "Timeout #2");
var byteRead = taskRead.Result;
}
} catch (AggregateException ex) {
var webEx = ex.InnerException as WebException;
Assert.IsNotNull(webEx, "Inner exception is not a WebException");
Assert.AreEqual (webEx.Status, WebExceptionStatus.RequestCanceled);
}
listener.Close ();
}
}
}