[bcl] Remove the ValueAdd and InetAccess NUnit categories (#2212)
[mono-project.git] / mcs / class / System / Test / System.Net / ServicePointManagerTest.cs
blob2ed577e5df80d09d71c9fbd9e3329c783d40c56f
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
24 private Uri googleUri;
25 private Uri yahooUri;
26 private Uri apacheUri;
27 private int maxIdle;
29 [SetUp]
30 public void GetReady ()
32 #if !FEATURE_NO_BSD_SOCKETS
33 maxIdle = ServicePointManager.MaxServicePointIdleTime;
34 ServicePointManager.MaxServicePointIdleTime = 10;
35 #endif
36 googleUri = new Uri ("http://www.google.com");
37 yahooUri = new Uri ("http://www.yahoo.com");
38 apacheUri = new Uri ("http://www.apache.org");
41 [TearDown]
42 public void Finish ()
44 #if !FEATURE_NO_BSD_SOCKETS
45 ServicePointManager.MaxServicePointIdleTime = maxIdle;
46 #endif
49 [Test, ExpectedException (typeof (InvalidOperationException))]
50 [Category ("NotWorking")]
51 public void MaxServicePointManagers ()
53 Assert.AreEqual (0, ServicePointManager.MaxServicePoints, "#1");
55 DoWebRequest (googleUri);
56 Thread.Sleep (100);
57 DoWebRequest (yahooUri);
58 Thread.Sleep (100);
59 DoWebRequest (apacheUri);
60 Thread.Sleep (100);
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);
78 GC.Collect ();
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);
88 [Test]
89 #if FEATURE_NO_BSD_SOCKETS
90 [ExpectedException (typeof (PlatformNotSupportedException))]
91 #endif
92 public void FindServicePoint ()
94 ServicePointManager.MaxServicePoints = 0;
95 ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));
96 Assert.AreEqual (apacheUri, sp.Address, "#1");
97 #if MOBILE
98 Assert.AreEqual (10, sp.ConnectionLimit, "#2");
99 #else
100 Assert.AreEqual (2, sp.ConnectionLimit, "#2");
101 #endif
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);