2 // ServicePointManagerTest.cs - NUnit Test Cases for System.Net.ServicePointManager
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
8 // (C) 2003 Martin Willemoes Hansen
11 using NUnit
.Framework
;
13 using System
.Collections
;
16 using System
.Threading
;
18 namespace MonoTests
.System
.Net
22 public class ServicePointManagerTest
24 private Uri googleUri
;
26 private Uri apacheUri
;
30 public void GetReady ()
32 #if !FEATURE_NO_BSD_SOCKETS
33 maxIdle
= ServicePointManager
.MaxServicePointIdleTime
;
34 ServicePointManager
.MaxServicePointIdleTime
= 10;
36 googleUri
= new Uri ("http://www.google.com");
37 yahooUri
= new Uri ("http://www.yahoo.com");
38 apacheUri
= new Uri ("http://www.apache.org");
44 #if !FEATURE_NO_BSD_SOCKETS
45 ServicePointManager
.MaxServicePointIdleTime
= maxIdle
;
49 [Test
, ExpectedException (typeof (InvalidOperationException
))]
50 [Category ("NotWorking")]
51 public void MaxServicePointManagers ()
53 Assert
.AreEqual (0, ServicePointManager
.MaxServicePoints
, "#1");
55 DoWebRequest (googleUri
);
57 DoWebRequest (yahooUri
);
59 DoWebRequest (apacheUri
);
62 ServicePoint sp
= ServicePointManager
.FindServicePoint (googleUri
);
63 //WriteServicePoint (sp);
64 sp
= ServicePointManager
.FindServicePoint (yahooUri
);
65 //WriteServicePoint (sp);
66 sp
= ServicePointManager
.FindServicePoint (apacheUri
);
67 //WriteServicePoint (sp);
69 ServicePointManager
.MaxServicePoints
= 1;
71 sp
= ServicePointManager
.FindServicePoint (googleUri
);
72 //WriteServicePoint (sp);
73 sp
= ServicePointManager
.FindServicePoint (yahooUri
);
74 //WriteServicePoint (sp);
75 sp
= ServicePointManager
.FindServicePoint (apacheUri
);
76 //WriteServicePoint (sp);
80 // hmm... aparently ms.net still has the service points even
81 // though I set it to a max of 1.
83 // this should force an exception then...
84 sp
= ServicePointManager
.FindServicePoint (new Uri ("http://www.microsoft.com"));
85 //WriteServicePoint (sp);
89 #if FEATURE_NO_BSD_SOCKETS
90 [ExpectedException (typeof (PlatformNotSupportedException
))]
92 public void FindServicePoint ()
94 ServicePointManager
.MaxServicePoints
= 0;
95 ServicePoint sp
= ServicePointManager
.FindServicePoint (googleUri
, new WebProxy (apacheUri
));
96 Assert
.AreEqual (apacheUri
, sp
.Address
, "#1");
98 Assert
.AreEqual (10, sp
.ConnectionLimit
, "#2");
100 Assert
.AreEqual (2, sp
.ConnectionLimit
, "#2");
102 Assert
.AreEqual ("http", sp
.ConnectionName
, "#3");
105 private void DoWebRequest (Uri uri
)
107 WebRequest
.Create (uri
).GetResponse ().Close ();
110 /* Unused code for now, but might be useful later for debugging
111 private void WriteServicePoint (ServicePoint sp)
113 Console.WriteLine ("\nAddress: " + sp.Address);
114 Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);
115 Console.WriteLine ("ConnectionName: " + sp.ConnectionName);
116 Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);
117 Console.WriteLine ("IdleSince: " + sp.IdleSince);
118 Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);
119 Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);
120 Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);