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
: Assertion
24 private Uri googleUri
;
26 private Uri apacheUri
;
29 public void GetReady ()
31 googleUri
= new Uri ("http://www.google.com");
32 yahooUri
= new Uri ("http://www.yahoo.com");
33 apacheUri
= new Uri ("http://www.apache.org");
36 [Test
, ExpectedException (typeof (InvalidOperationException
))]
37 public void MaxServicePointManagers ()
39 AssertEquals ("#1", 0, ServicePointManager
.MaxServicePoints
);
41 DoWebRequest (googleUri
);
43 DoWebRequest (yahooUri
);
45 DoWebRequest (apacheUri
);
48 ServicePoint sp
= ServicePointManager
.FindServicePoint (googleUri
);
49 //WriteServicePoint (sp);
50 sp
= ServicePointManager
.FindServicePoint (yahooUri
);
51 //WriteServicePoint (sp);
52 sp
= ServicePointManager
.FindServicePoint (apacheUri
);
53 //WriteServicePoint (sp);
55 ServicePointManager
.MaxServicePoints
= 1;
57 sp
= ServicePointManager
.FindServicePoint (googleUri
);
58 //WriteServicePoint (sp);
59 sp
= ServicePointManager
.FindServicePoint (yahooUri
);
60 //WriteServicePoint (sp);
61 sp
= ServicePointManager
.FindServicePoint (apacheUri
);
62 //WriteServicePoint (sp);
66 // hmm... aparently ms.net still has the service points even
67 // though I set it to a max of 1.
69 // this should force an exception then...
70 sp
= ServicePointManager
.FindServicePoint (new Uri ("http://www.microsoft.com"));
71 //WriteServicePoint (sp);
75 public void FindServicePoint ()
77 ServicePoint sp
= ServicePointManager
.FindServicePoint (googleUri
, new WebProxy (apacheUri
));
78 AssertEquals ("#1", apacheUri
, sp
.Address
);
79 AssertEquals ("#2", 2, sp
.ConnectionLimit
);
80 AssertEquals ("#3", "http", sp
.ConnectionName
);
83 private void DoWebRequest (Uri uri
)
85 WebRequest
.Create (uri
).GetResponse ().Close ();
88 /* Unused code for now, but might be useful later for debugging
89 private void WriteServicePoint (ServicePoint sp)
91 Console.WriteLine ("\nAddress: " + sp.Address);
92 Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);
93 Console.WriteLine ("ConnectionName: " + sp.ConnectionName);
94 Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);
95 Console.WriteLine ("IdleSince: " + sp.IdleSince);
96 Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);
97 Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);
98 Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining);