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
\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
47 public void MaxServicePointManagers ()
\r
49 Assert.AreEqual (0, ServicePointManager.MaxServicePoints, "#1");
\r
51 DoWebRequest (googleUri);
\r
53 DoWebRequest (yahooUri);
\r
55 DoWebRequest (apacheUri);
\r
58 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);
\r
59 //WriteServicePoint (sp);
\r
60 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
61 //WriteServicePoint (sp);
\r
62 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
63 //WriteServicePoint (sp);
\r
65 ServicePointManager.MaxServicePoints = 1;
\r
67 sp = ServicePointManager.FindServicePoint (googleUri);
\r
68 //WriteServicePoint (sp);
\r
69 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
70 //WriteServicePoint (sp);
\r
71 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
72 //WriteServicePoint (sp);
\r
76 // hmm... aparently ms.net still has the service points even
\r
77 // though I set it to a max of 1.
\r
79 // this should force an exception then...
\r
80 sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));
\r
81 //WriteServicePoint (sp);
\r
85 public void FindServicePoint ()
\r
87 ServicePointManager.MaxServicePoints = 0;
\r
88 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));
\r
89 Assert.AreEqual (apacheUri, sp.Address, "#1");
\r
90 #if MOBILE && !MONODROID
\r
91 Assert.AreEqual (10, sp.ConnectionLimit, "#2");
\r
93 Assert.AreEqual (2, sp.ConnectionLimit, "#2");
\r
95 Assert.AreEqual ("http", sp.ConnectionName, "#3");
\r
98 private void DoWebRequest (Uri uri)
\r
100 WebRequest.Create (uri).GetResponse ().Close ();
\r
103 /* Unused code for now, but might be useful later for debugging
\r
104 private void WriteServicePoint (ServicePoint sp)
\r
106 Console.WriteLine ("\nAddress: " + sp.Address);
\r
107 Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);
\r
108 Console.WriteLine ("ConnectionName: " + sp.ConnectionName);
\r
109 Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);
\r
110 Console.WriteLine ("IdleSince: " + sp.IdleSince);
\r
111 Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);
\r
112 Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);
\r
113 Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);
\r