* FileWebRequest.cs: Fixed PreAuthenticate and Proxy properties to
authorGert Driesen <drieseng@users.sourceforge.net>
Sun, 28 Jan 2007 15:52:04 +0000 (15:52 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Sun, 28 Jan 2007 15:52:04 +0000 (15:52 -0000)
no longer throw NotSupportedException. No longer store ContentLength
in headers. Do not allow null or zero-length method. Allow timeout
to be set to -1 (infine). Only disallow GET, HEAD and CONNECT requests.
Removed workarounds for bug #24943. In (Begin)GetRequest overwrite
file if it already exists. Binary serialization compatibility fixes.
* FileWebResponse.cs: Return application/octet-stream as ContentType.
* FileWebRequestTest.cs: Reworked tests to no longer rely on TMPDIR.
Added tests for ConnectionGroupName, ContentLength, ContentType,
Credentials, GetRequestStream, GetResponse, Method, PreAuthenticate,
Proxy, RequestUri, Timeout. Added binary serialization compatibility
tests.
* FileWebResponseTest.cs: Added tests for ContentLength, ContentType,
GetResponseStream, Headers, ResponseUri.
* System_test.dll.sources: Added FileWebResponseTest.cs.

svn path=/trunk/mcs/; revision=71809

mcs/class/System/ChangeLog
mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/FileWebRequest.cs
mcs/class/System/System.Net/FileWebResponse.cs
mcs/class/System/System_test.dll.sources
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/FileWebRequestTest.cs
mcs/class/System/Test/System.Net/FileWebResponseTest.cs [new file with mode: 0644]

index 16de6547ab585c665873e0074219444a55c31e66..a48966a31fccc52f69c5227a252d65f81782dfe2 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * System_test.dll.sources: Added FileWebResponseTest.cs.
+
 2007-01-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * System.dll.sources: added new sources:
index 4254cfcaf2d97bb8641bb59a51a9eea50a5daa3d..e05880b44d7d17b9aa537da51a57b15c3bbaf59e 100644 (file)
@@ -1,3 +1,13 @@
+2007-01-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * FileWebRequest.cs: Fixed PreAuthenticate and Proxy properties to
+       no longer throw NotSupportedException. No longer store ContentLength
+       in headers. Do not allow null or zero-length method. Allow timeout
+       to be set to -1 (infine). Only disallow GET, HEAD and CONNECT requests.
+       Removed workarounds for bug #24943. In (Begin)GetRequest overwrite
+       file if it already exists. Binary serialization compatibility fixes.
+       * FileWebResponse.cs: Return application/octet-stream as ContentType.
+
 2007-01-28  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * WebHeaderCollection.cs: Fixed binary serialization compatibility 
index 67ecd06ea46a5e60238940764e5b435ebc13cbc5..6cf6b3babfff504da521333be8c643577f7c2ad2 100644 (file)
@@ -43,7 +43,11 @@ namespace System.Net
                \r
                private ICredentials credentials;\r
                private string connectionGroup;\r
+               private long contentLength;\r
+               private FileAccess fileAccess = FileAccess.Read;\r
                private string method = "GET";\r
+               private IWebProxy proxy;\r
+               private bool preAuthenticate;\r
                private int timeout = 100000;\r
                \r
                private Stream requestStream;\r
@@ -57,40 +61,41 @@ namespace System.Net
                internal FileWebRequest (Uri uri) \r
                { \r
                        this.uri = uri;\r
-                       this.webHeaders = new WebHeaderCollection ();\r
-               }               \r
+                       this.webHeaders = new WebHeaderCollection ();\r
+               }\r
                \r
                protected FileWebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext) \r
                {\r
                        SerializationInfo info = serializationInfo;\r
-\r
-                       method = info.GetString ("method");\r
+                       webHeaders = (WebHeaderCollection) info.GetValue ("headers", typeof (WebHeaderCollection));\r
+                       proxy = (IWebProxy) info.GetValue ("proxy", typeof (IWebProxy));\r
                        uri = (Uri) info.GetValue ("uri", typeof (Uri));\r
+                       connectionGroup = info.GetString ("connectionGroupName");\r
+                       method = info.GetString ("method");\r
+                       contentLength = info.GetInt64 ("contentLength");\r
                        timeout = info.GetInt32 ("timeout");\r
-                       connectionGroup = info.GetString ("connectionGroup");\r
-                       webHeaders = (WebHeaderCollection) info.GetValue ("webHeaders", typeof (WebHeaderCollection));\r
+                       fileAccess = (FileAccess) info.GetValue ("fileAccess", typeof (FileAccess));\r
+                       preAuthenticate = info.GetBoolean ("preauthenticate");\r
                }\r
                \r
                // Properties\r
                \r
                // currently not used according to spec\r
