suite.AddTest (System.Collections.Specialized.AllTests.Suite);\r
suite.AddTest (System.Diagnostics.AllTests.Suite);\r
suite.AddTest (System.Net.AllTests.Suite);\r
+ suite.AddTest (System.Net.Sockets.AllTests.Suite);\r
suite.AddTest (System.Text.RegularExpressions.AllTests.Suite);\r
- \r
- //suite.AddTest (System.Net.DnsTest.Suite);\r
- \r
return suite;\r
}\r
}\r
+2002/05/17 Lawrence Pit <loz@cable.a2000.nl>
+
+ * AllTests.cs: added call to System.Net.Sockets.AllTests.cs
+
2002/05/14 Lawrence Pit <loz@cable.a2000.nl>
* Dnstest.cs: added test for asynchronous methods
--- /dev/null
+//
+// MonoTests.System.Net.Sockets.AllTests, System.dll
+//
+// Author:
+// Lawrence Pit <loz@cable.a2000nl>
+//
+
+using System;
+using NUnit.Framework;
+
+namespace MonoTests.System.Net.Sockets {
+ /// <summary>
+ /// Combines all available unit tests into one test suite.
+ /// </summary>
+ public class AllTests : TestCase {
+
+ public AllTests (string name) : base (name) {}
+
+ public static ITest Suite {
+ get
+ {
+ TestSuite suite = new TestSuite ();
+ #if NETWORKTEST
+ suite.AddTest (TcpListenerTest.Suite);
+ suite.AddTest (TcpClientTest.Suite);
+ //suite.AddTest (UdpClientTest.Suite);
+ #endif
+ return suite;
+ }
+ }
+ }
+}
+
--- /dev/null
+2002-05-17 Lawrence Pit <loz@cable.a2000.nl>
+
+ * AllTests.cs: added
+
+
+
suite.AddTest (CookieCollectionTest.Suite);
//suite.AddTest (CookieContainerTest.Suite);
suite.AddTest (CredentialCacheTest.Suite);
- suite.AddTest (FileWebRequestTest.Suite);
+ suite.AddTest (FileWebRequestTest.Suite);
suite.AddTest (IPAddressTest.Suite);
suite.AddTest (IPEndPointTest.Suite);
suite.AddTest (SocketPermissionTest.Suite);
suite.AddTest (WebHeaderCollectionTest.Suite);
+ suite.AddTest (WebProxyTest.Suite);
suite.AddTest (WebRequestTest.Suite);
+
+ #if NETWORKTEST
+ suite.AddTest (DnsTest.Suite);
+ suite.AddTest (HttpWebRequestTest.Suite);
+ suite.AddTest (ServicePointTest.Suite);
+ suite.AddTest (ServicePointManagerTest.Suite);
+ #endif
+
return suite;
}
}
+2002-05-20 Lawrence Pit <loz@cable.a2000.nl>
+
+ * ServicePointTest.cs: added
+ * ServicePointManagerTest.cs: added
+ * WebProxyTest.cs: added
+ * AllTests.cs: added the above tests
+ * WebHeaderCollection.cs: added TestIndexers.
+
2002-05-19 Lawrence Pit <loz@cable.a2000.nl>
* FileWebRequestTest.cs: all the async methods tests to behave the same
--- /dev/null
+//\r
+// HttpWebRequestTest.cs - NUnit Test Cases for System.Net.HttpWebRequest\r
+//\r
+// Author:\r
+// Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Net;\r
+using System.Collections;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class HttpWebRequestTest : TestCase\r
+{\r
+ public HttpWebRequestTest () :\r
+ base ("[MonoTests.System.Net.HttpWebRequestTest]") {}\r
+\r
+ public HttpWebRequestTest (string name) : base (name) {}\r
+\r
+ protected override void SetUp () {}\r
+\r
+ protected override void TearDown () {}\r
+\r
+ public static ITest Suite\r
+ {\r
+ get {\r
+ return new TestSuite (typeof (HttpWebRequestTest));\r
+ }\r
+ }\r
+ \r
+ public void TestSync ()\r
+ {\r
+ try {\r
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
+ req.UserAgent = "MonoClient v1.0";\r
+ Console.WriteLine ("req:If Modified Since: " + req.IfModifiedSince);\r
+ WriteHeaders ("req:", req.Headers); \r
+\r
+ HttpWebResponse res = (HttpWebResponse) req.GetResponse ();\r
+ Console.WriteLine ("res:HttpStatusCode: " + res.StatusCode);\r
+ Console.WriteLine ("res:HttpStatusDescription: " + res.StatusDescription);\r
+ \r
+ WriteHeaders ("res:", res.Headers); \r
+ Console.WriteLine("Last Modified: " + res.LastModified);\r
+ \r
+ WriteCookies ("res:", res.Cookies);\r
+ \r
+ WriteHeaders ("req:", req.Headers); \r
+ \r
+ res.Close ();\r
+ } catch (WebException e) {\r
+ Console.WriteLine("\nThe following Exception was raised : {0}", e.Message);\r
+ }\r
+ }\r
+ \r
+ public void TestAsync ()\r
+ {\r
+ }\r
+ \r
+ public void TestAddRange ()\r
+ {\r
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
+ req.AddRange (10);\r
+ req.AddRange (50, 90);\r
+ req.AddRange ("bytes", 100); \r
+ req.AddRange ("bytes", 100, 120);\r
+ AssertEquals ("#1", "bytes=10-,50-90,100-,100-120", req.Headers ["Range"]);\r
+ try {\r
+ req.AddRange ("bits", 2000);\r
+ Fail ("#2");\r
+ } catch (InvalidOperationException) {}\r
+ }\r
+ \r
+ private void WriteHeaders (string label, WebHeaderCollection col) \r
+ {\r
+ label += "Headers";\r
+ if (col.Count == 0)\r
+ Console.WriteLine (label + "Nothing in web headers collection\n");\r
+ else\r
+ Console.WriteLine (label);\r
+ for (int i = 0; i < col.Count; i++)\r
+ Console.WriteLine ("\t" + col.GetKey (i) + ": " + col.Get (i));\r
+ }\r
+ \r
+ private void WriteCookies (string label, CookieCollection col) \r
+ {\r
+ label += "Cookies";\r
+ if (col.Count == 0)\r
+ Console.WriteLine (label + "Nothing in cookies collection\n");\r
+ else\r
+ Console.WriteLine (label);\r
+ for (int i = 0; i < col.Count; i++)\r
+ Console.WriteLine ("\t" + col [i]);\r
+ }\r
+}\r
+\r
+}\r
+\r
--- /dev/null
+//\r
+// ServicePointManagerTest.cs - NUnit Test Cases for System.Net.ServicePointManager\r
+//\r
+// Author:\r
+// Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Collections;\r
+using System.IO;\r
+using System.Net;\r
+using System.Threading;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class ServicePointManagerTest : TestCase\r
+{\r
+ private Uri googleUri;\r
+ private Uri yahooUri;\r
+ private Uri apacheUri;\r
+ \r
+ public ServicePointManagerTest () :\r
+ base ("[MonoTests.System.Net.ServicePointManagerTest]") {}\r
+\r
+ public ServicePointManagerTest (string name) : base (name) {}\r
+\r
+ protected override void SetUp () {\r
+ googleUri = new Uri ("http://www.google.com");\r
+ yahooUri = new Uri ("http://www.yahoo.com");\r
+ apacheUri = new Uri ("http://www.apache.org");\r
+ }\r
+\r
+ protected override void TearDown () {}\r
+\r
+ public static ITest Suite\r
+ {\r
+ get {\r
+ return new TestSuite (typeof (ServicePointManagerTest));\r
+ }\r
+ }\r
+ \r
+ public void TestMaxServicePointManagers ()\r
+ {\r
+ try {\r
+ AssertEquals ("#1", 0, ServicePointManager.MaxServicePoints);\r
+ \r
+ DoWebRequest (googleUri);\r
+ Thread.Sleep (100);\r
+ DoWebRequest (yahooUri);\r
+ Thread.Sleep (100);\r
+ DoWebRequest (apacheUri);\r
+ Thread.Sleep (100);\r
+ \r
+ ServicePoint sp = ServicePointManager.FindServicePoint (googleUri);\r
+ WriteServicePoint (sp);\r
+ sp = ServicePointManager.FindServicePoint (yahooUri);\r
+ WriteServicePoint (sp);\r
+ sp = ServicePointManager.FindServicePoint (apacheUri);\r
+ WriteServicePoint (sp);\r
+ \r
+ ServicePointManager.MaxServicePoints = 1;\r
+\r
+ sp = ServicePointManager.FindServicePoint (googleUri);\r
+ WriteServicePoint (sp);\r
+ sp = ServicePointManager.FindServicePoint (yahooUri);\r
+ WriteServicePoint (sp);\r
+ sp = ServicePointManager.FindServicePoint (apacheUri);\r
+ WriteServicePoint (sp);\r
+ \r
+ GC.Collect ();\r
+ \r
+ // hmm... aparently ms.net still has the service points even\r
+ // though I set it to a max of 1.\r
+ \r
+ // this should force an exception then... \r
+ sp = ServicePointManager.FindServicePoint (new Uri ("http://www.microsoft.com"));\r
+ WriteServicePoint (sp);\r
+ \r
+ } catch (Exception e) {\r
+ Console.WriteLine("\nThe following Exception was raised : {0}", e.Message);\r
+ }\r
+ }\r
+ \r
+ public void TestFindServicePoint ()\r
+ {\r
+ ServicePoint sp = ServicePointManager.FindServicePoint (googleUri, new WebProxy (apacheUri));\r
+ AssertEquals ("#1", apacheUri, sp.Address);\r
+ AssertEquals ("#2", 2, sp.ConnectionLimit);\r
+ AssertEquals ("#3", "http", sp.ConnectionName);\r
+ }\r
+ \r
+ private void DoWebRequest (Uri uri)\r
+ {\r
+ WebRequest.Create (uri).GetResponse ().Close ();\r
+ }\r
+ \r
+ private void WriteServicePoint (ServicePoint sp)\r
+ {\r
+ Console.WriteLine ("\nAddress: " + sp.Address);\r
+ Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);\r
+ Console.WriteLine ("ConnectionName: " + sp.ConnectionName);\r
+ Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);\r
+ Console.WriteLine ("IdleSince: " + sp.IdleSince);\r
+ Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);\r
+ Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);\r
+ Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining); \r
+ }\r
+}\r
+\r
+}\r
+\r
--- /dev/null
+//\r
+// ServicePointTest.cs - NUnit Test Cases for System.Net.ServicePoint\r
+//\r
+// Author:\r
+// Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Collections;\r
+using System.IO;\r
+using System.Net;\r
+using System.Threading;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class ServicePointTest : TestCase\r
+{\r
+ public ServicePointTest () :\r
+ base ("[MonoTests.System.Net.ServicePointTest]") {}\r
+\r
+ public ServicePointTest (string name) : base (name) {}\r
+\r
+ protected override void SetUp () {}\r
+\r
+ protected override void TearDown () {}\r
+\r
+ public static ITest Suite\r
+ {\r
+ get {\r
+ return new TestSuite (typeof (ServicePointTest));\r
+ }\r
+ }\r
+ \r
+ public void TestAll ()\r
+ {\r
+ try {\r
+ ServicePoint p = ServicePointManager.FindServicePoint (new Uri ("mailto:xx@yyy.com"));\r
+ WriteServicePoint ("A servicepoint that isn't really", p); \r
+ \r
+ ServicePointManager.MaxServicePoints = 2;\r
+ ServicePoint google = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com"));\r
+ try { \r
+ ServicePoint slashdot = ServicePointManager.FindServicePoint (new Uri ("http://www.slashdot.org"));\r
+ Fail ("#1");\r
+ } catch (InvalidOperationException) { }\r
+ ServicePointManager.MaxServicePoints = 0;\r
+ \r
+ WriteServicePoint ("google before getting a webrequest", google);\r
+ \r
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
+ HttpWebResponse res = (HttpWebResponse) req.GetResponse (); \r
+ \r
+ WriteServicePoint ("google after getting a response", google);\r
+ ServicePoint google2 = ServicePointManager.FindServicePoint (new Uri ("http://www.google.com/dilbert.html"));\r
+ AssertEquals ("#equals", google, google2);\r
+ res.Close ();\r
+ \r
+ // in both instances property CurrentConnections is 0 according to ms.net.\r
+ // let's see what it says when we do async operations...\r
+ \r
+ HttpWebRequest req2 = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
+ req2.Method = "PUT";\r
+ IAsyncResult async = req2.BeginGetRequestStream (null, null);\r
+ WriteServicePoint ("after async BeginGetRequestStream", google);\r
+ // CurrentConnections: 1\r
+ Stream stream2 = req2.EndGetRequestStream (async);\r
+ WriteServicePoint ("after async EndGetRequestStream", google);\r
+ // CurrentConnections: 1\r
+ stream2.Close ();\r
+ \r
+ req2 = (HttpWebRequest) WebRequest.Create ("http://www.google.com");\r
+ async = req2.BeginGetResponse (null, null);\r
+ WriteServicePoint ("after async BeginGetResponse", google);\r
+ // CurrentConnections: 2\r
+ WebResponse res2 = req2.EndGetResponse (async);\r
+ WriteServicePoint ("after async EndGetResponse", google);\r
+ // CurrentConnections: 0 \r
+ // curious that after you get the webresponse object CurrentConnections is set to 0.\r
+ // you'd think that you'd still be connected until you close the webresponse..\r
+ Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
+ res2.Close ();\r
+ \r
+ \r
+ // unless of course some buffering is taking place.. let's check\r
+ Uri uri2 = new Uri ("http://www.apache.org/dist/httpd/httpd-2.0.36.tar.gz");\r
+ ServicePoint sp2 = ServicePointManager.FindServicePoint (uri2);\r
+ req2 = (HttpWebRequest) WebRequest.Create (uri2);\r
+ async = req2.BeginGetResponse (null, null);\r
+ WriteServicePoint ("Large file: after async BeginGetResponse", sp2);\r
+ // CurrentConnections: 1\r
+ res2 = req2.EndGetResponse (async);\r
+ WriteServicePoint ("Large file: after async EndGetResponse", sp2);\r
+ // CurrentConnections: 1\r
+ // and so it shows\r
+ Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
+ res2.Close ();\r
+ \r
+ \r
+ // what's the limit of the cache?\r
+ req2 = (HttpWebRequest) WebRequest.Create ("http://www.apache.org/");\r
+ res2 = req2.GetResponse ();\r
+ sp2 = ServicePointManager.FindServicePoint (new Uri("http://www.apache.org/"));\r
+ WriteServicePoint ("apache", sp2);\r
+ Console.WriteLine ("ContentLength: " + res2.ContentLength);\r
+ // CurrentConnections: 1\r
+ res2.Close ();\r
+ // curious other effect: address is actually the full Uri of the previous request\r
+ // anyways, buffer is probably 4096 bytes\r
+\r
+ \r
+ } catch (WebException e) {\r
+ Console.WriteLine("\nThe following Exception was raised : {0}", e.Message);\r
+ }\r
+ }\r
+\r
+ // try getting the stream to 5 web response objects \r
+ // while ConnectionLimit equals 2\r
+ /*\r
+ public void TestConnectionLimit ()\r
+ { \r
+ try {\r
+ // the default is already 2, just in case it isn't..\r
+ ServicePointManager.DefaultConnectionLimit = 2;\r
+ \r
+ Uri uri = new Uri ("http://www.apache.org/dist/httpd/httpd-2.0.36.tar.gz");\r
+ ServicePoint sp = ServicePointManager.FindServicePoint (uri); \r
+ WebResponse [] res = new WebResponse [5];\r
+ for (int i = 0; i < 5; i++) {\r
+ Console.WriteLine ("GOT1 : " + i);\r
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create (uri);\r
+ Console.WriteLine ("GOT2 : " + i);\r
+ res [i] = req.GetResponse ();\r
+ WriteServicePoint ("after getting " + (i + 1) + " web response objects", sp);\r
+ }\r
+ \r
+ for (int i = 0; i < 5; i++) {\r
+ Stream stream = res [i].GetResponseStream();\r
+ Console.WriteLine ("Reading stream: " + i + " : " + stream);\r
+ int len = 0;\r
+ while (stream.ReadByte () != -1)\r
+ len++;\r
+ Console.WriteLine ("Finished reading: " + len + " bytes");\r
+ }\r
+ \r
+ for (int i = 0; i < 5; i++) {\r
+ res [i].Close ();\r
+ }\r
+ } catch (WebException e) {\r
+ Console.WriteLine("\nThe following Exception was raised : {0}", e.Message);\r
+ } \r
+ }\r
+ */\r
+ \r
+ private void WriteServicePoint (string label, ServicePoint sp)\r
+ {\r
+ Console.WriteLine ("\n" + label);\r
+ Console.WriteLine ("Address: " + sp.Address);\r
+ Console.WriteLine ("ConnectionLimit: " + sp.ConnectionLimit);\r
+ Console.WriteLine ("ConnectionName: " + sp.ConnectionName);\r
+ Console.WriteLine ("CurrentConnections: " + sp.CurrentConnections);\r
+ Console.WriteLine ("IdleSince: " + sp.IdleSince);\r
+ Console.WriteLine ("MaxIdletime: " + sp.MaxIdleTime);\r
+ Console.WriteLine ("ProtocolVersion: " + sp.ProtocolVersion);\r
+ Console.WriteLine ("SupportsPipelining: " + sp.SupportsPipelining); \r
+ }\r
+}\r
+\r
+}\r
+\r
AssertEquals ("#15", null, w.GetValues ("NotExistent"));\r
}\r
\r
+ public void TestIndexers ()\r
+ {\r
+ AssertEquals ("#1", "Value1", col [0]);\r
+ AssertEquals ("#2", "Value1", col ["Name1"]);\r
+ AssertEquals ("#3", "Value1", col ["NAME1"]);\r
+ }\r
+ \r
public void TestRemove ()\r
{\r
col.Remove ("Name1");\r
--- /dev/null
+//\r
+// WebProxyTest.cs - NUnit Test Cases for System.Net.WebProxy\r
+//\r
+// Author:\r
+// Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Collections;\r
+using System.IO;\r
+using System.Net;\r
+using System.Threading;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class WebProxyTest : TestCase\r
+{\r
+ private Uri googleUri;\r
+ private Uri yahooUri;\r
+ private Uri apacheUri;\r
+ \r
+ public WebProxyTest () :\r
+ base ("[MonoTests.System.Net.WebProxyTest]") {}\r
+\r
+ public WebProxyTest (string name) : base (name) {}\r
+\r
+ protected override void SetUp () {\r
+ googleUri = new Uri ("http://www.google.com");\r
+ yahooUri = new Uri ("http://www.yahoo.com");\r
+ apacheUri = new Uri ("http://www.apache.org");\r
+ }\r
+\r
+ protected override void TearDown () {}\r
+\r
+ public static ITest Suite\r
+ {\r
+ get {\r
+ return new TestSuite (typeof (WebProxyTest));\r
+ }\r
+ }\r
+ \r
+ public void TestConstructors ()\r
+ {\r
+ WebProxy p = new WebProxy ();\r
+ Assert("#1", p.Address == null);\r
+ AssertEquals ("#2", 0, p.BypassArrayList.Count);\r
+ AssertEquals ("#3", 0, p.BypassList.Length);\r
+ AssertEquals ("#4", false, p.BypassProxyOnLocal);\r
+ try {\r
+ p.BypassList = null;\r
+ Fail ("#5 not spec'd, but should follow ms.net implementation");\r
+ } catch (ArgumentNullException) {}\r
+ }\r
+ \r
+ public void TestGetProxy ()\r
+ {\r
+ } \r
+ \r
+ public void TestIsByPassed ()\r
+ {\r
+ WebProxy p = new WebProxy ("http://proxy.contoso.com", true);\r
+ Assert ("#1", !p.IsBypassed (new Uri ("http://www.google.com")));\r
+ Assert ("#2", p.IsBypassed (new Uri ("http://localhost/index.html")));\r
+ Assert ("#3", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));\r
+ Assert ("#4", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));\r
+ Assert ("#5", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));\r
+ Assert ("#6", p.IsBypassed (new Uri ("http://webserver/index.html")));\r
+ Assert ("#7", !p.IsBypassed (new Uri ("http://webserver.com/index.html")));\r
+ try {\r
+ p.IsBypassed (null);\r
+ Fail ("#8 not spec'd, but should follow ms.net implementation");\r
+ } catch (NullReferenceException) {}\r
+ \r
+ p = new WebProxy ("http://proxy.contoso.com", false);\r
+ Assert ("#11", !p.IsBypassed (new Uri ("http://www.google.com")));\r
+ Assert ("#12: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost/index.html")));\r
+ Assert ("#13: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));\r
+ Assert ("#14: lamespec of ms.net", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));\r
+ Assert ("#15: lamespec of ms.net", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));\r
+ Assert ("#16", !p.IsBypassed (new Uri ("http://webserver/index.html")));\r
+ \r
+ p.BypassList = new string [] { "google.com", "contoso.com" };\r
+ Assert ("#20", p.IsBypassed (new Uri ("http://www.google.com")));\r
+ Assert ("#21", p.IsBypassed (new Uri ("http://www.GOOGLE.com")));\r
+ Assert ("#22", p.IsBypassed (new Uri ("http://www.contoso.com:8080/foo/bar/index.html")));\r
+ Assert ("#23", !p.IsBypassed (new Uri ("http://www.contoso2.com:8080/foo/bar/index.html")));\r
+ Assert ("#24", !p.IsBypassed (new Uri ("http://www.foo.com:8080/contoso.com.html")));\r
+ }\r
+}\r
+\r
+}\r
+\r