**** Merged from MCS ****
[mono-project.git] / mcs / class / System / Test / System.Net / ServicePointManagerTest.cs
blob669d1702a0d9d1853d63a027f68aa7eb8a6e41d5
1 //
2 // ServicePointManagerTest.cs - NUnit Test Cases for System.Net.ServicePointManager
3 //
4 // Authors:
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 //
8 // (C) 2003 Martin Willemoes Hansen
9 //
11 using NUnit.Framework;
12 using System;
13 using System.Collections;
14 using System.IO;
15 using System.Net;
16 using System.Threading;
18 namespace MonoTests.System.Net
21 [TestFixture]
22 public class ServicePointManagerTest : Assertion
24 private Uri googleUri;
25 private Uri yahooUri;
26 private Uri apacheUri;
28 [SetUp]
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);
42 Thread.Sleep (100);
43 DoWebRequest (yahooUri);
44 Thread.Sleep (100);
45 DoWebRequest (apacheUri);
46 Thread.Sleep (100);
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);
64 GC.Collect ();
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);
74 [Test]
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);