[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono.git] / mcs / class / System / Test / System.Net.Sockets / UdpClientTest.cs
index 51c3ac795b52decb800db45596cb972571e9f4d2..996da16f5cc0009ee0b3a56b4e6334812ba89508 100644 (file)
@@ -9,6 +9,7 @@ using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+using System.Threading.Tasks;
 
 using NUnit.Framework;
 
@@ -16,6 +17,9 @@ namespace MonoTests.System.Net.Sockets {
        [TestFixture]
        public class UdpClientTest {
                [Test] // .ctor ()
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor1 ()
                {
                        MyUdpClient client;
@@ -26,25 +30,24 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.IsNotNull (s, "Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "Client:SocketType");
                        Assert.IsFalse (client.Active, "Active");
-#if NET_2_0
                        Assert.IsFalse (client.DontFragment, "DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "Ttl");
-#endif
                        client.Close ();
                }
 
                [Test] // .ctor (AddressFamily)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor2 ()
                {
                        MyUdpClient client;
@@ -55,27 +58,19 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.IsNotNull (s, "#A:Client");
                        Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "#A:Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "#A:Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                        Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                        //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
 
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        client = new MyUdpClient (AddressFamily.InterNetworkV6);
@@ -83,25 +78,24 @@ namespace MonoTests.System.Net.Sockets {
                        Assert.IsNotNull (s, "#B:Client");
                        Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
                        Assert.IsFalse (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                        Assert.IsFalse (s.IsBound, "#A:Client:IsBound");
-#endif
                        Assert.IsNull (s.LocalEndPoint, "#B:Client:LocalEndPoint");
                        Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                        Assert.IsNull (s.RemoteEndPoint, "#B:Client:RemoteEndPoint");
                        Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                        Assert.IsFalse (client.Active, "#B:Active");
-#if NET_2_0
                        //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                        Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                        //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                        Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                        //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                        client.Close ();
                }
 
                [Test] // .ctor (AddressFamily)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor2_Family_Invalid ()
                {
                        try {
@@ -110,15 +104,10 @@ namespace MonoTests.System.Net.Sockets {
                        } catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.AreEqual ("family", ex.ParamName, "#A5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#A4");
-                               Assert.IsNull (ex.ParamName, "#A5");
-#endif
                        }
 
                        try {
@@ -127,17 +116,15 @@ namespace MonoTests.System.Net.Sockets {
                        } catch (ArgumentException ex) {
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
-#if NET_2_0
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.AreEqual ("family", ex.ParamName, "#B5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#B4");
-                               Assert.IsNull (ex.ParamName, "#B5");
-#endif
                        }
                }
 
                [Test] // .ctor (Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor3 ()
                {
                        Socket s;
@@ -149,19 +136,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-       #if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-       #endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-       #if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-       #endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
@@ -173,19 +156,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#B:Client:Connected");
-       #if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-       #endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsFalse (client.Active, "#B:Active");
-       #if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-       #endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -195,6 +174,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor3_Port_OutOfRange ()
                {
                        try {
@@ -221,6 +203,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (IPEndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor4 ()
                {
                        Socket s;
@@ -234,19 +219,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.IsFalse (object.ReferenceEquals (clientEP, localEP), "#A:Client:LocalEndPoint/ReferenceEquality");
@@ -257,6 +238,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (IPEndPoint)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor4_LocalEP_Null ()
                {
                        try {
@@ -271,6 +255,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (Int32, AddressFamily)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor5 ()
                {
                        Socket s;
@@ -282,30 +269,22 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsFalse (client.Active, "#A:Active");
-#if NET_2_0
                                //Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Any, localEP.Address, "#A:Client:LocalEndPoint/Address");
                                Assert.AreEqual (AddressFamily.InterNetwork, localEP.AddressFamily, "#A:Client:LocalEndPoint/AddressFamily");
                        }
 
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        using (MyUdpClient client = new MyUdpClient (IPEndPoint.MaxPort, AddressFamily.InterNetworkV6))
@@ -314,19 +293,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetworkV6, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsFalse (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsFalse (client.Active, "#B:Active");
-#if NET_2_0
                                //Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                Assert.IsTrue (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.IPv6Any, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -336,6 +311,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (Int32, AddressFamily)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor5_Family_Invalid ()
                {
                        try {
@@ -345,15 +323,10 @@ namespace MonoTests.System.Net.Sockets {
                                // family
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
                                Assert.IsNull (ex.InnerException, "#A3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#A4");
                                Assert.AreEqual ("family", ex.ParamName, "#A5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#A4");
-                               Assert.IsNull (ex.ParamName, "#A5");
-#endif
                        }
 
                        try {
@@ -363,19 +336,17 @@ namespace MonoTests.System.Net.Sockets {
                                // family
                                Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
                                Assert.IsNull (ex.InnerException, "#B3");
-#if NET_2_0
                                // 'UDP' Client can only accept InterNetwork or InterNetworkV6
                                // addresses
                                Assert.IsNotNull (ex.Message, "#B4");
                                Assert.AreEqual ("family", ex.ParamName, "#B5");
-#else
-                               Assert.AreEqual ("family", ex.Message, "#B4");
-                               Assert.IsNull (ex.ParamName, "#B5");
-#endif
                        }
                }
 
                [Test] // .ctor (Int32, AddressFamily)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor5_Port_OutOfRange ()
                {
                        try {
@@ -402,6 +373,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (String, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor6 ()
                {
                        Socket s;
@@ -415,19 +389,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#A:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#A:Client:AddressFamily");
                                Assert.IsTrue (s.Connected, "#A:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#A:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#A:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#A:Client:SocketType");
                                Assert.IsTrue (client.Active, "#A:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#A:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#A:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#A:ExclusiveAddressUse");
                                //Assert.IsFalse (client.MulticastLoopback, "#A:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#A:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#A:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#A:Client:LocalEndPoint/Address");
@@ -439,19 +409,15 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNotNull (s, "#B:Client");
                                Assert.AreEqual (AddressFamily.InterNetwork, s.AddressFamily, "#B:Client:AddressFamily");
                                Assert.IsTrue (s.Connected, "#B:Client:Connected");
-#if NET_2_0
                                Assert.IsTrue (s.IsBound, "#B:Client:IsBound");
-#endif
                                Assert.AreEqual (ProtocolType.Udp, s.ProtocolType, "#B:Client:ProtocolType");
                                Assert.AreEqual (SocketType.Dgram, s.SocketType, "#B:Client:SocketType");
                                Assert.IsTrue (client.Active, "#B:Active");
-#if NET_2_0
                                Assert.IsFalse (client.DontFragment, "#B:DontFragment");
                                Assert.IsFalse (client.EnableBroadcast, "#B:EnableBroadcast");
                                //Assert.IsFalse (client.ExclusiveAddressUse, "#B:ExclusiveAddressUse");
                                //Assert.IsFalse (client.MulticastLoopback, "#B:MulticastLoopback");
                                //Assert.AreEqual (32, client.Ttl, "#B:Ttl");
-#endif
                                localEP = s.LocalEndPoint as IPEndPoint;
                                Assert.IsNotNull (localEP, "#B:Client:LocalEndpoint");
                                Assert.AreEqual (IPAddress.Loopback, localEP.Address, "#B:Client:LocalEndPoint/Address");
@@ -460,6 +426,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (String, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor6_HostName_Null ()
                {
                        try {
@@ -474,6 +443,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // .ctor (String, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Constructor6_Port_OutOfRange ()
                {
                        try {
@@ -500,6 +472,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void UdpClientBroadcastTest () 
                {
                        UdpClient client = new UdpClient ();
@@ -513,6 +488,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup1_IPv4 ()
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
@@ -523,13 +501,12 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup1_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -540,30 +517,28 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup1_MulticastAddr_Null ()
                {
                        using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
                                try {
                                        client.JoinMulticastGroup ((IPAddress) null);
                                        Assert.Fail ("#1");
-#if NET_2_0
                                } catch (ArgumentNullException ex) {
                                        Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
                                        Assert.IsNull (ex.InnerException, "#3");
                                        Assert.IsNotNull (ex.Message, "#4");
                                        Assert.AreEqual ("multicastAddr", ex.ParamName, "#5");
                                }
-#else
-                               } catch (NullReferenceException ex) {
-                                       Assert.AreEqual (typeof (NullReferenceException), ex.GetType (), "#2");
-                                       Assert.IsNull (ex.InnerException, "#3");
-                                       Assert.IsNotNull (ex.Message, "#4");
-                               }
-#endif
                        }
                }
 
                [Test] // JoinMulticastGroup (IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup1_Socket_Closed ()
                {
                        IPAddress mcast_addr = null;
@@ -599,15 +574,16 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
                }
 
                [Test] // JoinMulticastGroup (In32, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup2_IPv4 ()
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
@@ -624,21 +600,18 @@ namespace MonoTests.System.Net.Sockets {
                                        Assert.IsNull (ex.InnerException, "#4");
                                        Assert.IsNotNull (ex.Message, "#5");
                                        Assert.AreEqual (10045, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                        Assert.AreEqual (SocketError.OperationNotSupported, ex.SocketErrorCode, "#7");
-#endif
                                }
                        }
                }
 
                [Test] // JoinMulticastGroup (In32, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup2_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -649,6 +622,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (Int32, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup2_MulticastAddr_Null ()
                {
                        using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
@@ -665,13 +641,12 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (Int32, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup2_Socket_Closed ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = null;
@@ -707,15 +682,16 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
                }
 
                [Test] // JoinMulticastGroup (IPAddress, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup3_IPv4 ()
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
@@ -730,13 +706,12 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup3_IPv6 ()
                {
-#if NET_2_0
                        if (!Socket.OSSupportsIPv6)
-#else
-                       if (!Socket.SupportsIPv6)
-#endif
                                Assert.Ignore ("IPv6 not enabled.");
 
                        IPAddress mcast_addr = IPAddress.Parse ("ff02::1");
@@ -751,6 +726,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup3_MulticastAddr_Null ()
                {
                        using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
@@ -767,6 +745,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, Int32)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup3_Socket_Closed ()
                {
                        IPAddress mcast_addr = null;
@@ -802,16 +783,16 @@ namespace MonoTests.System.Net.Sockets {
                                Assert.IsNull (ex.InnerException, "#4");
                                Assert.IsNotNull (ex.Message, "#5");
                                Assert.AreEqual (10022, ex.NativeErrorCode, "#6");
-#if NET_2_0
                                Assert.AreEqual (SocketError.InvalidArgument, ex.SocketErrorCode, "#7");
-#endif
                        } finally {
                                client.Close ();
                        }
                }
 
-#if NET_2_0
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup4_IPv4 ()
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
@@ -823,6 +804,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup4_IPv6 ()
                {
                        if (!Socket.OSSupportsIPv6)
@@ -849,6 +833,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup4_LocalAddress_Null ()
                {
                        IPAddress mcast_addr = IPAddress.Parse ("224.0.0.23");
@@ -867,6 +854,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup4_MulticastAddr_Null ()
                {
                        using (UdpClient client = new UdpClient (new IPEndPoint (IPAddress.Loopback, 1234))) {
@@ -883,6 +873,9 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test] // JoinMulticastGroup (IPAddress, IPAddress)
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroup4_Socket_Closed ()
                {
                        IPAddress mcast_addr = null;
@@ -927,40 +920,52 @@ namespace MonoTests.System.Net.Sockets {
                }
 
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void CloseInReceive ()
                {
                        UdpClient client = null;
                        var rnd = new Random ();
-                       for (int i = 0; i < 5; i++) {
+                       for (int i = 0, max = 5; i < max; i++) {
                                int port = rnd.Next (1025, 65534);
                                try {
                                        client = new UdpClient (port);
                                        break;
                                } catch (Exception) {
-                                       if (i == 5)
+                                       if (i == max - 1)
                                                throw;
                                }
                        }
 
-                       new Thread(delegate() {
-                               Thread.Sleep(2000);
-                               client.Close();
-                               }).Start();
-
+                       ManualResetEvent ready = new ManualResetEvent (false);
                        bool got_exc = false;
-                       IPEndPoint ep = new IPEndPoint (IPAddress.Any, 0);
-                       try {
-                               client.Receive(ref ep);
-                       } catch (SocketException) {
-                               got_exc = true;
-                       } finally {
-                               client.Close ();
-                       }
+
+                       Task receive_task = Task.Factory.StartNew (() => {
+                               IPEndPoint ep = new IPEndPoint (IPAddress.Any, 0);
+                               try {
+                                       ready.Set ();
+                                       client.Receive(ref ep);
+                               } catch (SocketException) {
+                                       got_exc = true;
+                               } finally {
+                                       client.Close ();
+                               }
+                       });
+
+                       ready.WaitOne (2000);
+                       Thread.Sleep (20);
+                       client.Close();
+
+                       Assert.IsTrue (receive_task.Wait (1000));
                        Assert.IsTrue (got_exc);
                }
 
                // Test for bug 324033
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void JoinMulticastGroupWithLocal ()
                {
                        UdpClient client = new UdpClient (9001);
@@ -975,7 +980,11 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
                [ExpectedException (typeof(ArgumentNullException))]
+#endif
                public void BeginSendNull ()
                {
                        UdpClient client = new UdpClient ();
@@ -998,6 +1007,9 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void BeginSend ()
                {
                        UdpClient client = new UdpClient ();
@@ -1052,6 +1064,9 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void BeginReceive ()
                {
                        UdpClient client = new UdpClient (1237);
@@ -1077,6 +1092,9 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void Available ()
                {
                        using (UdpClient client = new UdpClient (1238)) {
@@ -1111,6 +1129,9 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void EnableBroadcastDefault ()
                {
                        UdpClient client = new UdpClient ();
@@ -1150,6 +1171,9 @@ namespace MonoTests.System.Net.Sockets {
                }
                
                [Test]
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
                public void MulticastLoopbackDefault ()
                {
                        UdpClient client = new UdpClient ();
@@ -1158,9 +1182,31 @@ namespace MonoTests.System.Net.Sockets {
 
                        client.Close ();
                }
+
+               [Test] // #6057
+#if FEATURE_NO_BSD_SOCKETS
+               [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+               public void ReceiveIPv6 ()
+               {
+                       if (!Socket.OSSupportsIPv6)
+                               Assert.Ignore ("IPv6 not enabled.");
+
+                       int PORT = 9997;
+                       using(var udpClient = new UdpClient (PORT, AddressFamily.InterNetworkV6))
+                       using(var udpClient2 = new UdpClient (PORT+1, AddressFamily.InterNetworkV6))
+                       {
+                               var dataSent = new byte [] {1,2,3};
+                               udpClient2.SendAsync (dataSent, dataSent.Length, "::1", PORT);
+
+                               IPEndPoint endPoint = new IPEndPoint (IPAddress.IPv6Any, 0);
+                               var data = udpClient.Receive (ref endPoint);
+
+                               Assert.AreEqual (dataSent.Length, data.Length);
+                       }
+               }
                
                /* No test for Ttl default as it is platform dependent */
-#endif
 
                class MyUdpClient : UdpClient
                {
@@ -1199,12 +1245,6 @@ namespace MonoTests.System.Net.Sockets {
                                set { base.Active = value; }
                        }
 
-#if ONLY_1_1
-                       public new Socket Client {
-                               get { return base.Client; }
-                               set { base.Client = value; }
-                       }
-#endif
                }
        }
 }