[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono.git] / mcs / class / System / Test / System.Net / HttpListener2Test.cs
index 77fb73e3f00ed1404dbe81fe1a68294f5d7068a2..51e2990c0d18129f63dc2a748c8aa79707e1f4fa 100644 (file)
@@ -146,6 +146,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test1 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -154,10 +157,13 @@ namespace MonoTests.System.Net {
                        Send (ns, "GET / HTTP/1.1\r\n\r\n"); // No host
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 400", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 400"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test2 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -166,10 +172,13 @@ namespace MonoTests.System.Net {
                        Send (ns, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"); // no prefix
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 400", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 400"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test3 ()
                {
                        StringBuilder bad = new StringBuilder ();
@@ -204,11 +213,14 @@ namespace MonoTests.System.Net {
                                string response = Receive (ns, 512);
                                ns.Close ();
                                listener.Close ();
-                               StringAssert.StartsWith ("HTTP/1.1 400", response, String.Format ("Failed on {0}", (int) b));
+                               Assert.IsTrue(response.StartsWith ("HTTP/1.1 400"), String.Format ("Failed on {0}", (int) b));
                        }
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test4 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -217,10 +229,13 @@ namespace MonoTests.System.Net {
                        Send (ns, "POST /test4/ HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"); // length required
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 411", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 411"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test5 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -229,10 +244,13 @@ namespace MonoTests.System.Net {
                        Send (ns, "POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: pepe\r\n\r\n"); // not implemented
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 501", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 501"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test6 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -242,10 +260,13 @@ namespace MonoTests.System.Net {
                        Send (ns, "POST /test6/ HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: identity\r\n\r\n");
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 501", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 501"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test7 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -257,11 +278,14 @@ namespace MonoTests.System.Net {
                        ctx.Response.Close ();
                        string response = Receive (ns, 1024);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 200", response);
-                       StringAssert.Contains ("Transfer-Encoding: chunked", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 200"));
+                       Assert.IsTrue(response.Contains ("Transfer-Encoding: chunked"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test8 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -274,11 +298,14 @@ namespace MonoTests.System.Net {
                        ctx.Response.Close ();
                        string response = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 200", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 200"));
                        Assert.IsTrue (-1 == response.IndexOf ("Transfer-Encoding: chunked"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test9 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -290,10 +317,13 @@ namespace MonoTests.System.Net {
                        string response = ReceiveWithTimeout (ns, 512, 1000, out timeout);
                        ns.Close ();
                        Assert.IsFalse (timeout);
-                       StringAssert.StartsWith ("HTTP/1.1 411", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 411"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test10 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -306,10 +336,13 @@ namespace MonoTests.System.Net {
                        string response = ReceiveWithTimeout (ns, 512, 1000, out timeout);
                        ns.Close ();
                        Assert.IsFalse (timeout);
-                       StringAssert.StartsWith ("HTTP/1.1 411", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 411"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test11 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -320,10 +353,13 @@ namespace MonoTests.System.Net {
                        ns.GetSocket ().Shutdown (SocketShutdown.Send);
                        string input = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 400", input);
+                       Assert.IsTrue(input.StartsWith ("HTTP/1.1 400"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test12 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -334,10 +370,13 @@ namespace MonoTests.System.Net {
                        ns.GetSocket ().Shutdown (SocketShutdown.Send);
                        string input = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 400", input);
+                       Assert.IsTrue(input.StartsWith ("HTTP/1.1 400"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test13 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -348,13 +387,16 @@ namespace MonoTests.System.Net {
                        ns.GetSocket ().Shutdown (SocketShutdown.Send);
                        string input = Receive (ns, 512);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 400", input);
+                       Assert.IsTrue(input.StartsWith ("HTTP/1.1 400"));
                }
 
                HttpListenerRequest test14_request;
                ManualResetEvent test_evt;
                bool test14_error;
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test14 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -391,6 +433,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test15 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -413,6 +458,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test16 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -437,6 +485,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test17 ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -448,11 +499,14 @@ namespace MonoTests.System.Net {
                        ctx.Response.Close ();
                        string response = Receive (ns, 1024);
                        ns.Close ();
-                       StringAssert.StartsWith ("HTTP/1.1 200", response);
-                       StringAssert.Contains ("Transfer-Encoding: chunked", response);
+                       Assert.IsTrue(response.StartsWith ("HTTP/1.1 200"));
+                       Assert.IsTrue(response.Contains ("Transfer-Encoding: chunked"));
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test_MultipleClosesOnOuputStreamAllowed ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -483,6 +537,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void ReceiveCookiesFromClient ()
                {
                        sendCookiePort = NetworkHelpers.FindFreePort ();                        
@@ -529,6 +586,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void SendCookiestoClient ()
                {
                        receiveCookiePort = NetworkHelpers.FindFreePort ();
@@ -580,6 +640,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void MultiResponses ()
                {
                        echoServerPort = NetworkHelpers.FindFreePort ();
@@ -647,6 +710,9 @@ namespace MonoTests.System.Net {
        [TestFixture]
        public class HttpListenerBugs {
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void TestNonChunkedAsync ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -701,6 +767,9 @@ namespace MonoTests.System.Net {
                // a documented pattern to close the connection
                // 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test_MultipleConnections ()
                {
                        var port = NetworkHelpers.FindFreePort ();                      
@@ -731,6 +800,9 @@ namespace MonoTests.System.Net {
                // Test case for bug 341443, an pretty old bug, filed on November of 2007.
                //
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test_HostInUri ()
                {
                        var wait = new ManualResetEvent (false);
@@ -760,6 +832,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test] // bug #513849
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void ClosePort ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -783,6 +858,9 @@ namespace MonoTests.System.Net {
                // does not also listen to another interface.
                //
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void BindToSingleInterface ()
                {
                        IPAddress [] machineAddress = null;
@@ -809,6 +887,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void BindToAllInterfaces ()
                {
                        var h = new HttpListener ();
@@ -821,6 +902,9 @@ namespace MonoTests.System.Net {
 
                // Test case for bug #31209
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Test_EmptyLineAtStart ()
                {
                        var port = NetworkHelpers.FindFreePort ();