-               public override string ConnectionGroupName { \r
+               public override string ConnectionGroupName {\r
                        get { return connectionGroup; }\r
                        set { connectionGroup = value; }\r
                }\r
                \r
-               public override long ContentLength { \r
-                       get { \r
-                               try {\r
-                                       return Int64.Parse (webHeaders ["Content-Length"]); \r
-                               } catch (Exception) {\r
-                                       return 0;\r
-                               }\r
-                       }\r
-                       set { \r
+               public override long ContentLength {\r
+                       get { return contentLength; }\r
+                       set {\r
                                if (value < 0)\r
+#if NET_2_0\r
+                                       throw new ArgumentException ("The Content-Length value must be greater than or equal to zero.", "value");\r
+#else\r
                                        throw new ArgumentException ("value");\r
-                               webHeaders ["Content-Length"] = Convert.ToString (value);\r
+#endif\r
+                               contentLength =  value;\r
                        }\r
                }\r
                \r
@@ -111,19 +116,29 @@ namespace System.Net
                // currently not used according to spec\r
                public override string Method { \r
                        get { return this.method; }\r
-                       set { this.method = value; }\r
+                       set {\r
+                               if (value == null || value.Length == 0)\r
+#if NET_2_0\r
+                                       throw new ArgumentException ("Cannot set null or blank "\r
+                                               + "methods on request.", "value");\r
+#else\r
+                                       throw new ArgumentException ("Cannot set null or blank "\r
+                                               + "methods on request.");\r
+#endif\r
+                               this.method = value;\r
+                       }\r
                }\r
                \r
                // currently not used according to spec\r
                public override bool PreAuthenticate { \r
-                       get { throw new NotSupportedException (); }\r
-                       set { throw new NotSupportedException (); }\r
+                       get { return preAuthenticate; }\r
+                       set { preAuthenticate = value; }\r
                }\r
                \r
                // currently not used according to spec\r
-               public override IWebProxy Proxy { \r
-                       get { throw new NotSupportedException (); }\r
-                       set { throw new NotSupportedException (); }\r
+               public override IWebProxy Proxy {\r
+                       get { return proxy; }\r
+                       set { proxy = value; }\r
                }\r
                \r
                public override Uri RequestUri { \r
@@ -133,8 +148,14 @@ namespace System.Net
                public override int Timeout { \r
                        get { return timeout; }\r
                        set { \r
-                               if (value < 0)\r
-                                       throw new ArgumentException ("value");\r
+                               if (value < -1)\r
+#if NET_2_0\r
+                                       throw new ArgumentOutOfRangeException ("Timeout can be "\r
+                                               + "only set to 'System.Threading.Timeout.Infinite' "\r
+                                               + "or a value >= 0.");\r
+#else\r
+                                       throw new ArgumentOutOfRangeException ("value");\r
+#endif\r
                                timeout = value;\r
                        }\r
                }\r
@@ -145,22 +166,11 @@ namespace System.Net
                private delegate WebResponse GetResponseCallback ();\r
 \r
                public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) \r
-               {               \r
-                       if (method == null || (!method.Equals ("PUT") && !method.Equals ("POST")))\r
-                               throw new ProtocolViolationException ("Cannot send file when method is: " + this.method + ". Method must be PUT.");\r
-                       // workaround for bug 24943\r
-                       Exception e = null;\r
-                       lock (this) {\r
-                               if (asyncResponding || webResponse != null)\r
-                                       e = new InvalidOperationException ("This operation cannot be performed after the request has been submitted.");\r
-                               else if (requesting)\r
-                                       e = new InvalidOperationException ("Cannot re-call start of asynchronous method while a previous call is still in progress.");\r
-                               else\r
-                                       requesting = true;\r
-                       }\r
-                       if (e != null)\r
-                               throw e;\r
-                       /*\r
+               {\r
+                       if (string.Compare ("GET", method, true) == 0 ||\r
+                               string.Compare ("HEAD", method, true) == 0 ||\r
+                               string.Compare ("CONNECT", method, true) == 0)\r
+                               throw new ProtocolViolationException ("Cannot send a content-body with this verb-type.");\r
                        lock (this) {\r
                                if (asyncResponding || webResponse != null)\r
                                        throw new InvalidOperationException ("This operation cannot be performed after the request has been submitted.");\r
@@ -168,9 +178,8 @@ namespace System.Net
                                        throw new InvalidOperationException ("Cannot re-call start of asynchronous method while a previous call is still in progress.");\r
                                requesting = true;\r
                        }\r
-                       */\r
                        GetRequestStreamCallback c = new GetRequestStreamCallback (this.GetRequestStreamInternal);\r
-                       return c.BeginInvoke (callback, state);                 \r
+                       return c.BeginInvoke (callback, state);\r
                }\r
                \r
                public override Stream EndGetRequestStream (IAsyncResult asyncResult)\r
@@ -178,7 +187,7 @@ namespace System.Net
                        if (asyncResult == null)\r
                                throw new ArgumentNullException ("asyncResult");\r
                        if (!asyncResult.IsCompleted)\r
-                               asyncResult.AsyncWaitHandle.WaitOne ();                         \r
+                               asyncResult.AsyncWaitHandle.WaitOne ();\r
                        AsyncResult async = (AsyncResult) asyncResult;\r
                        GetRequestStreamCallback cb = (GetRequestStreamCallback) async.AsyncDelegate;\r
                        return cb.EndInvoke (asyncResult);\r
@@ -197,7 +206,7 @@ namespace System.Net
                {\r
                        this.requestStream = new FileWebStream (\r
                                                this,\r
-                                               FileMode.CreateNew,\r
+                                               FileMode.Create,\r
                                                FileAccess.Write, \r
                                                FileShare.Read);\r
                        return this.requestStream;\r
@@ -205,40 +214,28 @@ namespace System.Net
                \r
                public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state)\r
                {\r
-                       // workaround for bug 24943\r
-                       Exception e = null;\r
-                       lock (this) {\r
-                               if (asyncResponding)\r
-                                       e = new InvalidOperationException ("Cannot re-call start of asynchronous method while a previous call is still in progress.");\r
-                               else \r
-                                       asyncResponding = true;\r
-                       }\r
-                       if (e != null)\r
-                               throw e;\r
-                       /*\r
                        lock (this) {\r
                                if (asyncResponding)\r
                                        throw new InvalidOperationException ("Cannot re-call start of asynchronous method while a previous call is still in progress.");\r
                                asyncResponding = true;\r
                        }\r
-                       */\r
                        GetResponseCallback c = new GetResponseCallback (this.GetResponseInternal);\r
                        return c.BeginInvoke (callback, state);\r
                }\r
-\r
+               \r
                public override WebResponse EndGetResponse (IAsyncResult asyncResult)\r
                {\r
                        if (asyncResult == null)\r
                                throw new ArgumentNullException ("asyncResult");\r
                        if (!asyncResult.IsCompleted)\r
-                               asyncResult.AsyncWaitHandle.WaitOne ();                 \r
+                               asyncResult.AsyncWaitHandle.WaitOne ();\r
                        AsyncResult async = (AsyncResult) asyncResult;\r
                        GetResponseCallback cb = (GetResponseCallback) async.AsyncDelegate;\r
                        WebResponse webResponse = cb.EndInvoke(asyncResult);\r
                        asyncResponding = false;\r
                        return webResponse;\r
                }\r
-                               \r
+               \r
                public override WebResponse GetResponse ()\r
                {\r
                        IAsyncResult asyncResult = BeginGetResponse (null, null);\r
@@ -247,11 +244,11 @@ namespace System.Net
                        }\r
                        return EndGetResponse (asyncResult);\r
                }\r
-                       \r
+               \r
                WebResponse GetResponseInternal ()\r
                {\r
                        if (webResponse != null)\r
-                               return webResponse;                     \r
+                               return webResponse;\r
                        lock (this) {\r
                                if (requesting) {\r
                                        requestEndEvent = new AutoResetEvent (false);\r
@@ -260,24 +257,33 @@ namespace System.Net
                        if (requestEndEvent != null) {\r
                                requestEndEvent.WaitOne ();\r
                        }\r
-                       FileStream fileStream = new FileWebStream (\r
-                                                       this,\r
-                                                       FileMode.Open, \r
-                                                       FileAccess.Read, \r
-                                                       FileShare.Read);\r
-                       this.webResponse = new FileWebResponse (this.uri, fileStream);\r
-                       return (WebResponse) this.webResponse;\r
+                       FileStream fileStream = null;\r
+                       try {\r
+                               fileStream = new FileWebStream (this, FileMode.Open,\r
+                                FileAccess.Read, FileShare.Read);\r
+                       } catch (Exception ex) {\r
+                               throw new WebException (ex.Message, ex);\r
+                       }\r
+                       this.webResponse = new FileWebResponse (this.uri, fileStream);\r
+                       return (WebResponse) this.webResponse;\r
                }\r
                \r
                void ISerializable.GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)\r
                {\r
                        SerializationInfo info = serializationInfo;\r
-\r
-                       info.AddValue ("method", method);\r
+                       info.AddValue ("headers", webHeaders, typeof (WebHeaderCollection));\r
+                       info.AddValue ("proxy", proxy, typeof (IWebProxy));\r
                        info.AddValue ("uri", uri, typeof (Uri));\r
+                       info.AddValue ("connectionGroupName", connectionGroup);\r
+                       info.AddValue ("method", method);\r
+                       info.AddValue ("contentLength", contentLength);\r
                        info.AddValue ("timeout", timeout);\r
-                       info.AddValue ("connectionGroup", connectionGroup);\r
-                       info.AddValue ("webHeaders", webHeaders, typeof (WebHeaderCollection));\r
+                       info.AddValue ("fileAccess", fileAccess);\r
+#if NET_2_0\r
+                       info.AddValue ("preauthenticate", false);\r
+#else\r
+                       info.AddValue ("preauthenticate", preAuthenticate);\r
+#endif\r
                }\r
                \r
                internal void Close ()\r
@@ -287,7 +293,7 @@ namespace System.Net
                        //      requestStream.Close ();\r
                        // }\r
 \r
-                       lock (this) {                   \r
+                       lock (this) {\r
                                requesting = false;\r
                                if (requestEndEvent != null) \r
                                        requestEndEvent.Set ();\r
@@ -309,7 +315,7 @@ namespace System.Net
                        {\r
                                this.webRequest = webRequest;\r
                        }\r
-                                               \r
+                       \r
                        public override void Close() \r
                        {\r
                                base.Close ();\r
index 83e08583df66427c17e76bd506f8e850d0e326fe..44cc2ac6dca831ac674709a876344afafd2bc23b 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Net
                                this.contentLength = fileStream.Length;\r
                                this.webHeaders = new WebHeaderCollection ();\r
                                this.webHeaders.Add ("Content-Length", Convert.ToString (contentLength));\r
-                               this.webHeaders.Add ("Content-Type", "binary/octet-stream");\r
+                               this.webHeaders.Add ("Content-Type", "application/octet-stream");\r
                        } catch (Exception e) {\r
                                throw new WebException (e.Message, e);\r
                        }\r
@@ -68,33 +68,33 @@ namespace System.Net
                \r
                // Properties\r
                \r
-               public override long ContentLength {            \r
+               public override long ContentLength {\r
                        get {\r
                                CheckDisposed ();\r
                                return this.contentLength;\r
                        }\r
                }\r
                \r
-               public override string ContentType {            \r
+               public override string ContentType {\r
                        get {\r
                                CheckDisposed ();\r
-                               return "binary/octet-stream";\r
+                               return "application/octet-stream";\r
                        }\r
                }\r
                \r
-               public override WebHeaderCollection Headers {           \r
+               public override WebHeaderCollection Headers {\r
                        get {\r
                                CheckDisposed ();\r
                                return this.webHeaders;\r
                        }\r
                }\r
                \r
-               public override Uri ResponseUri {               \r
+               public override Uri ResponseUri {\r
                        get {\r
                                CheckDisposed ();\r
                                return this.responseUri;\r
                        }\r
-               }               \r
+               }\r
 \r
                // Methods\r
 \r
index da97b78500debfc72c9125b42b26b28abc775e18..7ea7719cf63c623451a71f80ad62d763fd625f71 100644 (file)
@@ -166,6 +166,7 @@ System.Net/DnsPermissionAttributeTest.cs
 System.Net/DnsPermissionTest.cs
 System.Net/DnsTest.cs
 System.Net/FileWebRequestTest.cs
+System.Net/FileWebResponseTest.cs
 System.Net/HttpWebRequestTest.cs
 System.Net/HttpListenerTest.cs
 System.Net/HttpListenerBasicIdentityTest.cs
index bd4ae6e5a05f7607e0cb11c1ae0b730a15c1e9fd..76779aad3f280a0eefa8e767c2d419c52f3e27f9 100644 (file)
@@ -1,3 +1,13 @@
+2007-01-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * FileWebRequestTest.cs: Reworked tests to no longer rely on TMPDIR.
+       Added tests for ConnectionGroupName, ContentLength, ContentType,
+       Credentials, GetRequestStream, GetResponse, Method, PreAuthenticate,
+       Proxy, RequestUri, Timeout. Added binary serialization compatibility
+       tests.
+       * FileWebResponseTest.cs: Added tests for ContentLength, ContentType,
+       GetResponseStream, Headers, ResponseUri.
+
 2007-01-28  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * WebHeaderCollectionTest.cs: Added tests for binary serialization
index 53162ae82eda9c2ab6c11b72136849b2bd26d7b0..21c2c4d28e59c8afbfc300c0ad031d8585271fd5 100644 (file)
-//\r
-// FileWebRequestTest.cs - NUnit Test Cases for System.Net.FileWebRequest\r
-//\r
-// Authors:\r
-//   Lawrence Pit (loz@cable.a2000.nl)\r
-//   Martin Willemoes Hansen (mwh@sysrq.dk)\r
-//\r
-// (C) 2003 Martin Willemoes Hansen\r
-//\r
-\r
-using NUnit.Framework;\r
-using System;\r
-using System.IO;\r
-using System.Net;\r
-using System.Collections;\r
-using System.Security;\r
-using System.Security.Permissions;\r
-\r
-namespace MonoTests.System.Net\r
-{\r
-\r
-[TestFixture]\r
-public class FileWebRequestTest\r
-{\r
-        [Test]\r
-        public void Async ()\r
-        {\r
-               string tmpFilename = GetFilename ();\r
-               if (tmpFilename == null) {\r
-                       Console.WriteLine ("\n\nSet environment variable TMPDIR to a temporary directory to test FileWebRequest\n");\r
-                       return;\r
-               }\r
-               \r
-               try {\r
-                       if (File.Exists (tmpFilename)) \r
-                               File.Delete (tmpFilename);\r
-                       \r
-                       Uri uri = new Uri ("file://" + tmpFilename);\r
-                       \r
-                       WebRequest req = WebRequest.Create (uri);\r
-                       req.Method = "PUT";\r
-                       \r
-                       req.Timeout = 2 * 1000;\r
-                       IAsyncResult async = req.BeginGetRequestStream (null, null);\r
-                       try {\r
-                               req.BeginGetRequestStream (null, null);\r
-                               Assertion.Fail ("#1 should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               //Console.WriteLine ("GOT1: " + e.Message + "\n" + e.StackTrace);                               \r
-                               // Cannot re-call BeginGetRequestStream/BeginGetResponse while\r
-                               // a previous call is still in progress\r
-                       }\r
-                       /*\r
-                       try {\r
-                               req.BeginGetResponse (null, null);\r
-                               Assertion.Fail ("#2 should've failed");\r
-                       } catch (InvalidOperationException) { }\r
-                       */\r
-                       try {\r
-                               req.GetRequestStream ();\r
-                               Assertion.Fail ("#3 should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               // Console.WriteLine ("GOT3: " + e.Message + "\n" + e.StackTrace);\r
-                               // Cannot re-call BeginGetRequestStream/BeginGetResponse while\r
-                               // a previous call is still in progress\r
-                       }\r
-\r
-                       try {\r
-                               req.GetResponse ();\r
-                               Assertion.Fail ("#4 should've failed");\r
-                       } catch (WebException) { \r
-                               // Console.WriteLine ("4: " + e.Message + "\n" + e.StackTrace);                         \r
-                               // The operation has timed out\r
-                       }\r
-\r
-                       try {\r
-                               IAsyncResult async0 = req.BeginGetResponse (null, null);\r
-                               req.EndGetResponse (async0);\r
-                               // Console.WriteLine ("X5c");\r
-                               Assertion.Fail ("#5 should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               // Console.WriteLine ("5e: " + e.Message + "\n" + e.StackTrace);\r
-                               // Cannot re-call BeginGetRequestStream/BeginGetResponse while\r
-                               // a previous call is still in progress\r
-                       }\r
-                       \r
-                       // Console.WriteLine ("WEBHEADERS: " + req.Headers);\r
-                       \r
-                       Stream wstream = req.EndGetRequestStream (async);\r
-                       Assertion.AssertEquals ("#1r", false, wstream.CanRead);\r
-                       Assertion.AssertEquals ("#1w", true, wstream.CanWrite);\r
-                       Assertion.AssertEquals ("#1s", true, wstream.CanSeek);\r
-\r
-                       wstream.WriteByte (72);\r
-                       wstream.WriteByte (101);\r
-                       wstream.WriteByte (108);\r
-                       wstream.WriteByte (108);\r
-                       wstream.WriteByte (111);\r
-                       wstream.Close ();\r
-                       \r
-                       // stream written\r
-\r
-                       req = WebRequest.Create (uri);\r
-                       WebResponse res = req.GetResponse ();   \r
-                       \r
-                       try {\r
-                               req.BeginGetRequestStream (null, null);\r
-                               Assertion.Fail ("#20: should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               // Console.WriteLine ("20: " + e.Message + "\n" + e.StackTrace);                                \r
-                               // Cannot send a content-body with this verb-type\r
-                       }\r
-                       \r
-                       try {\r
-                               req.Method = "PUT";\r
-                               req.BeginGetRequestStream (null, null);\r
-                               Assertion.Fail ("#21: should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               // Console.WriteLine ("21: " + e.Message + "\n" + e.StackTrace);                                \r
-                               // This operation cannot be perfomed after the request has been submitted.\r
-                       }\r
-                       \r
-                       try {\r
-                               //IAsyncResult async2 = req.BeginGetResponse (null, null);\r
-                               //Console.WriteLine ("OK!");\r
-                               req.GetResponse ();\r
-                               //Assertion.Fail ("#22: should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                               //Console.WriteLine ("22: " + e.Message + "\n" + e.StackTrace);\r
-                               // Cannot re-call BeginGetRequestStream/BeginGetResponse while\r
-                               // a previous call is still in progress\r
-                               Assertion.Fail ("#22: should not have failed");\r
-                       }                       \r
-                       \r
-                       try {\r
-                               IAsyncResult async2 = req.BeginGetResponse (null, null);\r
-                               \r
-                               // this succeeds !!\r
-                               \r
-                               try {\r
-                                       WebResponse res2 = req.EndGetResponse (async2);\r
-                                                                               \r
-                                       // and this succeeds\r
-                                       \r
-                                       Assertion.AssertEquals ("#23", res, res2) ;\r
-                                       \r
-                                       //Assertion.Fail ("#23: should've failed");\r
-                               } catch (InvalidOperationException) { \r
-                                       //Console.WriteLine ("22: " + e.Message + "\n" + e.StackTrace);                         \r
-                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse while\r
-                                       // a previous call is still in progress\r
-                               }                               \r
-                               \r
-                               // Assertion.Fail ("#22: should've failed");\r
-                       } catch (InvalidOperationException) { \r
-                       }                       \r
-\r
-                       Assertion.AssertEquals ("#2 len", (long) 5, res.ContentLength);\r
-                       Assertion.AssertEquals ("#2 type", "binary/octet-stream", res.ContentType);\r
-                       Assertion.AssertEquals ("#2 scheme", "file", res.ResponseUri.Scheme);\r
-                       \r
-                       Stream rstream = res.GetResponseStream ();                      \r
-                       Assertion.AssertEquals ("#3r", true, rstream.CanRead);\r
-                       Assertion.AssertEquals ("#3w", false, rstream.CanWrite);\r
-                       Assertion.AssertEquals ("#3s", true, rstream.CanSeek);\r
-                       \r
-                       Assertion.AssertEquals ("#4a", 72, rstream.ReadByte ());\r
-                       Assertion.AssertEquals ("#4b", 101, rstream.ReadByte ());\r
-                       Assertion.AssertEquals ("#4c", 108, rstream.ReadByte ());\r
-\r
-                       rstream.Close ();\r
-                       // res.Close ();\r
-                       \r
-                       try {\r
-                               long len = res.ContentLength;\r
-                               Assertion.AssertEquals ("#5", (long) 5, len);\r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed contentlength");                             \r
-                       }\r
-                       try {\r
-                               WebHeaderCollection w = res.Headers;\r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed headers");                           \r
-                       }                       \r
-                       try {\r
-                               res.Close ();                           \r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed close");                             \r
-                       }\r
-               } catch (Exception) {\r
-                       // Console.WriteLine ("ERROR! : " + ee.Message + "\n" + ee.StackTrace);\r
-               } finally {\r
-                       try {\r
-                               // known bug #24940\r
-                               File.Delete (tmpFilename);\r
-                       } catch (Exception) { \r
-                               // Console.WriteLine ("ERROR2! : " + ee2.Message + "\n" + ee2.StackTrace);\r
-                       }\r
-               }\r
-       }               \r
-        \r
-        [Test]\r
-#if TARGET_JVM\r
-       [Ignore ("TD BUG ID: 7205")]\r
-       [Category ("NotWorking")]\r
-#endif \r
-        public void Sync ()\r
-        {\r
-               string tmpFilename = GetFilename ();\r
-               if (tmpFilename == null)\r
-                       return;\r
-               \r
-               try {           \r
-#if TARGET_JVM\r
-                       /*\r
-                         Probably due to the fact that previos test doesn't close\r
-                         the temp file clearly the file cannot be deleted.\r
-                       */\r
-#endif\r
-                       if (File.Exists (tmpFilename)) \r
-                               File.Delete (tmpFilename);\r
-                       \r
-                       Uri uri = new Uri ("file://" + tmpFilename);\r
-                       \r
-                       WebRequest req = WebRequest.Create (uri);\r
-                       \r
-                       try {\r
-                               Stream stream = req.GetRequestStream ();\r
-                               Assertion.Fail ("should throw exception");\r
-                       } catch (ProtocolViolationException) {}\r
-                       \r
-                       req.Method = "PUT";\r
-                       \r
-                       Stream wstream = req.GetRequestStream ();\r
-                       Assertion.AssertEquals ("#1r", false, wstream.CanRead);\r
-                       Assertion.AssertEquals ("#1w", true, wstream.CanWrite);\r
-                       Assertion.AssertEquals ("#1s", true, wstream.CanSeek);\r
-\r
-                       wstream.WriteByte (72);\r
-                       wstream.WriteByte (101);\r
-                       wstream.WriteByte (108);\r
-                       wstream.WriteByte (108);\r
-                       wstream.WriteByte (111);\r
-                       wstream.Close ();\r
-                       \r
-                       // stream written\r
-                       \r
-                       req = WebRequest.Create (uri);\r
-                       WebResponse res = req.GetResponse ();                   \r
-                       Assertion.AssertEquals ("#2 len", (long) 5, res.ContentLength);\r
-                       Assertion.AssertEquals ("#2 type", "binary/octet-stream", res.ContentType);\r
-                       Assertion.AssertEquals ("#2 scheme", "file", res.ResponseUri.Scheme);\r
-                       \r
-                       Stream rstream = res.GetResponseStream ();                      \r
-                       Assertion.AssertEquals ("#3r", true, rstream.CanRead);\r
-                       Assertion.AssertEquals ("#3w", false, rstream.CanWrite);\r
-                       Assertion.AssertEquals ("#3s", true, rstream.CanSeek);\r
-                       \r
-                       Assertion.AssertEquals ("#4a", 72, rstream.ReadByte ());\r
-                       Assertion.AssertEquals ("#4b", 101, rstream.ReadByte ());\r
-                       Assertion.AssertEquals ("#4c", 108, rstream.ReadByte ());\r
-                       \r
-                       rstream.Close ();\r
-                       // res.Close ();\r
-                       \r
-                       try {\r
-                               long len = res.ContentLength;\r
-                               Assertion.AssertEquals ("#5", (long) 5, len);\r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed contentlength");                             \r
-                       }\r
-                       try {\r
-                               WebHeaderCollection w = res.Headers;\r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed headers");                           \r
-                       }                       \r
-                       try {\r
-                               res.Close ();                           \r
-                       } catch (ObjectDisposedException) {\r
-                               Assertion.Fail ("#disposed close");                             \r
-                       }\r
-                       \r
-               } finally {\r
-                       try {\r
-                               File.Delete (tmpFilename);\r
-                       } catch (Exception) { }\r
-               }\r
-       }       \r
-       \r
-       private string GetFilename ()\r
-       {\r
-               string tmpdir = Environment.GetEnvironmentVariable ("TMPDIR");\r
-               if (tmpdir == null || tmpdir.Length == 0) {\r
-                       return null;\r
-               }\r
-               \r
-               tmpdir = tmpdir.Replace ('\\', '/');\r
-               if (tmpdir [tmpdir.Length - 1] != '/')\r
-                       tmpdir += "/";\r
-               return tmpdir + "FileWebRequestTest.tmp";\r
-       }\r
-}\r
-\r
-}\r
+//
+// FileWebRequestTest.cs - NUnit Test Cases for System.Net.FileWebRequest
+//
+// Authors:
+//   Lawrence Pit (loz@cable.a2000.nl)
+//   Martin Willemoes Hansen (mwh@sysrq.dk)
+//   Gert Driesen (drieseng@users.sourceforge.net)
+//
+// (C) 2003 Martin Willemoes Hansen
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Net;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Security;
+using System.Security.Permissions;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Net
+{
+       [TestFixture]
+       public class FileWebRequestTest
+       {
+               private string _tempDirectory;
+               private string _tempFile;
+               private Uri _tempFileUri;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       _tempDirectory = Path.Combine (Path.GetTempPath (), "MonoTests.System.Net.FileWebRequestTest");
+                       _tempFile = Path.Combine (_tempDirectory, "FileWebRequestTest.tmp");
+                       if (!Directory.Exists (_tempDirectory)) {
+                               Directory.CreateDirectory (_tempDirectory);
+                       } else {
+                               // ensure no files are left over from previous runs
+                               string [] files = Directory.GetFiles (_tempDirectory, "*");
+                               foreach (string file in files)
+                                       File.Delete (file);
+                       }
+                       _tempFileUri = GetTempFileUri ();
+               }
+
+               [TearDown]
+               public void TearDown ()
+               {
+                       if (Directory.Exists (_tempDirectory)) {
+                               string [] files = Directory.GetFiles (_tempDirectory, "*");
+                               foreach (string file in files)
+                                       File.Delete (file);
+                               Directory.Delete (_tempDirectory, true);
+                       }
+               }
+
+               [Test]
+               public void Async ()
+               {
+                       WebResponse res = null;
+
+                       try {
+                               FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                               req.Method = "PUT";
+                               req.ContentLength = 1;
+                               req.ContentType = "image/png";
+
+                               req.Timeout = 2 * 1000;
+                               IAsyncResult async = req.BeginGetRequestStream (null, null);
+                               try {
+                                       req.BeginGetRequestStream (null, null);
+                                       Assert.Fail ("#1 should've failed");
+                               } catch (InvalidOperationException) {
+                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse while
+                                       // a previous call is still in progress
+                               }
+
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#3 should've failed");
+                               } catch (InvalidOperationException) {
+                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse while
+                                       // a previous call is still in progress
+                               }
+
+                               try {
+                                       req.GetResponse ();
+                                       Assert.Fail ("#4 should've failed");
+                               } catch (WebException) {
+                                       // The operation has timed out
+                               }
+
+                               try {
+                                       req.BeginGetResponse (null, null);
+                                       Assert.Fail ("#5 should've failed");
+                               } catch (InvalidOperationException) {
+                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse while
+                                       // a previous call is still in progress
+                               }
+
+                               Stream wstream = req.EndGetRequestStream (async);
+                               Assert.IsFalse (wstream.CanRead, "#1r");
+                               Assert.IsTrue (wstream.CanWrite, "#1w");
+                               Assert.IsTrue (wstream.CanSeek, "#1s");
+
+                               wstream.WriteByte (72);
+                               wstream.WriteByte (101);
+                               wstream.WriteByte (108);
+                               wstream.WriteByte (108);
+                               wstream.WriteByte (111);
+                               wstream.Close ();
+
+                               Assert.AreEqual (1, req.ContentLength, "#1cl");
+                               Assert.AreEqual ("image/png", req.ContentType, "#1ct");
+
+                               // stream written
+
+                               req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                               res = req.GetResponse ();
+
+                               try {
+                                       req.BeginGetRequestStream (null, null);
+                                       Assert.Fail ("#20: should've failed");
+                               } catch (InvalidOperationException) {
+                                       // Cannot send a content-body with this verb-type
+                               }
+
+                               try {
+                                       req.Method = "PUT";
+                                       req.BeginGetRequestStream (null, null);
+                                       Assert.Fail ("#21: should've failed");
+                               } catch (InvalidOperationException) {
+                                       // This operation cannot be perfomed after the request has been submitted.
+                               }
+
+                               req.GetResponse ();
+
+                               IAsyncResult async2 = req.BeginGetResponse (null, null);
+
+                               // this succeeds !!
+                               WebResponse res2 = req.EndGetResponse (async2);
+                               Assert.AreSame (res, res2, "#23");
+
+                               Assert.AreEqual (5, res.ContentLength, "#2 len");
+                               Assert.AreEqual ("application/octet-stream", res.ContentType, "#2 type");
+                               Assert.AreEqual ("file", res.ResponseUri.Scheme, "#2 scheme");
+
+                               Stream rstream = res.GetResponseStream ();
+                               Assert.IsTrue (rstream.CanRead, "#3r");
+                               Assert.IsFalse (rstream.CanWrite, "#3w");
+                               Assert.IsTrue (rstream.CanSeek, "#3s");
+
+                               Assert.AreEqual (72, rstream.ReadByte (), "#4a");
+                               Assert.AreEqual (101, rstream.ReadByte (), "#4b");
+                               Assert.AreEqual (108, rstream.ReadByte (), "#4c");
+                               Assert.AreEqual (108, rstream.ReadByte (), "#4d");
+                               Assert.AreEqual (111, rstream.ReadByte (), "#4e");
+
+                               rstream.Close ();
+
+                               try {
+                                       long len = res.ContentLength;
+                                       Assert.AreEqual ((long) 5, len, "#5");
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed contentlength");
+                               }
+                               try {
+                                       WebHeaderCollection w = res.Headers;
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed headers");
+                               }
+                               try {
+                                       res.Close ();
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed close");
+                               }
+                       } finally {
+                               if (res != null)
+                                       res.Close ();
+                       }
+               }
+
+               [Test]
+#if TARGET_JVM
+       [Ignore ("TD BUG ID: 7205")]
+       [Category ("NotWorking")]
+#endif 
+               public void Sync ()
+               {
+                       WebResponse res = null;
+
+                       try {
+                               FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                               req.ContentLength = 1;
+                               req.ContentType = "image/png";
+
+                               try {
+                                       Stream stream = req.GetRequestStream ();
+                                       Assert.Fail ("should throw exception");
+                               } catch (ProtocolViolationException) {
+                               }
+
+                               req.Method = "PUT";
+
+                               Stream wstream = req.GetRequestStream ();
+                               Assert.IsFalse (wstream.CanRead, "#1r");
+                               Assert.IsTrue (wstream.CanWrite, "#1w");
+                               Assert.IsTrue (wstream.CanSeek, "#1s");
+
+                               wstream.WriteByte (72);
+                               wstream.WriteByte (101);
+                               wstream.WriteByte (108);
+                               wstream.WriteByte (108);
+                               wstream.WriteByte (111);
+                               wstream.Close ();
+
+                               Assert.AreEqual (1, req.ContentLength, "#1cl");
+                               Assert.AreEqual ("image/png", req.ContentType, "#1ct");
+
+                               // stream written
+
+                               req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                               res = req.GetResponse ();
+                               Assert.AreEqual ((long) 5, res.ContentLength, "#2 len");
+                               Assert.AreEqual ("application/octet-stream", res.ContentType, "#2 type");
+                               Assert.AreEqual ("file", res.ResponseUri.Scheme, "#2 scheme");
+
+                               Stream rstream = res.GetResponseStream ();
+                               Assert.IsTrue (rstream.CanRead, "#3r");
+                               Assert.IsFalse (rstream.CanWrite, "#3w");
+                               Assert.IsTrue (rstream.CanSeek, "#3s");
+
+                               Assert.AreEqual (72, rstream.ReadByte (), "#4a");
+                               Assert.AreEqual (101, rstream.ReadByte (), "#4b");
+                               Assert.AreEqual (108, rstream.ReadByte (), "#4c");
+                               Assert.AreEqual (108, rstream.ReadByte (), "#4d");
+                               Assert.AreEqual (111, rstream.ReadByte (), "#4e");
+
+                               rstream.Close ();
+
+                               try {
+                                       long len = res.ContentLength;
+                                       Assert.AreEqual ((long) 5, len, "#5");
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed contentlength");
+                               }
+                               try {
+                                       WebHeaderCollection w = res.Headers;
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed headers");
+                               }
+                               try {
+                                       res.Close ();
+                               } catch (ObjectDisposedException) {
+                                       Assert.Fail ("#disposed close");
+                               }
+                       } finally {
+                               if (res != null)
+                                       res.Close ();
+                       }
+               }
+
+               [Test]
+               public void ConnectionGroupName ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.IsNull (req.ConnectionGroupName, "#A");
+                       req.ConnectionGroupName = "whatever";
+                       Assert.IsNotNull (req.ConnectionGroupName, "#B1");
+                       Assert.AreEqual ("whatever", req.ConnectionGroupName, "#B2");
+                       req.ConnectionGroupName = string.Empty;
+                       Assert.IsNotNull (req.ConnectionGroupName, "#C1");
+                       Assert.AreEqual (string.Empty, req.ConnectionGroupName, "#C2");
+                       req.ConnectionGroupName = null;
+                       Assert.IsNull (req.ConnectionGroupName, "#D");
+               }
+
+               [Test]
+               public void ContentLength ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.AreEqual (0, req.Headers.Count, "#A1");
+                       Assert.AreEqual (0, req.ContentLength, "#A2");
+                       req.ContentLength = 5;
+                       Assert.AreEqual (5, req.ContentLength, "#A3");
+                       Assert.AreEqual (0, req.Headers.Count, "#A4");
+
+                       req.Method = "PUT";
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (5);
+                               Assert.AreEqual (5, req.ContentLength, "#B1");
+                               s.WriteByte (4);
+                               Assert.AreEqual (5, req.ContentLength, "#B2");
+                               s.Flush ();
+                               Assert.AreEqual (5, req.ContentLength, "#B3");
+                       }
+                       Assert.AreEqual (5, req.ContentLength, "#B4");
+               }
+
+               [Test]
+               public void ContentLength_Negative ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       try {
+                               req.ContentLength = -1;
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+#if NET_2_0
+                               Assert.IsFalse (ex.Message == "value", "#4");
+#else
+                               Assert.AreEqual ("value", ex.Message, "#4");
+#endif
+#if !TARGET_JVM
+#if NET_2_0
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#else
+                               Assert.IsNull (ex.ParamName, "#5");
+#endif
+#endif
+                               Assert.IsNull (ex.InnerException, "#7");
+                       }
+               }
+
+               [Test]
+               public void ContentType ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.AreEqual (0, req.Headers.Count, "#A1");
+                       Assert.IsNull (req.ContentType, "#A2");
+
+                       req.ContentType = "application/x-gzip";
+                       Assert.AreEqual (1, req.Headers.Count, "#B1");
+                       Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#B2");
+                       Assert.AreEqual ("application/x-gzip", req.Headers.Get (0), "#B3");
+                       Assert.AreEqual ("application/x-gzip", req.ContentType, "#B4");
+
+                       req.Headers.Set ("Content-Type", "image/png");
+                       Assert.AreEqual ("image/png", req.ContentType, "#C1");
+
+                       req.ContentType = null;
+                       Assert.AreEqual (1, req.Headers.Count, "#D1");
+                       Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#D2");
+                       Assert.AreEqual (string.Empty, req.Headers.Get (0), "#D3");
+                       Assert.AreEqual (string.Empty, req.ContentType, "#D4");
+
+                       req.Headers.Remove ("Content-Type");
+                       Assert.AreEqual (0, req.Headers.Count, "#E1");
+                       Assert.IsNull (req.ContentType, "#E2");
+               }
+
+               [Test]
+               public void Credentials ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.IsNull (req.Credentials, "#1");
+                       req.Credentials = new NetworkCredential ();
+                       Assert.IsNotNull (req.Credentials, "#2");
+                       req.Credentials = null;
+                       Assert.IsNull (req.Credentials, "#3");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void GetRequestStream ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (
+                               _tempFileUri);
+                       req.Timeout = 1000;
+                       req.Method = "POST";
+                       FileStream fsA = null;
+                       FileStream fsB = null;
+                       try {
+                               fsA = req.GetRequestStream () as FileStream;
+                               Assert.IsNotNull (fsA, "#A1");
+#if NET_2_0
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#A2");
+                               } catch (WebException) {
+                                       // The operation has timed out
+                               }
+                               fsA.Close ();
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#A3");
+                               } catch (InvalidOperationException) {
+                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse 
+                                       // while a previous call is still in progress.
+                               }
+#else
+                               fsB = req.GetRequestStream () as FileStream;
+                               Assert.IsNotNull (fsB, "#A2");
+                               Assert.AreSame (fsA, fsB, "#A3");
+#endif
+                       } finally {
+                               if (fsA != null)
+                                       fsA.Close ();
+                               if (fsB != null)
+                                       fsB.Close ();
+                       }
+
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Timeout = 1000;
+                       req.Method = "POST";
+                       try {
+                               fsA = req.GetRequestStream () as FileStream;
+                               Assert.IsNotNull (fsA, "#B1");
+                               fsA.Close ();
+#if NET_2_0
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#B2");
+                               } catch (WebException) {
+                                       // The operation has timed out
+                               }
+                               fsA.Close ();
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#B3");
+                               } catch (InvalidOperationException) {
+                                       // Cannot re-call BeginGetRequestStream/BeginGetResponse 
+                                       // while a previous call is still in progress.
+                               }
+#else
+                               fsB = req.GetRequestStream () as FileStream;
+                               Assert.IsNotNull (fsB, "#B2");
+                               Assert.AreSame (fsA, fsB, "#B3");
+#endif
+                       } finally {
+                               if (fsA != null)
+                                       fsA.Close ();
+                               if (fsB != null)
+                                       fsB.Close ();
+                       }
+               }
+
+               [Test]
+               public void GetRequestStream_File_Exists ()
+               {
+                       Stream s = File.Create (_tempFile);
+                       s.Close ();
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (
+                               _tempFileUri);
+                       req.Method = "POST";
+                       s = req.GetRequestStream ();
+                       s.Close ();
+               }
+
+               [Test]
+               public void GetRequestStream_Method_Valid ()
+               {
+                       string [] methods = new string [] { "PUT", "POST", "CHECKOUT",
+                               "DELETE", "OPTIONS", "TRACE", "GET ", "DUNNO" };
+
+                       foreach (string method in methods) {
+                               FileWebRequest req = (FileWebRequest) WebRequest.Create (
+                                       _tempFileUri);
+                               req.Method = method;
+                               using (Stream s = req.GetRequestStream ()) {
+                                       Assert.IsNotNull (s, "#1:" + method);
+                                       Assert.IsFalse (s.CanRead, "#2:" + method);
+                                       Assert.IsTrue (s.CanSeek, "#3:" + method);
+#if NET_2_0
+                                       Assert.IsFalse (s.CanTimeout, "#4:" + method);
+#endif
+                                       Assert.IsTrue (s.CanWrite, "#5:" + method);
+                                       Assert.AreEqual (0, s.Length, "#6:" + method);
+                                       Assert.AreEqual (0, s.Position, "#7:" + method);
+#if NET_2_0
+                                       try {
+                                               int i = s.ReadTimeout;
+                                               Assert.Fail ("#8:" + method + "=>" + i);
+                                       } catch (InvalidOperationException) {
+                                       }
+                                       try {
+                                               int i = s.WriteTimeout;
+                                               Assert.Fail ("#9:" + method + "=>" + i);
+                                       } catch (InvalidOperationException) {
+                                       }
+#endif
+                               }
+                       }
+               }
+
+               [Test]
+               public void GetRequestStream_Method_Invalid ()
+               {
+                       string [] methods = new string [] { "GET", "get", "HEAD", "head",
+                               "CONNECT", "connect"};
+                       foreach (string method in methods) {
+                               FileWebRequest req = (FileWebRequest) WebRequest.Create (
+                                       _tempFileUri);
+                               req.Method = method;
+                               try {
+                                       req.GetRequestStream ();
+                                       Assert.Fail ("#1:" + method);
+                               } catch (ProtocolViolationException ex) {
+                                       Assert.AreEqual (typeof (ProtocolViolationException), ex.GetType (), "#2:" + method);
+                                       Assert.IsNotNull (ex.Message, "#3:" + method);
+                                       Assert.IsNull (ex.InnerException, "#4:" + method);
+                               }
+                       }
+               }
+
+               [Test]
+               public void GetResponse_File_Exists ()
+               {
+                       Stream s = File.Create (_tempFile);
+                       s.Close ();
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       FileWebResponse respA = null;
+                       FileWebResponse respB = null;
+                       try {
+                               respA = req.GetResponse () as FileWebResponse;
+                               Assert.IsNotNull (respA, "#1");
+                               respB = req.GetResponse () as FileWebResponse;
+                               Assert.IsNotNull (respB, "#2");
+                               Assert.AreSame (respA, respB, "#3");
+                       } finally {
+                               if (respA != null)
+                                       respA.Close ();
+                               if (respB != null)
+                                       respB.Close ();
+                       }
+               }
+
+               [Test]
+               public void GetResponse_File_DoesNotExist ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       try {
+                               req.GetResponse ();
+                               Assert.Fail ("#1");
+                       } catch (WebException ex) {
+                               Assert.AreEqual (typeof (WebException), ex.GetType (), "#1");
+                               Assert.IsNotNull (ex.Message, "#2");
+                               Assert.IsTrue (ex.Message.IndexOf ("FileWebRequestTest.tmp") != -1, "#3");
+                               Assert.IsNull (ex.Response, "#4");
+                               Assert.IsNotNull (ex.InnerException, "#5");
+
+#if ONLY_1_1
+                               FileNotFoundException fnf = ex.InnerException as FileNotFoundException;
+                               Assert.IsNotNull (fnf, "#6");
+                               Assert.AreEqual (typeof (FileNotFoundException), fnf.GetType (), "#7");
+                               Assert.IsNotNull (fnf.FileName, "#8");
+                               Assert.IsTrue (fnf.FileName.IndexOf ("FileWebRequestTest.tmp") != -1, "#9");
+                               Assert.IsNotNull (fnf.Message, "#10");
+                               Assert.IsTrue (fnf.Message.IndexOf ("FileWebRequestTest.tmp") != -1, "#11");
+                               Assert.IsNull (fnf.InnerException, "#12");
+#endif
+                       }
+               }
+
+               [Test]
+               public void Method ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.IsNotNull (req.Method, "#A1");
+                       Assert.AreEqual ("GET", req.Method, "#A2");
+                       req.Method = "whatever";
+                       Assert.IsNotNull (req.Method, "#B1");
+                       Assert.AreEqual ("whatever", req.Method, "#B2");
+                       req.Method = "get ";
+                       Assert.IsNotNull (req.Method, "#C1");
+                       Assert.AreEqual ("get ", req.Method, "#C2");
+               }
+
+               [Test]
+               public void Method_Empty ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       try {
+                               req.Method = string.Empty;
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+#if !TARGET_JVM
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#4");
+#else
+                               Assert.IsNull (ex.ParamName, "#4");
+#endif
+#endif
+                               Assert.IsNull (ex.InnerException, "#5");
+                       }
+               }
+
+               [Test]
+               public void Method_Null ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       try {
+                               req.Method = null;
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNotNull (ex.Message, "#3");
+#if !TARGET_JVM
+#if NET_2_0
+                               Assert.AreEqual ("value", ex.ParamName, "#4");
+#else
+                               Assert.IsNull (ex.ParamName, "#4");
+#endif
+#endif
+                               Assert.IsNull (ex.InnerException, "#5");
+                       }
+               }
+
+               [Test]
+               public void PreAuthenticate ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.IsFalse (req.PreAuthenticate, "#1");
+                       req.PreAuthenticate = true;
+                       Assert.IsTrue (req.PreAuthenticate, "#2");
+               }
+
+               [Test]
+               public void Proxy ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.IsNull (req.Proxy, "#1");
+                       req.Proxy = new WebProxy ();
+                       Assert.IsNotNull (req.Proxy, "#2");
+                       req.Proxy = null;
+                       Assert.IsNull (req.Proxy, "#3");
+               }
+
+               [Test]
+               public void RequestUri ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.AreSame (_tempFileUri, req.RequestUri);
+               }
+
+               [Test]
+               public void Timeout ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       Assert.AreEqual (100000, req.Timeout, "#1");
+                       req.Timeout = int.MaxValue;
+                       Assert.AreEqual (int.MaxValue, req.Timeout, "#2");
+                       req.Timeout = 0;
+                       Assert.AreEqual (0, req.Timeout, "#3");
+               }
+
+               [Test]
+               public void Timeout_Negative ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Timeout = -1;
+                       Assert.AreEqual (-1, req.Timeout, "#1");
+                       try {
+                               req.Timeout = -2;
+                               Assert.Fail ("#2");
+                       } catch (ArgumentOutOfRangeException ex) {
+                               Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+#if !TARGET_JVM
+                               Assert.IsNotNull (ex.ParamName, "#5");
+#if NET_2_0
+                               Assert.IsFalse (ex.ParamName == "value", "#6");
+#else
+                               Assert.AreEqual ("value", ex.ParamName, "#6");
+#endif
+#endif
+                               Assert.IsNull (ex.InnerException, "#7");
+                       }
+               }
+
+               [Test]
+               public void GetObjectData ()
+               {
+                       FileWebRequest fwr = (FileWebRequest) WebRequest.Create ("file:///test.txt");
+                       fwr.ConnectionGroupName = "CGN";
+                       fwr.ContentLength = 10;
+                       fwr.ContentType = "image/png";
+                       fwr.Credentials = new NetworkCredential ("Miguel", "de Icaza", "Novell");
+                       fwr.Headers.Add ("Disposition", "attach");
+                       fwr.Method = "PUT";
+                       fwr.PreAuthenticate = true;
+                       fwr.Proxy = new WebProxy ("proxy.ximian.com");
+                       fwr.Timeout = 20;
+
+                       SerializationInfo si = new SerializationInfo (typeof (FileWebRequest),
+                               new FormatterConverter ());
+                       ((ISerializable) fwr).GetObjectData (si, new StreamingContext ());
+                       Assert.AreEqual (9, si.MemberCount, "#A1");
+                       int i = 0;
+                       foreach (SerializationEntry entry in si) {
+                               Assert.IsNotNull (entry.Name, "#B1:" + i);
+                               Assert.IsNotNull (entry.ObjectType, "#B2:" + i);
+                               Assert.IsNotNull (entry.Value, "#B3:" + i);
+
+                               switch (i) {
+                               case 0:
+                                       Assert.AreEqual ("headers", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (WebHeaderCollection), entry.ObjectType, "#B5:" + i);
+                                       break;
+                               case 1:
+                                       Assert.AreEqual ("proxy", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (IWebProxy), entry.ObjectType, "#B5:" + i);
+                                       break;
+                               case 2:
+                                       Assert.AreEqual ("uri", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (Uri), entry.ObjectType, "#B5:" + i);
+                                       break;
+                               case 3:
+                                       Assert.AreEqual ("connectionGroupName", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
+                                       Assert.AreEqual ("CGN", entry.Value, "#B6:" + i);
+                                       break;
+                               case 4:
+                                       Assert.AreEqual ("method", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
+                                       Assert.AreEqual ("PUT", entry.Value, "#B6:" + i);
+                                       break;
+                               case 5:
+                                       Assert.AreEqual ("contentLength", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (long), entry.ObjectType, "#B5:" + i);
+                                       Assert.AreEqual (10, entry.Value, "#B6:" + i);
+                                       break;
+                               case 6:
+                                       Assert.AreEqual ("timeout", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (int), entry.ObjectType, "#B5:" + i);
+                                       Assert.AreEqual (20, entry.Value, "#B6:" + i);
+                                       break;
+                               case 7:
+                                       Assert.AreEqual ("fileAccess", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (FileAccess), entry.ObjectType, "#B5:" + i);
+                                       Assert.AreEqual (FileAccess.Read, entry.Value, "#B6:" + i);
+                                       break;
+                               case 8:
+                                       Assert.AreEqual ("preauthenticate", entry.Name, "#B4:" + i);
+                                       Assert.AreEqual (typeof (bool), entry.ObjectType, "#B5:" + i);
+#if NET_2_0
+                                       Assert.AreEqual (false, entry.Value, "#B6:" + i);
+#else
+                                       Assert.AreEqual (true, entry.Value, "#B6:" + i);
+#endif
+                                       break;
+                               }
+                               i++;
+                       }
+               }
+
+               [Test]
+               [Category ("NotWorking")] // Difference at index 272: 20 instead of 19
+               public void Serialize ()
+               {
+                       FileWebRequest fwr = (FileWebRequest) WebRequest.Create ("file://test.txt/");
+                       fwr.ConnectionGroupName = "CGN";
+                       fwr.ContentLength = 10;
+                       fwr.ContentType = "image/png";
+                       fwr.Credentials = new NetworkCredential ("Miguel", "de Icaza", "Novell");
+                       fwr.Headers.Add ("Disposition", "attach");
+                       fwr.Method = "PUT";
+                       fwr.PreAuthenticate = true;
+                       fwr.Proxy = new WebProxy ("proxy.ximian.com");
+                       fwr.Timeout = 20;
+
+                       BinaryFormatter bf = new BinaryFormatter ();
+                       bf.AssemblyFormat = FormatterAssemblyStyle.Full;
+
+                       MemoryStream ms = new MemoryStream ();
+                       bf.Serialize (ms, fwr);
+                       ms.Position = 0;
+
+                       byte [] buffer = new byte [ms.Length];
+                       ms.Read (buffer, 0, buffer.Length);
+                       Assert.AreEqual (_serialized, buffer);
+               }
+
+               [Test]
+               public void Deserialize ()
+               {
+                       MemoryStream ms = new MemoryStream ();
+                       ms.Write (_serialized, 0, _serialized.Length);
+                       ms.Position = 0;
+
+                       BinaryFormatter bf = new BinaryFormatter ();
+                       FileWebRequest req = (FileWebRequest) bf.Deserialize (ms);
+                       Assert.AreEqual ("CGN", req.ConnectionGroupName, "#A1");
+                       Assert.AreEqual (10, req.ContentLength, "#A2");
+                       Assert.AreEqual ("image/png", req.ContentType, "#A3");
+                       Assert.IsNull (req.Credentials, "#A4");
+                       Assert.AreEqual ("PUT", req.Method, "#A5");
+#if NET_2_0
+                       Assert.IsFalse (req.PreAuthenticate, "#A6");
+#else
+                       Assert.IsTrue (req.PreAuthenticate, "#A6");
+#endif
+                       Assert.AreEqual ("file://test.txt/", req.RequestUri.AbsoluteUri, "#A7");
+                       Assert.AreEqual (20, req.Timeout, "#A8");
+
+                       WebHeaderCollection headers = req.Headers;
+                       Assert.IsNotNull (headers, "#C1");
+                       Assert.AreEqual (2, headers.Count, "#C2");
+                       Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#C3");
+                       Assert.AreEqual ("image/png", req.Headers.Get (0), "#C4");
+                       Assert.AreEqual ("Disposition", req.Headers.GetKey (1), "#C5");
+                       Assert.AreEqual ("attach", req.Headers.Get (1), "#C6");
+
+                       WebProxy proxy = req.Proxy as WebProxy;
+                       Assert.IsNotNull (proxy, "#D1");
+                       Assert.AreEqual ("http://proxy.ximian.com/", proxy.Address.AbsoluteUri, "#D2");
+                       Assert.IsNotNull (proxy.BypassArrayList, "#D3");
+                       Assert.AreEqual (0, proxy.BypassArrayList.Count, "#D4");
+                       Assert.IsNotNull (proxy.BypassList, "#D5");
+                       Assert.AreEqual (0, proxy.BypassList.Length, "#D6");
+                       Assert.IsFalse (proxy.BypassProxyOnLocal, "#D7");
+                       Assert.IsNull (proxy.Credentials, "#D8");
+               }
+
+               private Uri GetTempFileUri ()
+               {
+                       string tempFile = _tempFile;
+                       if (RunningOnUnix) {
+                               // remove leading slash for absolute paths
+                               tempFile = tempFile.TrimStart ('/');
+                       } else {
+                               tempFile = tempFile.Replace ('\\', '/');
+                       }
+                       return new Uri ("file:///" + tempFile);
+               }
+
+               private bool RunningOnUnix {
+                       get {
+                               // check for Unix platforms - see FAQ for more details
+                               // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
+                               int platform = (int) Environment.OSVersion.Platform;
+                               return ((platform == 4) || (platform == 128));
+                       }
+               }
+
+               private static readonly byte [] _serialized = new byte [] {
+#if NET_2_0
+                       0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
+                       0x49, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
+                       0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30,
+                       0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65,
+                       0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50,
+                       0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b,
+                       0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36,
+                       0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x05, 0x01, 0x00,
+                       0x00, 0x00, 0x19, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e,
+                       0x65, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x57, 0x65, 0x62, 0x52,
+                       0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x09, 0x00, 0x00, 0x00, 0x07,
+                       0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x05, 0x70, 0x72, 0x6f,
+                       0x78, 0x79, 0x03, 0x75, 0x72, 0x69, 0x13, 0x63, 0x6f, 0x6e, 0x6e,
+                       0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70,
+                       0x4e, 0x61, 0x6d, 0x65, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64,
+                       0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x4c, 0x65, 0x6e,
+                       0x67, 0x74, 0x68, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74,
+                       0x0a, 0x66, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73,
+                       0x0f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74,
+                       0x69, 0x63, 0x61, 0x74, 0x65, 0x04, 0x04, 0x04, 0x01, 0x01, 0x00,
+                       0x00, 0x03, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e,
+                       0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65, 0x61, 0x64,
+                       0x65, 0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f,
+                       0x6e, 0x02, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x50, 0x72,
+                       0x6f, 0x78, 0x79, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x53, 0x79, 0x73,
+                       0x74, 0x65, 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02, 0x00, 0x00, 0x00,
+                       0x09, 0x08, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x49,
+                       0x4f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73,
+                       0x73, 0x01, 0x02, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00,
+                       0x09, 0x04, 0x00, 0x00, 0x00, 0x09, 0x05, 0x00, 0x00, 0x00, 0x06,
+                       0x06, 0x00, 0x00, 0x00, 0x03, 0x43, 0x47, 0x4e, 0x06, 0x07, 0x00,
+                       0x00, 0x00, 0x03, 0x50, 0x55, 0x54, 0x0a, 0x00, 0x00, 0x00, 0x00,
+                       0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0xf8, 0xff, 0xff,
+                       0xff, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x49, 0x4f,
+                       0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73,
+                       0x01, 0x00, 0x00, 0x00, 0x07, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f,
+                       0x5f, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00,
+                       0x00, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e,
+                       0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65, 0x61, 0x64, 0x65,
+                       0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
+                       0x05, 0x00, 0x00, 0x00, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x01,
+                       0x30, 0x01, 0x32, 0x01, 0x31, 0x01, 0x33, 0x00, 0x01, 0x01, 0x01,
+                       0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06,
+                       0x09, 0x00, 0x00, 0x00, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
+                       0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x06, 0x0a, 0x00, 0x00, 0x00,
+                       0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x06,
+                       0x0b, 0x00, 0x00, 0x00, 0x0b, 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73,
+                       0x69, 0x74, 0x69, 0x6f, 0x6e, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x06,
+                       0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x05, 0x04, 0x00, 0x00, 0x00,
+                       0x13, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e, 0x65, 0x74,
+                       0x2e, 0x57, 0x65, 0x62, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x04, 0x00,
+                       0x00, 0x00, 0x0e, 0x5f, 0x42, 0x79, 0x70, 0x61, 0x73, 0x73, 0x4f,
+                       0x6e, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x0d, 0x5f, 0x50, 0x72, 0x6f,
+                       0x78, 0x79, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x0b, 0x5f,
+                       0x42, 0x79, 0x70, 0x61, 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x16,
+                       0x5f, 0x55, 0x73, 0x65, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
+                       0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73,
+                       0x00, 0x04, 0x02, 0x00, 0x01, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02, 0x00, 0x00, 0x00, 0x01, 0x02,
+                       0x00, 0x00, 0x00, 0x00, 0x09, 0x0d, 0x00, 0x00, 0x00, 0x0a, 0x00,
+                       0x05, 0x05, 0x00, 0x00, 0x00, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x55, 0x72, 0x69, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x41,
+                       0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x55, 0x72, 0x69, 0x01,
+                       0x02, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x66,
+                       0x69, 0x6c, 0x65, 0x3a, 0x2f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e,
+                       0x74, 0x78, 0x74, 0x2f, 0x01, 0x0d, 0x00, 0x00, 0x00, 0x05, 0x00,
+                       0x00, 0x00, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x18, 0x68, 0x74, 0x74,
+                       0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x78,
+                       0x69, 0x6d, 0x69, 0x61, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x0b
+#else
+                       0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
+                       0x4c, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
+                       0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x31, 0x2e, 0x30, 0x2e, 0x35,
+                       0x30, 0x30, 0x30, 0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74,
+                       0x75, 0x72, 0x65, 0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c,
+                       0x2c, 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79,
+                       0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35,
+                       0x63, 0x35, 0x36, 0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39,
+                       0x05, 0x01, 0x00, 0x00, 0x00, 0x19, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x57,
+                       0x65, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x09, 0x00,
+                       0x00, 0x00, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x05,
+                       0x70, 0x72, 0x6f, 0x78, 0x79, 0x03, 0x75, 0x72, 0x69, 0x13, 0x63,
+                       0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x47, 0x72,
+                       0x6f, 0x75, 0x70, 0x4e, 0x61, 0x6d, 0x65, 0x06, 0x6d, 0x65, 0x74,
+                       0x68, 0x6f, 0x64, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
+                       0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x07, 0x74, 0x69, 0x6d, 0x65,
+                       0x6f, 0x75, 0x74, 0x0a, 0x66, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63,
+                       0x65, 0x73, 0x73, 0x0f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68,
+                       0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x65, 0x04, 0x04, 0x04,
+                       0x01, 0x01, 0x00, 0x00, 0x03, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74,
+                       0x65, 0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48,
+                       0x65, 0x61, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63,
+                       0x74, 0x69, 0x6f, 0x6e, 0x02, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79,
+                       0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65,
+                       0x62, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x02, 0x00, 0x00, 0x00, 0x0a,
+                       0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02,
+                       0x00, 0x00, 0x00, 0x09, 0x08, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x49, 0x4f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63,
+                       0x63, 0x65, 0x73, 0x73, 0x01, 0x02, 0x00, 0x00, 0x00, 0x09, 0x03,
+                       0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0x09, 0x05, 0x00,
+                       0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, 0x03, 0x43, 0x47, 0x4e,
+                       0x06, 0x07, 0x00, 0x00, 0x00, 0x03, 0x50, 0x55, 0x54, 0x0a, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04,
+                       0xf8, 0xff, 0xff, 0xff, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
+                       0x2e, 0x49, 0x4f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63,
+                       0x65, 0x73, 0x73, 0x01, 0x00, 0x00, 0x00, 0x07, 0x76, 0x61, 0x6c,
+                       0x75, 0x65, 0x5f, 0x5f, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x01,
+                       0x05, 0x03, 0x00, 0x00, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65,
+                       0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65,
+                       0x61, 0x64, 0x65, 0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74,
+                       0x69, 0x6f, 0x6e, 0x05, 0x00, 0x00, 0x00, 0x05, 0x43, 0x6f, 0x75,
+                       0x6e, 0x74, 0x01, 0x30, 0x01, 0x32, 0x01, 0x31, 0x01, 0x33, 0x00,
+                       0x01, 0x01, 0x01, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00,
+                       0x00, 0x00, 0x06, 0x09, 0x00, 0x00, 0x00, 0x0c, 0x43, 0x6f, 0x6e,
+                       0x74, 0x65, 0x6e, 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x06, 0x0a,
+                       0x00, 0x00, 0x00, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70,
+                       0x6e, 0x67, 0x06, 0x0b, 0x00, 0x00, 0x00, 0x0b, 0x44, 0x69, 0x73,
+                       0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x06, 0x0c, 0x00,
+                       0x00, 0x00, 0x06, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x05, 0x04,
+                       0x00, 0x00, 0x00, 0x13, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e,
+                       0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x50, 0x72, 0x6f, 0x78,
+                       0x79, 0x03, 0x00, 0x00, 0x00, 0x0e, 0x5f, 0x42, 0x79, 0x70, 0x61,
+                       0x73, 0x73, 0x4f, 0x6e, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x0d, 0x5f,
+                       0x50, 0x72, 0x6f, 0x78, 0x79, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73,
+                       0x73, 0x0b, 0x5f, 0x42, 0x79, 0x70, 0x61, 0x73, 0x73, 0x4c, 0x69,
+                       0x73, 0x74, 0x00, 0x04, 0x02, 0x01, 0x0a, 0x53, 0x79, 0x73, 0x74,
+                       0x65, 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02, 0x00, 0x00, 0x00, 0x02,
+                       0x00, 0x00, 0x00, 0x00, 0x09, 0x0d, 0x00, 0x00, 0x00, 0x0a, 0x05,
+                       0x05, 0x00, 0x00, 0x00, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d,
+                       0x2e, 0x55, 0x72, 0x69, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x41, 0x62,
+                       0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x55, 0x72, 0x69, 0x01, 0x02,
+                       0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x66, 0x69,
+                       0x6c, 0x65, 0x3a, 0x2f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x74,
+                       0x78, 0x74, 0x2f, 0x01, 0x0d, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
+                       0x00, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x18, 0x68, 0x74, 0x74, 0x70,
+                       0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x78, 0x69,
+                       0x6d, 0x69, 0x61, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x0b
+#endif
+               };
+       }
+}
diff --git a/mcs/class/System/Test/System.Net/FileWebResponseTest.cs b/mcs/class/System/Test/System.Net/FileWebResponseTest.cs
new file mode 100644 (file)
index 0000000..4dc99df
--- /dev/null
@@ -0,0 +1,232 @@
+//
+// FileWebResponseTest.cs - NUnit Test Cases for System.Net.FileWebResponse
+//
+// Authors:
+//   Gert Driesen (drieseng@users.sourceforge.net)
+//
+// (C) 2007 Gert Driesen
+//
+
+using System;
+using System.IO;
+using System.Net;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Net
+{
+       [TestFixture]
+       public class FileWebResponseTest
+       {
+               private string _tempDirectory;
+               private string _tempFile;
+               private Uri _tempFileUri;
+
+               [SetUp]
+               public void SetUp ()
+               {
+                       _tempDirectory = Path.Combine (Path.GetTempPath (), "MonoTests.System.Net.FileWebResponseTest");
+                       _tempFile = Path.Combine (_tempDirectory, "FileWebResponseTest.tmp");
+                       if (!Directory.Exists (_tempDirectory)) {
+                               Directory.CreateDirectory (_tempDirectory);
+                       } else {
+                               // ensure no files are left over from previous runs
+                               string [] files = Directory.GetFiles (_tempDirectory, "*");
+                               foreach (string file in files)
+                                       File.Delete (file);
+                       }
+                       _tempFileUri = GetTempFileUri ();
+               }
+
+               [TearDown]
+               public void TearDown ()
+               {
+                       if (Directory.Exists (_tempDirectory)) {
+                               string [] files = Directory.GetFiles (_tempDirectory, "*");
+                               foreach (string file in files)
+                                       File.Delete (file);
+                               Directory.Delete (_tempDirectory, true);
+                       }
+               }
+
+               [Test]
+               public void ContentLength ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Method = "PUT";
+                       req.ContentLength = 100;
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (72);
+                               s.WriteByte (110);
+                               s.WriteByte (80);
+                               s.Flush ();
+                       }
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       using (FileWebResponse resp = (FileWebResponse) req.GetResponse ()) {
+                               Assert.AreEqual (3, resp.ContentLength, "#1");
+                               Assert.AreEqual (2, resp.Headers.Count, "#2");
+                               Assert.AreEqual ("Content-Length", resp.Headers.Keys [0], "#3");
+                               Assert.AreEqual ("3", resp.Headers.Get (0), "#4");
+                               resp.Headers.Clear ();
+                               Assert.AreEqual (3, resp.ContentLength, "#5");
+                               Assert.AreEqual (0, resp.Headers.Count, "#6");
+                       }
+               }
+
+               [Test]
+               public void ContentType ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Method = "PUT";
+                       req.ContentType = "image/png";
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (72);
+                               s.WriteByte (110);
+                               s.WriteByte (80);
+                               s.Flush ();
+                       }
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       using (FileWebResponse resp = (FileWebResponse) req.GetResponse ()) {
+                               Assert.AreEqual ("application/octet-stream", resp.ContentType, "#1");
+                               Assert.AreEqual (2, resp.Headers.Count, "#2");
+                               Assert.AreEqual ("Content-Type", resp.Headers.Keys [1], "#3");
+                               Assert.AreEqual ("application/octet-stream", resp.Headers.Get (1), "#4");
+                               resp.Headers.Clear ();
+                               Assert.AreEqual ("application/octet-stream", resp.ContentType, "#5");
+                               Assert.AreEqual (0, resp.Headers.Count, "#6");
+                       }
+               }
+
+               [Test]
+               public void GetResponseStream ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Method = "PUT";
+                       req.ContentType = "image/png";
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (72);
+                               s.WriteByte (110);
+                               s.WriteByte (80);
+                               s.Flush ();
+                       }
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       FileWebResponse respA = null;
+                       FileWebResponse respB = null;
+                       FileStream fsA = null;
+                       FileStream fsB = null;
+                       try {
+                               respA = (FileWebResponse) req.GetResponse ();
+                               fsA = respA.GetResponseStream () as FileStream;
+                               Assert.IsNotNull (fsA, "#A1");
+                               Assert.IsTrue (fsA.CanRead, "#A2");
+                               Assert.IsTrue (fsA.CanSeek, "#A3");
+#if NET_2_0
+                               Assert.IsFalse (fsA.CanTimeout, "#A4");
+#endif
+                               Assert.IsFalse (fsA.CanWrite, "#A5");
+                               Assert.AreEqual (3, fsA.Length, "#A6");
+                               Assert.AreEqual (0, fsA.Position, "#A7");
+#if NET_2_0
+                               try {
+                                       int i = fsA.ReadTimeout;
+                                       Assert.Fail ("#A8:" + i);
+                               } catch (InvalidOperationException) {
+                               }
+                               try {
+                                       int i = fsA.WriteTimeout;
+                                       Assert.Fail ("#A9:" + i);
+                               } catch (InvalidOperationException) {
+                               }
+#endif
+
+                               respB = (FileWebResponse) req.GetResponse ();
+                               fsB = respB.GetResponseStream () as FileStream;
+                               Assert.IsNotNull (fsB, "#B1");
+                               Assert.IsTrue (fsB.CanRead, "#B2");
+                               Assert.IsTrue (fsB.CanSeek, "#B3");
+#if NET_2_0
+                               Assert.IsFalse (fsB.CanTimeout, "#B4");
+#endif
+                               Assert.IsFalse (fsB.CanWrite, "#B5");
+                               Assert.AreEqual (3, fsB.Length, "#B6");
+                               Assert.AreEqual (0, fsB.Position, "#B7");
+#if NET_2_0
+                               try {
+                                       int i = fsB.ReadTimeout;
+                                       Assert.Fail ("#B8:" + i);
+                               } catch (InvalidOperationException) {
+                               }
+                               try {
+                                       int i = fsB.WriteTimeout;
+                                       Assert.Fail ("#B9:" + i);
+                               } catch (InvalidOperationException) {
+                               }
+#endif
+                       } finally {
+                               if (respA != null)
+                                       respA.Close ();
+                               if (respB != null)
+                                       respB.Close ();
+                       }
+               }
+
+               [Test]
+               public void Headers ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Method = "PUT";
+                       req.Headers.Add ("Disposition", "attach");
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (72);
+                               s.WriteByte (110);
+                               s.WriteByte (80);
+                               s.Flush ();
+                       }
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       using (FileWebResponse resp = (FileWebResponse) req.GetResponse ()) {
+                               Assert.AreEqual (2, resp.Headers.Count, "#1");
+                               Assert.AreEqual ("Content-Length", resp.Headers.Keys [0], "#2");
+                               Assert.AreEqual ("Content-Type", resp.Headers.Keys [1], "#3");
+                       }
+               }
+
+               [Test]
+               public void ResponseUri ()
+               {
+                       FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       req.Method = "PUT";
+                       req.ContentType = "image/png";
+                       using (Stream s = req.GetRequestStream ()) {
+                               s.WriteByte (72);
+                               s.WriteByte (110);
+                               s.WriteByte (80);
+                               s.Flush ();
+                       }
+                       req = (FileWebRequest) WebRequest.Create (_tempFileUri);
+                       using (FileWebResponse resp = (FileWebResponse) req.GetResponse ()) {
+                               Assert.AreEqual (_tempFileUri, resp.ResponseUri);
+                       }
+               }
+
+               private Uri GetTempFileUri ()
+               {
+                       string tempFile = _tempFile;
+                       if (RunningOnUnix) {
+                               // remove leading slash for absolute paths
+                               tempFile = tempFile.TrimStart ('/');
+                       } else {
+                               tempFile = tempFile.Replace ('\\', '/');
+                       }
+                       return new Uri ("file:///" + tempFile);
+               }
+
+               private bool RunningOnUnix {
+                       get {
+                               // check for Unix platforms - see FAQ for more details
+                               // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
+                               int platform = (int) Environment.OSVersion.Platform;
+                               return ((platform == 4) || (platform == 128));
+                       }
+               }
+       }
+}