[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono.git] / mcs / class / System / Test / System.Net / ServicePointTest.cs
index 63a6b3e52b3e2ffd2c27acab0f8c8e547e035ddc..1e848148f92c21783688163be5f07e1fcb669a87 100644 (file)
@@ -13,7 +13,7 @@ using System;
 using System.Collections;\r
 using System.IO;\r
 using System.Net;\r
-using System.Reflection;
+using System.Reflection;\r
 using System.Threading;\r
 \r
 namespace MonoTests.System.Net\r
@@ -54,13 +54,13 @@ public class ServicePointTest
                HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
                HttpWebResponse res = (HttpWebResponse) req.GetResponse ();                     \r
                \r
-#if FOUND_SOME_OTHER_URL
-               // URL is no longer found, disabled the test until a more reliable URL is found :P
+#if FOUND_SOME_OTHER_URL\r
+               // URL is no longer found, disabled the test until a more reliable URL is found :P\r
                //WriteServicePoint ("google after getting a response", google);\r
                ServicePoint google2 = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com/dilbert.html"));\r
                Assert.AreEqual (google, google2, "#equals");\r
                res.Close ();\r
-#endif
+#endif\r
                \r
                // in both instances property CurrentConnections is 0 according to ms.net.\r
                // let's see what it says when we do async operations...\r
@@ -87,8 +87,8 @@ public class ServicePointTest
                //Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
                res2.Close ();\r
                \r
-               ServicePoint sp2;
-#if FOUND_SOME_OTHER_URL
+               ServicePoint sp2;\r
+#if FOUND_SOME_OTHER_URL\r
                // unless of course some buffering is taking place.. let's check\r
                Uri uri2 = new Uri ("http://freedesktop.org/Software/pkgconfig/releases/pkgconfig-0.15.0.tar.gz");\r
                sp2 = ServicePointManager.FindServicePoint (uri2);\r
@@ -102,7 +102,7 @@ public class ServicePointTest
                // and so it shows\r
                //Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
                res2.Close ();\r
-#endif
+#endif\r
                \r
                \r
                // what's the limit of the cache?\r
@@ -154,7 +154,7 @@ public class ServicePointTest
 \r
        [Test]\r
        [Category ("InetAccess")]\r
-       [Category ("AndroidNotWorking")] // #A1 fails
+       [Category ("AndroidNotWorking")] // #A1 fails\r
        public void EndPointBind ()\r
        {\r
                Uri uri = new Uri ("http://www.go-mono.com/");\r
@@ -189,6 +189,10 @@ public class ServicePointTest
        }\r
 \r
        [Test] //Covers #19823\r
+#if FEATURE_NO_BSD_SOCKETS\r
+       // This test uses HttpWebRequest\r
+       [ExpectedException (typeof (PlatformNotSupportedException))]\r
+#endif\r
        public void CloseConnectionGroupConcurency ()\r
        {\r
                // Try with multiple service points\r
@@ -206,36 +210,37 @@ public class ServicePointTest
                }\r
        }\r
 \r
-
-       [Test]
-       public void DnsRefreshTimeout ()
-       {
-               const int dnsRefreshTimeout = 2000;
-
-               ServicePoint sp;
-               IPHostEntry host0, host1, host2;
-               Uri uri;
-               PropertyInfo hostEntryProperty;
-
-               ServicePointManager.DnsRefreshTimeout = dnsRefreshTimeout;
-
-               uri = new Uri ("http://www.google.com/");
-               sp = ServicePointManager.FindServicePoint (uri);
-
-               hostEntryProperty = typeof (ServicePoint).GetProperty ("HostEntry", BindingFlags.NonPublic | BindingFlags.Instance);
-
-               host0 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
-               host1 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
-
-               Assert.AreSame (host0, host1, "HostEntry should result in the same IPHostEntry object.");
-
-               Thread.Sleep (dnsRefreshTimeout * 2);
-               host2 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;
-
-               Assert.AreNotSame(host0, host2, "HostEntry should result in a new IPHostEntry " +
-                               "object when DnsRefreshTimeout is reached.");
-       }
-
+\r
+       [Test]\r
+       [Category ("RequiresBSDSockets")] // Tests internals, so it doesn't make sense to assert that PlatformNotSupportedExceptions are thrown.\r
+       public void DnsRefreshTimeout ()\r
+       {\r
+               const int dnsRefreshTimeout = 2000;\r
+\r
+               ServicePoint sp;\r
+               IPHostEntry host0, host1, host2;\r
+               Uri uri;\r
+               PropertyInfo hostEntryProperty;\r
+\r
+               ServicePointManager.DnsRefreshTimeout = dnsRefreshTimeout;\r
+\r
+               uri = new Uri ("http://localhost/");\r
+               sp = ServicePointManager.FindServicePoint (uri);\r
+\r
+               hostEntryProperty = typeof (ServicePoint).GetProperty ("HostEntry", BindingFlags.NonPublic | BindingFlags.Instance);\r
+\r
+               host0 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+               host1 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+\r
+               Assert.AreSame (host0, host1, "HostEntry should result in the same IPHostEntry object.");\r
+\r
+               Thread.Sleep (dnsRefreshTimeout * 2);\r
+               host2 = hostEntryProperty.GetValue (sp, null) as IPHostEntry;\r
+\r
+               Assert.AreNotSame(host0, host2, "HostEntry should result in a new IPHostEntry " +\r
+                               "object when DnsRefreshTimeout is reached.");\r
+       }\r
+\r
 // Debug code not used now, but could be useful later\r
 /*\r
        private void WriteServicePoint (string label, ServicePoint sp)\r