//\r
// ServicePointManagerTest.cs - NUnit Test Cases for System.Net.ServicePointManager\r
//\r
-// Author:\r
+// Authors:\r
// Lawrence Pit (loz@cable.a2000.nl)\r
+// Martin Willemoes Hansen (mwh@sysrq.dk)\r
+//\r
+// (C) 2003 Martin Willemoes Hansen\r
//\r
\r
using NUnit.Framework;\r
namespace MonoTests.System.Net\r
{\r
\r
-public class ServicePointManagerTest : TestCase\r
+[TestFixture]\r
+public class ServicePointManagerTest : Assertion\r
{\r
private Uri googleUri;\r
private Uri yahooUri;\r
private Uri apacheUri;\r
+ private int maxIdle;\r
\r
- public ServicePointManagerTest () :\r
- base ("[MonoTests.System.Net.ServicePointManagerTest]") {}\r
-\r
- public ServicePointManagerTest (string name) : base (name) {}\r
-\r
- protected override void SetUp () {\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
- protected override void TearDown () {}\r
+ [TearDown]\r
+ public void Finish ()\r
+ {\r
+ ServicePointManager.MaxServicePointIdleTime = maxIdle;\r
+ }\r
\r
- public static ITest Suite\r
+ [Test, ExpectedException (typeof (InvalidOperationException))]\r
+ [Category ("InetAccess")]\r
+#if TARGET_JVM\r
+ [Ignore ("Unsupported property - ServicePointManager.MaxServicePoints")]\r
+#endif\r
+ public void MaxServicePointManagers ()\r
{\r
- get {\r
- return new TestSuite (typeof (ServicePointManagerTest));\r
- }\r
- }\r
- \r
- public void TestMaxServicePointManagers ()\r
- {\r
- try {\r
- 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
+ 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
\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
- Console.WriteLine("\nThe following Exception was raised : {0}", e.Message);\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
- public void TestFindServicePoint ()\r
+ [Test]\r
+ public void FindServicePoint ()\r
{\r
+ ServicePointManager.MaxServicePoints = 0;\r
ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));\r
AssertEquals ("#1", apacheUri, sp.Address);\r
AssertEquals ("#2", 2, sp.ConnectionLimit);\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
Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);\r
Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining); \r
}\r
-}\r
+*/\r
\r
}\r
+}\r
\r