[bcl] Fix a few hardcoded socket ports in tests (#5471)
[mono.git] / mcs / class / System / Test / System.Net.Sockets / TcpClientTest.cs
index 91b461487eb0cc38526671ac56a1ca34797fc8fa..d827ae4de367cc074666e49c3a182b7ad4148c52 100644 (file)
@@ -29,6 +29,9 @@ namespace MonoTests.System.Net.Sockets
                /// (from System.Net.Sockets)
                /// </summary>
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void TcpClient()
                {
                        // set up a listening Socket
@@ -76,6 +79,9 @@ namespace MonoTests.System.Net.Sockets
                }
 
                [Test] // bug #81105
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void CloseTest ()
                {
                        var port = NetworkHelpers.FindFreePort ();
@@ -139,16 +145,23 @@ namespace MonoTests.System.Net.Sockets
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof(ArgumentNullException))]
+#endif
                public void ConnectMultiNull ()
                {
                        TcpClient client = new TcpClient ();
                        IPAddress[] ipAddresses = null;
                        
-                       client.Connect (ipAddresses, 1234);
+                       client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void ConnectMultiAny ()
                {
                        TcpClient client = new TcpClient ();
@@ -157,7 +170,7 @@ namespace MonoTests.System.Net.Sockets
                        ipAddresses[0] = IPAddress.Any;
                        
                        try {
-                               client.Connect (ipAddresses, 1234);
+                               client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                                Assert.Fail ("ConnectMultiAny #1");
                        } catch (SocketException ex) {
                                Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2");
@@ -167,6 +180,9 @@ namespace MonoTests.System.Net.Sockets
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void ConnectMultiRefused ()
                {
                        TcpClient client = new TcpClient ();
@@ -175,7 +191,7 @@ namespace MonoTests.System.Net.Sockets
                        ipAddresses[0] = IPAddress.Loopback;
                        
                        try {
-                               client.Connect (ipAddresses, 1234);
+                               client.Connect (ipAddresses, NetworkHelpers.FindFreePort ());
                                Assert.Fail ("ConnectMultiRefused #1");
                        } catch (SocketException ex) {
                                Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiRefused #2");
@@ -183,5 +199,16 @@ namespace MonoTests.System.Net.Sockets
                                Assert.Fail ("ConnectMultiRefused #3");
                        }
                }
+
+               [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+               public void ExclusiveAddressUse ()
+               {
+                       using (TcpClient client = new TcpClient ()) {
+                               client.ExclusiveAddressUse = false;
+                       }
+               }
        }
 }