Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mcs / class / System / Test / System.Net / ServicePointManagerTest.cs
index 157aee20d42280bb901c04e8e0a2b52f9d458bb5..f0c3272f721ef14a3340283fc4c102accd8cf1b3 100644 (file)
@@ -24,72 +24,83 @@ public class ServicePointManagerTest
        private Uri googleUri;\r
        private Uri yahooUri;\r
        private Uri apacheUri;\r
+       private int maxIdle;\r
        \r
        [SetUp]\r
         public void GetReady () \r
        {\r
+               maxIdle = ServicePointManager.MaxServicePointIdleTime;\r
+               ServicePointManager.MaxServicePointIdleTime = 10;\r
                googleUri = new Uri ("http://www.google.com");\r
                yahooUri = new Uri ("http://www.yahoo.com");\r
                apacheUri = new Uri ("http://www.apache.org");\r
        }\r
 \r
-        [Test]\r
+       [TearDown]\r
+       public void Finish ()\r
+       {\r
+               ServicePointManager.MaxServicePointIdleTime = maxIdle;\r
+       }\r
+\r
+        [Test, ExpectedException (typeof (InvalidOperationException))]\r
+               [Category ("InetAccess")]\r
         public void MaxServicePointManagers ()\r
         {\r
-               try {\r
-                       Assertion.AssertEquals ("#1", 0, ServicePointManager.MaxServicePoints);\r
-                       \r
-                       DoWebRequest (googleUri);\r
-                       Thread.Sleep (100);\r
-                       DoWebRequest (yahooUri);\r
-                       Thread.Sleep (100);\r
-                       DoWebRequest (apacheUri);\r
-                       Thread.Sleep (100);\r
-                       \r
-                       ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);\r
-                       WriteServicePoint (sp);\r
-                       sp = ServicePointManager.FindServicePoint (yahooUri);\r
-                       WriteServicePoint (sp);\r
-                       sp = ServicePointManager.FindServicePoint (apacheUri);\r
-                       WriteServicePoint (sp);\r
-                       \r
-                       ServicePointManager.MaxServicePoints = 1;\r
+               Assert.AreEqual (0, ServicePointManager.MaxServicePoints, "#1");\r
+               \r
+               DoWebRequest (googleUri);\r
+               Thread.Sleep (100);\r
+               DoWebRequest (yahooUri);\r
+               Thread.Sleep (100);\r
+               DoWebRequest (apacheUri);\r
+               Thread.Sleep (100);\r
+               \r
+               ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);\r
+               //WriteServicePoint (sp);\r
+               sp = ServicePointManager.FindServicePoint (yahooUri);\r
+               //WriteServicePoint (sp);\r
+               sp = ServicePointManager.FindServicePoint (apacheUri);\r
+               //WriteServicePoint (sp);\r
+               \r
+               ServicePointManager.MaxServicePoints = 1;\r
 \r
-                       sp = ServicePointManager.FindServicePoint (googleUri);\r
-                       WriteServicePoint (sp);\r
-                       sp = ServicePointManager.FindServicePoint (yahooUri);\r
-                       WriteServicePoint (sp);\r
-                       sp = ServicePointManager.FindServicePoint (apacheUri);\r
-                       WriteServicePoint (sp);\r
-                       \r
-                       GC.Collect ();\r
-                       \r
-                       // hmm... aparently ms.net still has the service points even\r
-                       // though I set it to a max of 1.\r
-                       \r
-                       // this should force an exception then...               \r
-                       sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));\r
-                       WriteServicePoint (sp);\r
-                       \r
-               } catch (Exception e) {\r
-                       Assertion.Fail("The following unexpected Exception was thrown : " + e);\r
-               }\r
+               sp = ServicePointManager.FindServicePoint (googleUri);\r
+               //WriteServicePoint (sp);\r
+               sp = ServicePointManager.FindServicePoint (yahooUri);\r
+               //WriteServicePoint (sp);\r
+               sp = ServicePointManager.FindServicePoint (apacheUri);\r
+               //WriteServicePoint (sp);\r
+               \r
+               GC.Collect ();\r
+               \r
+               // hmm... aparently ms.net still has the service points even\r
+               // though I set it to a max of 1.\r
+               \r
+               // this should force an exception then...               \r
+               sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));\r
+               //WriteServicePoint (sp);\r
        }\r
        \r
         [Test]\r
        public void FindServicePoint ()\r
        {\r
+               ServicePointManager.MaxServicePoints = 0;\r
                ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));\r
-               Assertion.AssertEquals ("#1", apacheUri, sp.Address);\r
-               Assertion.AssertEquals ("#2", 2, sp.ConnectionLimit);\r
-               Assertion.AssertEquals ("#3", "http", sp.ConnectionName);\r
+               Assert.AreEqual (apacheUri, sp.Address, "#1");\r
+#if NET_2_1\r
+               Assert.AreEqual (10, sp.ConnectionLimit, "#2");\r
+#else\r
+               Assert.AreEqual (2, sp.ConnectionLimit, "#2");\r
+#endif\r
+               Assert.AreEqual ("http", sp.ConnectionName, "#3");\r
        }\r
        \r
        private void DoWebRequest (Uri uri)\r
        {\r
                WebRequest.Create (uri).GetResponse ().Close ();\r
        }\r
-       \r
+\r
+/* Unused code for now, but might be useful later for debugging\r
        private void WriteServicePoint (ServicePoint sp)\r
        {\r
                Console.WriteLine ("\nAddress: " + sp.Address);\r
@@ -101,7 +112,8 @@ public class ServicePointManagerTest
                Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);\r
                Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);             \r
        }\r
-}\r
+*/\r
 \r
 }\r
+}\r
 \r