[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono.git] / mcs / class / System / Test / System.Net / HttpListenerTest.cs
index 70dcede89717281e238f732afa91b55935082777..bbd716c0ed267f6c00aeb6956e16cbc354b1bb51 100644 (file)
@@ -37,17 +37,17 @@ using MonoTests.Helpers;
 
 namespace MonoTests.System.Net {
        [TestFixture]
-       [Category ("RequiresBSDSockets")]
        public class HttpListenerTest {
 
-               int port;
-
-               [SetUp]
-               public void SetUp () {
-                       port = NetworkHelpers.FindFreePort ();
+               int? _port;
+               int port {
+                       get { return _port ?? (_port = NetworkHelpers.FindFreePort ()).Value; }
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void DefaultProperties ()
                {
                        HttpListener listener = new HttpListener ();
@@ -61,6 +61,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Start1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -68,6 +71,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Stop1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -75,7 +81,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (InvalidOperationException))]
+#endif
                public void GetContext1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -84,7 +94,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (InvalidOperationException))]
+#endif
                public void GetContext2 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -94,7 +108,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (InvalidOperationException))]
+#endif
                public void BeginGetContext1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -103,6 +121,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void BeginGetContext2 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -135,6 +156,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void DefaultHttpPort ()
                {
                        if (!CanOpenPort (80))
@@ -148,6 +172,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void DefaultHttpsPort ()
                {
                        if (!CanOpenPort (443))
@@ -161,6 +188,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void TwoListeners_SameAddress ()
                {
                        if (!CanOpenPort (port))
@@ -174,7 +204,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (HttpListenerException))]
+#endif
                public void TwoListeners_SameURL ()
                {
                        if (!CanOpenPort (port))
@@ -188,7 +222,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (HttpListenerException))]
+#endif
                public void MultipleSlashes ()
                {
                        if (!CanOpenPort (port))
@@ -200,7 +238,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (HttpListenerException))]
+#endif
                public void PercentSign ()
                {
                        if (!CanOpenPort (port))
@@ -212,6 +254,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void CloseBeforeStart ()
                {
                        HttpListener listener = new HttpListener ();
@@ -219,6 +264,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void CloseTwice ()
                {
                        if (!CanOpenPort (port))
@@ -231,6 +279,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void StartStopStart ()
                {
                        if (!CanOpenPort (port))
@@ -244,6 +295,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void StartStopDispose ()
                {
                        if (!CanOpenPort (port))
@@ -256,6 +310,9 @@ namespace MonoTests.System.Net {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void AbortBeforeStart ()
                {
                        HttpListener listener = new HttpListener ();
@@ -263,6 +320,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void AbortTwice ()
                {
                        if (!CanOpenPort (port))
@@ -275,6 +335,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void PropertiesWhenClosed1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -288,7 +351,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosed2 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -297,7 +364,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosedSet1 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -306,7 +377,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosedSet2 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -315,7 +390,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosedSet3 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -324,7 +403,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosedSet4 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -333,7 +416,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (ObjectDisposedException))]
+#endif
                public void PropertiesWhenClosedSet5 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -342,6 +429,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void PropertiesWhenClosed3 ()
                {
                        HttpListener listener = new HttpListener ();
@@ -350,6 +440,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void CloseWhileBegin ()
                {
                        HttpListener listener = new HttpListener ();
@@ -366,6 +459,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void AbortWhileBegin ()
                {
                        HttpListener listener = new HttpListener ();
@@ -382,7 +478,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (HttpListenerException))]
+#endif
                public void CloseWhileGet ()
                {
                        // "System.Net.HttpListener Exception : The I/O operation has been aborted
@@ -399,7 +499,11 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof (HttpListenerException))]
+#endif
                public void AbortWhileGet ()
                {
                        // "System.Net.HttpListener Exception : The I/O operation has been aborted
@@ -479,6 +583,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void ConnectionReuse ()
                {
                        var uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
@@ -536,6 +643,9 @@ namespace MonoTests.System.Net {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void UserHeaderWithDoubleMultiValue ()
                {
                        string uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
@@ -563,6 +673,9 @@ namespace MonoTests.System.Net {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void HttpClientIsDisconnectedCheckForWriteException()
                {
                        string uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";