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 #if !FEATURE_NO_BSD_SOCKETS
\r
33 maxIdle = ServicePointManager.MaxServicePointIdleTime;
\r
34 ServicePointManager.MaxServicePointIdleTime = 10;
\r
36 googleUri = new Uri ("http://www.google.com");
\r
37 yahooUri = new Uri ("http://www.yahoo.com");
\r
38 apacheUri = new Uri ("http://www.apache.org");
\r
42 public void Finish ()
\r
44 #if !FEATURE_NO_BSD_SOCKETS
\r
45 ServicePointManager.MaxServicePointIdleTime = maxIdle;
\r
49 [Test, ExpectedException (typeof (InvalidOperationException))]
\r
50 [Category ("InetAccess")]
\r
51 public void MaxServicePointManagers ()
\r
53 Assert.AreEqual (0, ServicePointManager.MaxServicePoints, "#1");
\r
55 DoWebRequest (googleUri);
\r
57 DoWebRequest (yahooUri);
\r
59 DoWebRequest (apacheUri);
\r
62 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);
\r
63 //WriteServicePoint (sp);
\r
64 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
65 //WriteServicePoint (sp);
\r
66 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
67 //WriteServicePoint (sp);
\r
69 ServicePointManager.MaxServicePoints = 1;
\r
71 sp = ServicePointManager.FindServicePoint (googleUri);
\r
72 //WriteServicePoint (sp);
\r
73 sp = ServicePointManager.FindServicePoint (yahooUri);
\r
74 //WriteServicePoint (sp);
\r
75 sp = ServicePointManager.FindServicePoint (apacheUri);
\r
76 //WriteServicePoint (sp);
\r
80 // hmm... aparently ms.net still has the service points even
\r
81 // though I set it to a max of 1.
\r
83 // this should force an exception then...
\r
84 sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));
\r
85 //WriteServicePoint (sp);
\r
89 #if FEATURE_NO_BSD_SOCKETS
\r
90 [ExpectedException (typeof (PlatformNotSupportedException))]
\r
92 public void FindServicePoint ()
\r
94 ServicePointManager.MaxServicePoints = 0;
\r
95 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));
\r
96 Assert.AreEqual (apacheUri, sp.Address, "#1");
\r
97 #if MOBILE && !MONODROID
\r
98 Assert.AreEqual (10, sp.ConnectionLimit, "#2");
\r
100 Assert.AreEqual (2, sp.ConnectionLimit, "#2");
\r
102 Assert.AreEqual ("http", sp.ConnectionName, "#3");
\r
105 private void DoWebRequest (Uri uri)
\r
107 WebRequest.Create (uri).GetResponse ().Close ();
\r
110 /* Unused code for now, but might be useful later for debugging
\r
111 private void WriteServicePoint (ServicePoint sp)
\r
113 Console.WriteLine ("\nAddress: " + sp.Address);
\r
114 Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);
\r
115 Console.WriteLine ("ConnectionName: " + sp.ConnectionName);
\r
116 Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);
\r
117 Console.WriteLine ("IdleSince: " + sp.IdleSince);
\r
118 Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);
\r
119 Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);
\r
120 Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);
\r