2 // FileWebRequestTest.cs - NUnit Test Cases for System.Net.FileWebRequest
5 // Lawrence Pit (loz@cable.a2000.nl)
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 // Gert Driesen (drieseng@users.sourceforge.net)
9 // (C) 2003 Martin Willemoes Hansen
13 using System.Collections;
16 using System.Runtime.Serialization;
17 using System.Runtime.Serialization.Formatters;
18 using System.Runtime.Serialization.Formatters.Binary;
19 using System.Security;
20 using System.Security.Permissions;
22 using NUnit.Framework;
25 namespace MonoTests.System.Net
28 [Category ("RequiresBSDSockets")]
29 public class FileWebRequestTest
31 private string _tempDirectory;
32 private string _tempFile;
33 private Uri _tempFileUri;
38 _tempDirectory = Path.Combine (Path.GetTempPath (), "MonoTests.System.Net.FileWebRequestTest");
39 _tempFile = Path.Combine (_tempDirectory, "FileWebRequestTest.tmp");
40 if (!Directory.Exists (_tempDirectory)) {
41 Directory.CreateDirectory (_tempDirectory);
43 // ensure no files are left over from previous runs
44 string [] files = Directory.GetFiles (_tempDirectory, "*");
45 foreach (string file in files)
48 _tempFileUri = GetTempFileUri ();
52 public void TearDown ()
54 if (Directory.Exists (_tempDirectory))
55 Directory.Delete (_tempDirectory, true);
61 WebResponse res = null;
64 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
66 req.ContentLength = 1;
67 req.ContentType = "image/png";
69 req.Timeout = 2 * 1000;
70 IAsyncResult async = req.BeginGetRequestStream (null, null);
72 req.BeginGetRequestStream (null, null);
73 Assert.Fail ("#1 should've failed");
74 } catch (InvalidOperationException) {
75 // Cannot re-call BeginGetRequestStream/BeginGetResponse while
76 // a previous call is still in progress
80 req.GetRequestStream ();
81 Assert.Fail ("#3 should've failed");
82 } catch (InvalidOperationException) {
83 // Cannot re-call BeginGetRequestStream/BeginGetResponse while
84 // a previous call is still in progress
87 using (Stream wstream = req.EndGetRequestStream (async)) {
88 Assert.IsFalse (wstream.CanRead, "#1r");
89 Assert.IsTrue (wstream.CanWrite, "#1w");
90 Assert.IsTrue (wstream.CanSeek, "#1s");
92 wstream.WriteByte (72);
93 wstream.WriteByte (101);
94 wstream.WriteByte (108);
95 wstream.WriteByte (108);
96 wstream.WriteByte (111);
100 Assert.AreEqual (1, req.ContentLength, "#1cl");
101 Assert.AreEqual ("image/png", req.ContentType, "#1ct");
105 req = (FileWebRequest) WebRequest.Create (_tempFileUri);
106 res = req.GetResponse ();
109 req.BeginGetRequestStream (null, null);
110 Assert.Fail ("#20: should've failed");
111 } catch (InvalidOperationException) {
112 // Cannot send a content-body with this verb-type
117 req.BeginGetRequestStream (null, null);
118 Assert.Fail ("#21: should've failed");
119 } catch (InvalidOperationException) {
120 // This operation cannot be perfomed after the request has been submitted.
125 IAsyncResult async2 = req.BeginGetResponse (null, null);
128 WebResponse res2 = req.EndGetResponse (async2);
129 Assert.AreSame (res, res2, "#23");
131 Assert.AreEqual (5, res.ContentLength, "#2 len");
132 Assert.AreEqual ("application/octet-stream", res.ContentType, "#2 type");
133 Assert.AreEqual ("file", res.ResponseUri.Scheme, "#2 scheme");
135 Stream rstream = res.GetResponseStream ();
136 Assert.IsTrue (rstream.CanRead, "#3r");
137 Assert.IsFalse (rstream.CanWrite, "#3w");
138 Assert.IsTrue (rstream.CanSeek, "#3s");
140 Assert.AreEqual (72, rstream.ReadByte (), "#4a");
141 Assert.AreEqual (101, rstream.ReadByte (), "#4b");
142 Assert.AreEqual (108, rstream.ReadByte (), "#4c");
143 Assert.AreEqual (108, rstream.ReadByte (), "#4d");
144 Assert.AreEqual (111, rstream.ReadByte (), "#4e");
149 long len = res.ContentLength;
150 Assert.AreEqual ((long) 5, len, "#5");
151 } catch (ObjectDisposedException) {
152 Assert.Fail ("#disposed contentlength");
155 WebHeaderCollection w = res.Headers;
156 } catch (ObjectDisposedException) {
157 Assert.Fail ("#disposed headers");
161 } catch (ObjectDisposedException) {
162 Assert.Fail ("#disposed close");
171 [Category ("NotWorking")] // bug #323388
172 public void Async_GetResponse_Failure ()
174 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
176 req.ContentLength = 1;
177 req.ContentType = "image/png";
180 IAsyncResult async = req.BeginGetRequestStream (null, null);
184 } catch (WebException) {
185 // The operation has timed out
189 req.BeginGetResponse (null, null);
191 } catch (InvalidOperationException) {
192 // Cannot re-call BeginGetRequestStream/BeginGetResponse while
193 // a previous call is still in progress
196 using (Stream wstream = req.EndGetRequestStream (async)) {
197 wstream.WriteByte (72);
200 // the temp file should not be in use
201 Directory.Delete (_tempDirectory, true);
207 WebResponse res = null;
210 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
211 req.ContentLength = 1;
212 req.ContentType = "image/png";
215 Stream stream = req.GetRequestStream ();
216 Assert.Fail ("should throw exception");
217 } catch (ProtocolViolationException) {
222 Stream wstream = req.GetRequestStream ();
223 Assert.IsFalse (wstream.CanRead, "#1r");
224 Assert.IsTrue (wstream.CanWrite, "#1w");
225 Assert.IsTrue (wstream.CanSeek, "#1s");
227 wstream.WriteByte (72);
228 wstream.WriteByte (101);
229 wstream.WriteByte (108);
230 wstream.WriteByte (108);
231 wstream.WriteByte (111);
234 Assert.AreEqual (1, req.ContentLength, "#1cl");
235 Assert.AreEqual ("image/png", req.ContentType, "#1ct");
239 req = (FileWebRequest) WebRequest.Create (_tempFileUri);
240 res = req.GetResponse ();
241 Assert.AreEqual ((long) 5, res.ContentLength, "#2 len");
242 Assert.AreEqual ("application/octet-stream", res.ContentType, "#2 type");
243 Assert.AreEqual ("file", res.ResponseUri.Scheme, "#2 scheme");
245 Stream rstream = res.GetResponseStream ();
246 Assert.IsTrue (rstream.CanRead, "#3r");
247 Assert.IsFalse (rstream.CanWrite, "#3w");
248 Assert.IsTrue (rstream.CanSeek, "#3s");
250 Assert.AreEqual (72, rstream.ReadByte (), "#4a");
251 Assert.AreEqual (101, rstream.ReadByte (), "#4b");
252 Assert.AreEqual (108, rstream.ReadByte (), "#4c");
253 Assert.AreEqual (108, rstream.ReadByte (), "#4d");
254 Assert.AreEqual (111, rstream.ReadByte (), "#4e");
259 long len = res.ContentLength;
260 Assert.AreEqual ((long) 5, len, "#5");
261 } catch (ObjectDisposedException) {
262 Assert.Fail ("#disposed contentlength");
265 WebHeaderCollection w = res.Headers;
266 } catch (ObjectDisposedException) {
267 Assert.Fail ("#disposed headers");
271 } catch (ObjectDisposedException) {
272 Assert.Fail ("#disposed close");
281 [Category ("NotWorking")] // bug #323388
282 public void Sync_GetResponse_Failure ()
284 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
286 req.ContentLength = 1;
287 req.ContentType = "image/png";
290 using (Stream rs = req.GetRequestStream ()) {
294 } catch (WebException) {
295 // The operation has timed out
299 req.BeginGetResponse (null, null);
301 } catch (InvalidOperationException) {
302 // Cannot re-call BeginGetRequestStream/BeginGetResponse while
303 // a previous call is still in progress
307 // the temp file should not be in use
308 Directory.Delete (_tempDirectory, true);
312 public void ConnectionGroupName ()
314 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
315 Assert.IsNull (req.ConnectionGroupName, "#A");
316 req.ConnectionGroupName = "whatever";
317 Assert.IsNotNull (req.ConnectionGroupName, "#B1");
318 Assert.AreEqual ("whatever", req.ConnectionGroupName, "#B2");
319 req.ConnectionGroupName = string.Empty;
320 Assert.IsNotNull (req.ConnectionGroupName, "#C1");
321 Assert.AreEqual (string.Empty, req.ConnectionGroupName, "#C2");
322 req.ConnectionGroupName = null;
323 Assert.IsNull (req.ConnectionGroupName, "#D");
327 public void ContentLength ()
329 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
330 Assert.AreEqual (0, req.Headers.Count, "#A1");
331 Assert.AreEqual (0, req.ContentLength, "#A2");
332 req.ContentLength = 5;
333 Assert.AreEqual (5, req.ContentLength, "#A3");
334 Assert.AreEqual (0, req.Headers.Count, "#A4");
337 using (Stream s = req.GetRequestStream ()) {
339 Assert.AreEqual (5, req.ContentLength, "#B1");
341 Assert.AreEqual (5, req.ContentLength, "#B2");
343 Assert.AreEqual (5, req.ContentLength, "#B3");
345 Assert.AreEqual (5, req.ContentLength, "#B4");
349 public void ContentLength_Negative ()
351 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
353 req.ContentLength = -1;
355 } catch (ArgumentException ex) {
356 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
357 Assert.IsNotNull (ex.Message, "#3");
358 Assert.IsFalse (ex.Message == "value", "#4");
359 Assert.IsNotNull (ex.ParamName, "#5");
360 Assert.AreEqual ("value", ex.ParamName, "#6");
361 Assert.IsNull (ex.InnerException, "#7");
366 public void ContentType ()
368 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
369 Assert.AreEqual (0, req.Headers.Count, "#A1");
370 Assert.IsNull (req.ContentType, "#A2");
372 req.ContentType = "application/x-gzip";
373 Assert.AreEqual (1, req.Headers.Count, "#B1");
374 Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#B2");
375 Assert.AreEqual ("application/x-gzip", req.Headers.Get (0), "#B3");
376 Assert.AreEqual ("application/x-gzip", req.ContentType, "#B4");
378 req.Headers.Set ("Content-Type", "image/png");
379 Assert.AreEqual ("image/png", req.ContentType, "#C1");
381 req.ContentType = null;
382 Assert.AreEqual (1, req.Headers.Count, "#D1");
383 Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#D2");
384 Assert.AreEqual (string.Empty, req.Headers.Get (0), "#D3");
385 Assert.AreEqual (string.Empty, req.ContentType, "#D4");
387 req.Headers.Remove ("Content-Type");
388 Assert.AreEqual (0, req.Headers.Count, "#E1");
389 Assert.IsNull (req.ContentType, "#E2");
393 public void Credentials ()
395 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
396 Assert.IsNull (req.Credentials, "#1");
397 req.Credentials = new NetworkCredential ();
398 Assert.IsNotNull (req.Credentials, "#2");
399 req.Credentials = null;
400 Assert.IsNull (req.Credentials, "#3");
404 [Category ("NotWorking")]
405 public void GetRequestStream ()
407 FileWebRequest req = (FileWebRequest) WebRequest.Create (
411 FileStream fsA = null;
412 FileStream fsB = null;
414 fsA = req.GetRequestStream () as FileStream;
415 Assert.IsNotNull (fsA, "#A1");
417 req.GetRequestStream ();
419 } catch (WebException) {
420 // The operation has timed out
424 req.GetRequestStream ();
426 } catch (InvalidOperationException) {
427 // Cannot re-call BeginGetRequestStream/BeginGetResponse
428 // while a previous call is still in progress.
437 req = (FileWebRequest) WebRequest.Create (_tempFileUri);
441 fsA = req.GetRequestStream () as FileStream;
442 Assert.IsNotNull (fsA, "#B1");
445 req.GetRequestStream ();
447 } catch (WebException) {
448 // The operation has timed out
452 req.GetRequestStream ();
454 } catch (InvalidOperationException) {
455 // Cannot re-call BeginGetRequestStream/BeginGetResponse
456 // while a previous call is still in progress.
467 public void GetRequestStream_File_Exists ()
469 Stream s = File.Create (_tempFile);
471 FileWebRequest req = (FileWebRequest) WebRequest.Create (
474 s = req.GetRequestStream ();
479 public void GetRequestStream_Method_Valid ()
481 string [] methods = new string [] { "PUT", "POST", "CHECKOUT",
482 "DELETE", "OPTIONS", "TRACE", "GET ", "DUNNO" };
484 foreach (string method in methods) {
485 FileWebRequest req = (FileWebRequest) WebRequest.Create (
488 using (Stream s = req.GetRequestStream ()) {
489 Assert.IsNotNull (s, "#1:" + method);
490 Assert.IsFalse (s.CanRead, "#2:" + method);
491 Assert.IsTrue (s.CanSeek, "#3:" + method);
492 Assert.IsFalse (s.CanTimeout, "#4:" + method);
493 Assert.IsTrue (s.CanWrite, "#5:" + method);
494 Assert.AreEqual (0, s.Length, "#6:" + method);
495 Assert.AreEqual (0, s.Position, "#7:" + method);
497 int i = s.ReadTimeout;
498 Assert.Fail ("#8:" + method + "=>" + i);
499 } catch (InvalidOperationException) {
502 int i = s.WriteTimeout;
503 Assert.Fail ("#9:" + method + "=>" + i);
504 } catch (InvalidOperationException) {
511 public void GetRequestStream_Method_Invalid ()
513 string [] methods = new string [] { "GET", "get", "HEAD", "head",
514 "CONNECT", "connect"};
515 foreach (string method in methods) {
516 FileWebRequest req = (FileWebRequest) WebRequest.Create (
520 req.GetRequestStream ();
521 Assert.Fail ("#1:" + method);
522 } catch (ProtocolViolationException ex) {
523 Assert.AreEqual (typeof (ProtocolViolationException), ex.GetType (), "#2:" + method);
524 Assert.IsNotNull (ex.Message, "#3:" + method);
525 Assert.IsNull (ex.InnerException, "#4:" + method);
531 public void GetResponse_File_Exists ()
533 Stream s = File.Create (_tempFile);
535 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
536 FileWebResponse respA = null;
537 FileWebResponse respB = null;
539 respA = req.GetResponse () as FileWebResponse;
540 Assert.IsNotNull (respA, "#1");
541 respB = req.GetResponse () as FileWebResponse;
542 Assert.IsNotNull (respB, "#2");
543 Assert.AreSame (respA, respB, "#3");
553 public void GetResponse_File_DoesNotExist ()
555 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
559 } catch (WebException ex) {
560 Assert.AreEqual (typeof (WebException), ex.GetType (), "#1");
561 Assert.IsNotNull (ex.Message, "#2");
562 Assert.IsTrue (ex.Message.IndexOf ("FileWebRequestTest.tmp") != -1, "#3");
563 Assert.IsNull (ex.Response, "#4");
564 Assert.IsNotNull (ex.InnerException, "#5");
570 public void Method ()
572 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
573 Assert.IsNotNull (req.Method, "#A1");
574 Assert.AreEqual ("GET", req.Method, "#A2");
575 req.Method = "whatever";
576 Assert.IsNotNull (req.Method, "#B1");
577 Assert.AreEqual ("whatever", req.Method, "#B2");
579 Assert.IsNotNull (req.Method, "#C1");
580 Assert.AreEqual ("get ", req.Method, "#C2");
584 public void Method_Empty ()
586 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
588 req.Method = string.Empty;
590 } catch (ArgumentException ex) {
591 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
592 Assert.IsNotNull (ex.Message, "#3");
593 Assert.AreEqual ("value", ex.ParamName, "#4");
594 Assert.IsNull (ex.InnerException, "#5");
599 public void Method_Null ()
601 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
605 } catch (ArgumentException ex) {
606 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
607 Assert.IsNotNull (ex.Message, "#3");
608 Assert.AreEqual ("value", ex.ParamName, "#4");
609 Assert.IsNull (ex.InnerException, "#5");
614 public void PreAuthenticate ()
616 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
617 Assert.IsFalse (req.PreAuthenticate, "#1");
618 req.PreAuthenticate = true;
619 Assert.IsTrue (req.PreAuthenticate, "#2");
625 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
626 Assert.IsNull (req.Proxy, "#1");
627 req.Proxy = new WebProxy ();
628 Assert.IsNotNull (req.Proxy, "#2");
630 Assert.IsNull (req.Proxy, "#3");
634 public void RequestUri ()
636 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
637 Assert.AreSame (_tempFileUri, req.RequestUri);
641 public void Timeout ()
643 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
644 Assert.AreEqual (100000, req.Timeout, "#1");
645 req.Timeout = int.MaxValue;
646 Assert.AreEqual (int.MaxValue, req.Timeout, "#2");
648 Assert.AreEqual (0, req.Timeout, "#3");
652 public void Timeout_Negative ()
654 FileWebRequest req = (FileWebRequest) WebRequest.Create (_tempFileUri);
656 Assert.AreEqual (-1, req.Timeout, "#1");
660 } catch (ArgumentOutOfRangeException ex) {
661 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
662 Assert.IsNotNull (ex.Message, "#4");
663 Assert.IsNotNull (ex.ParamName, "#5");
664 Assert.AreEqual ("value", ex.ParamName, "#6");
665 Assert.IsNull (ex.InnerException, "#7");
670 public void GetObjectData ()
672 FileWebRequest fwr = (FileWebRequest) WebRequest.Create ("file:///test.txt");
673 fwr.ConnectionGroupName = "CGN";
674 fwr.ContentLength = 10;
675 fwr.ContentType = "image/png";
676 fwr.Credentials = new NetworkCredential ("Miguel", "de Icaza", "Novell");
677 fwr.Headers.Add ("Disposition", "attach");
679 fwr.PreAuthenticate = true;
680 fwr.Proxy = new WebProxy ("proxy.ximian.com");
683 SerializationInfo si = new SerializationInfo (typeof (FileWebRequest),
684 new FormatterConverter ());
685 ((ISerializable) fwr).GetObjectData (si, new StreamingContext ());
686 Assert.AreEqual (9, si.MemberCount, "#A1");
688 foreach (SerializationEntry entry in si) {
689 Assert.IsNotNull (entry.Name, "#B1:" + i);
690 Assert.IsNotNull (entry.ObjectType, "#B2:" + i);
691 Assert.IsNotNull (entry.Value, "#B3:" + i);
695 Assert.AreEqual ("headers", entry.Name, "#B4:" + i);
696 Assert.AreEqual (typeof (WebHeaderCollection), entry.ObjectType, "#B5:" + i);
699 Assert.AreEqual ("proxy", entry.Name, "#B4:" + i);
700 Assert.AreEqual (typeof (IWebProxy), entry.ObjectType, "#B5:" + i);
703 Assert.AreEqual ("uri", entry.Name, "#B4:" + i);
704 Assert.AreEqual (typeof (Uri), entry.ObjectType, "#B5:" + i);
707 Assert.AreEqual ("connectionGroupName", entry.Name, "#B4:" + i);
708 Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
709 Assert.AreEqual ("CGN", entry.Value, "#B6:" + i);
712 Assert.AreEqual ("method", entry.Name, "#B4:" + i);
713 Assert.AreEqual (typeof (string), entry.ObjectType, "#B5:" + i);
714 Assert.AreEqual ("PUT", entry.Value, "#B6:" + i);
717 Assert.AreEqual ("contentLength", entry.Name, "#B4:" + i);
718 Assert.AreEqual (typeof (long), entry.ObjectType, "#B5:" + i);
719 Assert.AreEqual (10, entry.Value, "#B6:" + i);
722 Assert.AreEqual ("timeout", entry.Name, "#B4:" + i);
723 Assert.AreEqual (typeof (int), entry.ObjectType, "#B5:" + i);
724 Assert.AreEqual (20, entry.Value, "#B6:" + i);
727 Assert.AreEqual ("fileAccess", entry.Name, "#B4:" + i);
728 Assert.AreEqual (typeof (FileAccess), entry.ObjectType, "#B5:" + i);
729 Assert.AreEqual (FileAccess.Read, entry.Value, "#B6:" + i);
732 Assert.AreEqual ("preauthenticate", entry.Name, "#B4:" + i);
733 Assert.AreEqual (typeof (bool), entry.ObjectType, "#B5:" + i);
734 Assert.AreEqual (false, entry.Value, "#B6:" + i);
742 [Category ("NotWorking")] // Difference at index 272: 20 instead of 19
743 public void Serialize ()
745 FileWebRequest fwr = (FileWebRequest) WebRequest.Create ("file://test.txt/");
746 fwr.ConnectionGroupName = "CGN";
747 fwr.ContentLength = 10;
748 fwr.ContentType = "image/png";
749 fwr.Credentials = new NetworkCredential ("Miguel", "de Icaza", "Novell");
750 fwr.Headers.Add ("Disposition", "attach");
752 fwr.PreAuthenticate = true;
753 fwr.Proxy = new WebProxy ("proxy.ximian.com");
756 BinaryFormatter bf = new BinaryFormatter ();
757 bf.AssemblyFormat = FormatterAssemblyStyle.Full;
759 MemoryStream ms = new MemoryStream ();
760 bf.Serialize (ms, fwr);
763 byte [] buffer = new byte [ms.Length];
764 ms.Read (buffer, 0, buffer.Length);
765 Assert.AreEqual (_serialized, buffer);
769 public void Deserialize ()
771 MemoryStream ms = new MemoryStream ();
772 ms.Write (_serialized, 0, _serialized.Length);
775 BinaryFormatter bf = new BinaryFormatter ();
776 FileWebRequest req = (FileWebRequest) bf.Deserialize (ms);
777 Assert.AreEqual ("CGN", req.ConnectionGroupName, "#A1");
778 Assert.AreEqual (10, req.ContentLength, "#A2");
779 Assert.AreEqual ("image/png", req.ContentType, "#A3");
780 Assert.IsNull (req.Credentials, "#A4");
781 Assert.AreEqual ("PUT", req.Method, "#A5");
782 Assert.IsFalse (req.PreAuthenticate, "#A6");
783 Assert.AreEqual ("file://test.txt/", req.RequestUri.AbsoluteUri, "#A7");
784 Assert.AreEqual (20, req.Timeout, "#A8");
786 WebHeaderCollection headers = req.Headers;
787 Assert.IsNotNull (headers, "#C1");
788 Assert.AreEqual (2, headers.Count, "#C2");
789 Assert.AreEqual ("Content-Type", req.Headers.GetKey (0), "#C3");
790 Assert.AreEqual ("image/png", req.Headers.Get (0), "#C4");
791 Assert.AreEqual ("Disposition", req.Headers.GetKey (1), "#C5");
792 Assert.AreEqual ("attach", req.Headers.Get (1), "#C6");
794 WebProxy proxy = req.Proxy as WebProxy;
795 Assert.IsNotNull (proxy, "#D1");
796 Assert.AreEqual ("http://proxy.ximian.com/", proxy.Address.AbsoluteUri, "#D2");
797 Assert.IsNotNull (proxy.BypassArrayList, "#D3");
798 Assert.AreEqual (0, proxy.BypassArrayList.Count, "#D4");
799 Assert.IsNotNull (proxy.BypassList, "#D5");
800 Assert.AreEqual (0, proxy.BypassList.Length, "#D6");
801 Assert.IsFalse (proxy.BypassProxyOnLocal, "#D7");
802 Assert.IsNull (proxy.Credentials, "#D8");
805 private Uri GetTempFileUri ()
807 string tempFile = _tempFile;
809 // remove leading slash for absolute paths
810 tempFile = tempFile.TrimStart ('/');
812 tempFile = tempFile.Replace ('\\', '/');
814 return new Uri ("file:///" + tempFile);
817 private bool RunningOnUnix {
819 // check for Unix platforms - see FAQ for more details
820 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
821 int platform = (int) Environment.OSVersion.Platform;
822 return ((platform == 4) || (platform == 128) || (platform == 6));
826 private static readonly byte [] _serialized = new byte [] {
827 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
829 0x49, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
830 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30,
831 0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65,
832 0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50,
833 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b,
834 0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36,
835 0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x05, 0x01, 0x00,
836 0x00, 0x00, 0x19, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e,
837 0x65, 0x74, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x57, 0x65, 0x62, 0x52,
838 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x09, 0x00, 0x00, 0x00, 0x07,
839 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x05, 0x70, 0x72, 0x6f,
840 0x78, 0x79, 0x03, 0x75, 0x72, 0x69, 0x13, 0x63, 0x6f, 0x6e, 0x6e,
841 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70,
842 0x4e, 0x61, 0x6d, 0x65, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64,
843 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x4c, 0x65, 0x6e,
844 0x67, 0x74, 0x68, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74,
845 0x0a, 0x66, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73,
846 0x0f, 0x70, 0x72, 0x65, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74,
847 0x69, 0x63, 0x61, 0x74, 0x65, 0x04, 0x04, 0x04, 0x01, 0x01, 0x00,
848 0x00, 0x03, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e,
849 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65, 0x61, 0x64,
850 0x65, 0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f,
851 0x6e, 0x02, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79, 0x73, 0x74, 0x65,
852 0x6d, 0x2e, 0x4e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x50, 0x72,
853 0x6f, 0x78, 0x79, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x53, 0x79, 0x73,
854 0x74, 0x65, 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02, 0x00, 0x00, 0x00,
855 0x09, 0x08, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x49,
856 0x4f, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73,
857 0x73, 0x01, 0x02, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00,
858 0x09, 0x04, 0x00, 0x00, 0x00, 0x09, 0x05, 0x00, 0x00, 0x00, 0x06,
859 0x06, 0x00, 0x00, 0x00, 0x03, 0x43, 0x47, 0x4e, 0x06, 0x07, 0x00,
860 0x00, 0x00, 0x03, 0x50, 0x55, 0x54, 0x0a, 0x00, 0x00, 0x00, 0x00,
861 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0xf8, 0xff, 0xff,
862 0xff, 0x14, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x49, 0x4f,
863 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73,
864 0x01, 0x00, 0x00, 0x00, 0x07, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f,
865 0x5f, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05, 0x03, 0x00,
866 0x00, 0x00, 0x1e, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e,
867 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x48, 0x65, 0x61, 0x64, 0x65,
868 0x72, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
869 0x05, 0x00, 0x00, 0x00, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x01,
870 0x30, 0x01, 0x32, 0x01, 0x31, 0x01, 0x33, 0x00, 0x01, 0x01, 0x01,
871 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06,
872 0x09, 0x00, 0x00, 0x00, 0x0c, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
873 0x74, 0x2d, 0x54, 0x79, 0x70, 0x65, 0x06, 0x0a, 0x00, 0x00, 0x00,
874 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x70, 0x6e, 0x67, 0x06,
875 0x0b, 0x00, 0x00, 0x00, 0x0b, 0x44, 0x69, 0x73, 0x70, 0x6f, 0x73,
876 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x06, 0x0c, 0x00, 0x00, 0x00, 0x06,
877 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x05, 0x04, 0x00, 0x00, 0x00,
878 0x13, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x4e, 0x65, 0x74,
879 0x2e, 0x57, 0x65, 0x62, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x04, 0x00,
880 0x00, 0x00, 0x0e, 0x5f, 0x42, 0x79, 0x70, 0x61, 0x73, 0x73, 0x4f,
881 0x6e, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x0d, 0x5f, 0x50, 0x72, 0x6f,
882 0x78, 0x79, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x0b, 0x5f,
883 0x42, 0x79, 0x70, 0x61, 0x73, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x16,
884 0x5f, 0x55, 0x73, 0x65, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
885 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73,
886 0x00, 0x04, 0x02, 0x00, 0x01, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65,
887 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x02, 0x00, 0x00, 0x00, 0x01, 0x02,
888 0x00, 0x00, 0x00, 0x00, 0x09, 0x0d, 0x00, 0x00, 0x00, 0x0a, 0x00,
889 0x05, 0x05, 0x00, 0x00, 0x00, 0x0a, 0x53, 0x79, 0x73, 0x74, 0x65,
890 0x6d, 0x2e, 0x55, 0x72, 0x69, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x41,
891 0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x55, 0x72, 0x69, 0x01,
892 0x02, 0x00, 0x00, 0x00, 0x06, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x66,
893 0x69, 0x6c, 0x65, 0x3a, 0x2f, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e,
894 0x74, 0x78, 0x74, 0x2f, 0x01, 0x0d, 0x00, 0x00, 0x00, 0x05, 0x00,
895 0x00, 0x00, 0x06, 0x0f, 0x00, 0x00, 0x00, 0x18, 0x68, 0x74, 0x74,
896 0x70, 0x3a, 0x2f, 0x2f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x78,
897 0x69, 0x6d, 0x69, 0x61, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x0b