[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono.git] / mcs / class / System / Test / System.Net.WebSockets / ClientWebSocketTest.cs
index 6ac81723d256323574d1fe207424f04c333676b0..e3dd58188c17358fe03c97bac68aaed04f105ef7 100644 (file)
@@ -1,4 +1,3 @@
-#if NET_4_5
 using System;
 using System.Net;
 using System.Threading;
@@ -10,43 +9,47 @@ using System.Text;
 
 using NUnit.Framework;
 
+using MonoTests.Helpers;
 
 namespace MonoTests.System.Net.WebSockets
 {
        [TestFixture]
        public class ClientWebSocketTest
        {
-               const string EchoServerUrl = "ws://echo.websocket.org";
-               const int Port = 42123;
-               HttpListener listener;
-               ClientWebSocket socket;
-               MethodInfo headerSetMethod;
-
-               [SetUp]
-               public void Setup ()
-               {
-                       listener = new HttpListener ();
-                       listener.Prefixes.Add ("http://localhost:" + Port + "/");
-                       listener.Start ();
-                       socket = new ClientWebSocket ();
+               const string EchoServerUrl = "ws://corefx-net.cloudapp.net/WebSocket/EchoWebSocket.ashx";
+               int Port = NetworkHelpers.FindFreePort ();
+               HttpListener _listener;
+               HttpListener listener {
+                       get {
+                               if (_listener != null)
+                                       return _listener;
+                               var tmp = new HttpListener ();
+                               tmp.Prefixes.Add ("http://localhost:" + Port + "/");
+                               tmp.Start ();
+                               return _listener = tmp;
+                       }
                }
+               ClientWebSocket _socket;
+               ClientWebSocket socket { get { return _socket ?? (_socket = new ClientWebSocket ()); } }
+               MethodInfo headerSetMethod;
 
                [TearDown]
                public void Teardown ()
                {
-                       if (listener != null) {
-                               listener.Stop ();
-                               listener = null;
+                       if (_listener != null) {
+                               _listener.Stop ();
+                               _listener = null;
                        }
-                       if (socket != null) {
-                               if (socket.State == WebSocketState.Open)
-                                       socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (2000);
-                               socket.Dispose ();
-                               socket = null;
+                       if (_socket != null) {
+                               if (_socket.State == WebSocketState.Open)
+                                       _socket.CloseAsync (WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).Wait (2000);
+                               _socket.Dispose ();
+                               _socket = null;
                        }
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void ServerHandshakeReturnCrapStatusCodeTest ()
                {
                        // On purpose, 
@@ -63,6 +66,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void ServerHandshakeReturnWrongUpgradeHeader ()
                {
                        #pragma warning disable 4014
@@ -81,6 +85,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void ServerHandshakeReturnWrongConnectionHeader ()
                {
                        #pragma warning disable 4014
@@ -101,7 +106,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
-               [Ignore ("See bug #24340")]
+               [Category ("MobileNotWorking")] // The test hangs when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void EchoTest ()
                {
                        const string Payload = "This is a websocket test";
@@ -126,7 +131,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
-               [Ignore ("See bug #24340")]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void CloseOutputAsyncTest ()
                {
                        Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
@@ -143,6 +148,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void CloseAsyncTest ()
                {
                        Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
@@ -159,6 +165,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test, ExpectedException (typeof (ArgumentNullException))]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void SendAsyncArgTest_NoArray ()
                {
                        Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
@@ -172,6 +179,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test, ExpectedException (typeof (ArgumentNullException))]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void ReceiveAsyncArgTest_NoArray ()
                {
                        Assert.IsTrue (socket.ConnectAsync (new Uri (EchoServerUrl), CancellationToken.None).Wait (5000));
@@ -179,6 +187,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void ReceiveAsyncWrongState_Closed ()
                {
                        try {
@@ -193,6 +202,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void SendAsyncWrongState_Closed ()
                {
                        try {
@@ -207,6 +217,7 @@ namespace MonoTests.System.Net.WebSockets
                }
 
                [Test]
+               [Category ("MobileNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
                public void SendAsyncWrongState_CloseSent ()
                {
                        try {
@@ -287,4 +298,3 @@ namespace MonoTests.System.Net.WebSockets
        }
 }
 
-#endif