2 // ServicePointManagerTest.cs - NUnit Test Cases for System.Net.ServicePointManager
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
\r
8 // (C) 2003 Martin Willemoes Hansen
\r
11 using NUnit.Framework;
\r
13 using System.Collections;
\r
16 using System.Threading;
\r
18 namespace MonoTests.System.Net
\r
22 public class ServicePointManagerTest : Assertion
\r
24 private Uri googleUri;
\r
25 private Uri yahooUri;
\r
26 private Uri apacheUri;
\r
27 private int maxIdle;
\r
30 public void GetReady ()
\r
32 maxIdle = ServicePointManager.MaxServicePointIdleTime;
\r
33 ServicePointManager.MaxServicePointIdleTime = 10;
\r
34 googleUri = new Uri ("http://www.google.com");
\r
35 yahooUri = new Uri ("http://www.yahoo.com");
\r
36 apacheUri = new Uri ("http://www.apache.org");
\r
40 public void Finish ()
\r
42 ServicePointManager.MaxServicePointIdleTime = maxIdle;
\r
45 [Test, ExpectedException (typeof (InvalidOperationException))]
\r
46 [Category ("InetAccess")]
\r
48 [Ignore ("Unsupported property - ServicePointManager.MaxServicePoints")]
\r
50 public void MaxServicePointManagers ()
\r
52 AssertEquals ("#1", 0, ServicePointManager.MaxServicePoints);
\r
54 DoWebRequest (googleUri);
\r
56 DoWebRequest (yahooUri);
\r
58 DoWebRequest (apacheUri);
\r
61 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);
\r
62 //WriteServicePoint (sp);
\r
63 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
64 //WriteServicePoint (sp);
\r
65 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
66 //WriteServicePoint (sp);
\r
68 ServicePointManager.MaxServicePoints = 1;
\r
70 sp = ServicePointManager.FindServicePoint (googleUri);
\r
71 //WriteServicePoint (sp);
\r
72 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
73 //WriteServicePoint (sp);
\r
74 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
75 //WriteServicePoint (sp);
\r
79 // hmm... aparently ms.net still has the service points even
\r
80 // though I set it to a max of 1.
\r
82 // this should force an exception then...
\r
83 sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));
\r
84 //WriteServicePoint (sp);
\r
88 public void FindServicePoint ()
\r
90 ServicePointManager.MaxServicePoints = 0;
\r
91 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));
\r
92 AssertEquals ("#1", apacheUri, sp.Address);
\r
93 AssertEquals ("#2", 2, sp.ConnectionLimit);
\r
94 AssertEquals ("#3", "http", sp.ConnectionName);
\r
97 private void DoWebRequest (Uri uri)
\r
99 WebRequest.Create (uri).GetResponse ().Close ();
\r
102 /* Unused code for now, but might be useful later for debugging
\r
103 private void WriteServicePoint (ServicePoint sp)
\r
105 Console.WriteLine ("\nAddress: " + sp.Address);
\r
106 Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);
\r
107 Console.WriteLine ("ConnectionName: " + sp.ConnectionName);
\r
108 Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);
\r
109 Console.WriteLine ("IdleSince: " + sp.IdleSince);
\r
110 Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);
\r
111 Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);
\r
112 Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);
\r