2 // WebClientTest.cs - NUnit Test Cases for System.Net.WebClient
4 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8 using System.Collections;
9 using System.Collections.Specialized;
10 using System.Globalization;
13 using System.Net.Sockets;
14 using System.Runtime.Serialization;
16 using System.Threading;
17 using NUnit.Framework;
19 using MonoTests.Helpers;
21 namespace MonoTests.System.Net
24 public class WebClientTest
26 private string _tempFolder;
31 _tempFolder = Path.Combine (Path.GetTempPath (),
33 if (Directory.Exists (_tempFolder))
34 Directory.Delete (_tempFolder, true);
35 Directory.CreateDirectory (_tempFolder);
39 public void TearDown ()
41 if (Directory.Exists (_tempFolder))
42 Directory.Delete (_tempFolder, true);
46 [Category ("InetAccess")]
47 public void DownloadTwice ()
49 WebClient wc = new WebClient();
50 string filename = Path.GetTempFileName();
52 // A new, but empty file has been created. This is a test case
54 wc.DownloadFile("http://google.com/", filename);
56 // Now, remove the file and attempt to download again.
57 File.Delete(filename);
58 wc.DownloadFile("http://google.com/", filename);
62 public void DownloadData1_Address_Null ()
64 WebClient wc = new WebClient ();
66 wc.DownloadData ((string) null);
68 } catch (ArgumentNullException ex) {
69 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
70 Assert.IsNull (ex.InnerException, "#3");
71 Assert.IsNotNull (ex.Message, "#4");
72 Assert.IsNotNull (ex.ParamName, "#5");
73 Assert.AreEqual ("address", ex.ParamName, "#6");
77 [Test] // DownloadData (string)
78 public void DownloadData1_Address_SchemeNotSupported ()
80 WebClient wc = new WebClient ();
82 wc.DownloadData ("tp://scheme.notsupported");
84 } catch (WebException ex) {
85 // An error occurred performing a WebClient request
86 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
87 Assert.IsNotNull (ex.InnerException, "#3");
88 Assert.IsNotNull (ex.Message, "#4");
89 Assert.IsNull (ex.Response, "#5");
90 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
92 // The URI prefix is not recognized
93 Exception inner = ex.InnerException;
94 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
95 Assert.IsNull (inner.InnerException, "#8");
96 Assert.IsNotNull (inner.Message, "#9");
100 [Test] // DownloadData (Uri)
101 public void DownloadData2_Address_Null ()
103 WebClient wc = new WebClient ();
105 wc.DownloadData ((Uri) null);
107 } catch (ArgumentNullException ex) {
108 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
109 Assert.IsNull (ex.InnerException, "#3");
110 Assert.IsNotNull (ex.Message, "#4");
111 Assert.IsNotNull (ex.ParamName, "#5");
112 Assert.AreEqual ("address", ex.ParamName, "#6");
116 [Test] // DownloadData (Uri)
117 public void DownloadData2_Address_SchemeNotSupported ()
119 WebClient wc = new WebClient ();
121 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
123 } catch (WebException ex) {
124 // An error occurred performing a WebClient request
125 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
126 Assert.IsNotNull (ex.InnerException, "#3");
127 Assert.IsNotNull (ex.Message, "#4");
128 Assert.IsNull (ex.Response, "#5");
129 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
131 // The URI prefix is not recognized
132 Exception inner = ex.InnerException;
133 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
134 Assert.IsNull (inner.InnerException, "#8");
135 Assert.IsNotNull (inner.Message, "#9");
140 public void DownloadFile1_Address_Null ()
142 WebClient wc = new WebClient ();
144 wc.DownloadFile ((string) null, "tmp.out");
146 } catch (ArgumentNullException ex) {
147 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
148 Assert.IsNull (ex.InnerException, "#3");
149 Assert.IsNotNull (ex.Message, "#4");
150 Assert.IsNotNull (ex.ParamName, "#5");
151 Assert.AreEqual ("address", ex.ParamName, "#6");
155 [Test] // DownloadFile (string, string)
156 public void DownloadFile1_Address_SchemeNotSupported ()
158 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
159 WebClient wc = new WebClient ();
161 wc.DownloadFile ("tp://scheme.notsupported", file);
163 } catch (WebException ex) {
164 // An error occurred performing a WebClient request
165 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
166 Assert.IsNotNull (ex.InnerException, "#3");
167 Assert.IsNotNull (ex.Message, "#4");
168 Assert.IsNull (ex.Response, "#5");
169 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
171 // The URI prefix is not recognized
172 Exception inner = ex.InnerException;
173 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
174 Assert.IsNull (inner.InnerException, "#8");
175 Assert.IsNotNull (inner.Message, "#9");
178 if (File.Exists (file))
183 [Test] // DownloadFile (string, string)
184 public void DownloadFile1_FileName_Null ()
186 WebClient wc = new WebClient ();
188 wc.DownloadFile ("tp://scheme.notsupported",
191 } catch (ArgumentNullException ex) {
192 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
193 Assert.IsNull (ex.InnerException, "#3");
194 Assert.IsNotNull (ex.Message, "#4");
195 Assert.IsNotNull (ex.ParamName, "#5");
196 Assert.AreEqual ("fileName", ex.ParamName, "#6");
200 [Test] // DownloadFile (Uri, string)
201 public void DownloadFile2_Address_Null ()
203 WebClient wc = new WebClient ();
205 wc.DownloadFile ((Uri) null, "tmp.out");
207 } catch (ArgumentNullException ex) {
208 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
209 Assert.IsNull (ex.InnerException, "#3");
210 Assert.IsNotNull (ex.Message, "#4");
211 Assert.IsNotNull (ex.ParamName, "#5");
212 Assert.AreEqual ("address", ex.ParamName, "#6");
216 [Test] // DownloadFile (Uri, string)
217 public void DownloadFile2_Address_SchemeNotSupported ()
219 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
220 WebClient wc = new WebClient ();
222 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
224 } catch (WebException ex) {
225 // An error occurred performing a WebClient request
226 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
227 Assert.IsNotNull (ex.InnerException, "#3");
228 Assert.IsNotNull (ex.Message, "#4");
229 Assert.IsNull (ex.Response, "#5");
230 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
232 // The URI prefix is not recognized
233 Exception inner = ex.InnerException;
234 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
235 Assert.IsNull (inner.InnerException, "#8");
236 Assert.IsNotNull (inner.Message, "#9");
239 if (File.Exists (file))
244 [Test] // DownloadFile (Uri, string)
245 public void DownloadFile2_FileName_Null ()
247 WebClient wc = new WebClient ();
249 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
252 } catch (ArgumentNullException ex) {
253 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
254 Assert.IsNull (ex.InnerException, "#3");
255 Assert.IsNotNull (ex.Message, "#4");
256 Assert.IsNotNull (ex.ParamName, "#5");
257 Assert.AreEqual ("fileName", ex.ParamName, "#6");
261 [Test] // DownloadString (string)
262 public void DownloadString1_Address_Null ()
264 WebClient wc = new WebClient ();
266 wc.DownloadString ((string) null);
268 } catch (ArgumentNullException ex) {
269 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
270 Assert.IsNull (ex.InnerException, "#3");
271 Assert.IsNotNull (ex.Message, "#4");
272 Assert.IsNotNull (ex.ParamName, "#5");
273 Assert.AreEqual ("address", ex.ParamName, "#6");
277 [Test] // DownloadString (string)
278 public void DownloadString1_Address_SchemeNotSupported ()
280 WebClient wc = new WebClient ();
282 wc.DownloadString ("tp://scheme.notsupported");
284 } catch (WebException ex) {
285 // An error occurred performing a WebClient request
286 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
287 Assert.IsNotNull (ex.InnerException, "#3");
288 Assert.IsNotNull (ex.Message, "#4");
289 Assert.IsNull (ex.Response, "#5");
290 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
292 // The URI prefix is not recognized
293 Exception inner = ex.InnerException;
294 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
295 Assert.IsNull (inner.InnerException, "#8");
296 Assert.IsNotNull (inner.Message, "#9");
300 [Test] // DownloadString (Uri)
301 public void DownloadString2_Address_Null ()
303 WebClient wc = new WebClient ();
305 wc.DownloadString ((Uri) null);
307 } catch (ArgumentNullException ex) {
308 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
309 Assert.IsNull (ex.InnerException, "#3");
310 Assert.IsNotNull (ex.Message, "#4");
311 Assert.IsNotNull (ex.ParamName, "#5");
312 Assert.AreEqual ("address", ex.ParamName, "#6");
316 [Test] // DownloadString (Uri)
317 public void DownloadString2_Address_SchemeNotSupported ()
319 WebClient wc = new WebClient ();
321 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
323 } catch (WebException ex) {
324 // An error occurred performing a WebClient request
325 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
326 Assert.IsNotNull (ex.InnerException, "#3");
327 Assert.IsNotNull (ex.Message, "#4");
328 Assert.IsNull (ex.Response, "#5");
329 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
331 // The URI prefix is not recognized
332 Exception inner = ex.InnerException;
333 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
334 Assert.IsNull (inner.InnerException, "#8");
335 Assert.IsNotNull (inner.Message, "#9");
340 public void EncodingTest ()
342 WebClient wc = new WebClient ();
343 Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
344 wc.Encoding = Encoding.ASCII;
345 Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
349 public void Encoding_Value_Null ()
351 WebClient wc = new WebClient ();
355 } catch (ArgumentNullException ex) {
356 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
357 Assert.IsNull (ex.InnerException, "#3");
358 Assert.IsNotNull (ex.Message, "#4");
359 Assert.AreEqual ("Encoding", ex.ParamName, "#6");
363 [Test] // OpenRead (string)
364 public void OpenRead1_Address_Null ()
366 WebClient wc = new WebClient ();
368 wc.OpenRead ((string) null);
370 } catch (ArgumentNullException ex) {
371 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
372 Assert.IsNull (ex.InnerException, "#3");
373 Assert.IsNotNull (ex.Message, "#4");
374 Assert.IsNotNull (ex.ParamName, "#5");
375 Assert.AreEqual ("address", ex.ParamName, "#6");
379 [Test] // OpenRead (string)
380 public void OpenRead1_Address_SchemeNotSupported ()
382 WebClient wc = new WebClient ();
384 wc.OpenRead ("tp://scheme.notsupported");
386 } catch (WebException ex) {
387 // An error occurred performing a WebClient request
388 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
389 Assert.IsNotNull (ex.InnerException, "#3");
390 Assert.IsNotNull (ex.Message, "#4");
391 Assert.IsNull (ex.Response, "#5");
392 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
394 // The URI prefix is not recognized
395 Exception inner = ex.InnerException;
396 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
397 Assert.IsNull (inner.InnerException, "#8");
398 Assert.IsNotNull (inner.Message, "#9");
402 [Test] // OpenRead (Uri)
403 public void OpenRead2_Address_Null ()
405 WebClient wc = new WebClient ();
407 wc.OpenRead ((Uri) null);
409 } catch (ArgumentNullException ex) {
410 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
411 Assert.IsNull (ex.InnerException, "#3");
412 Assert.IsNotNull (ex.Message, "#4");
413 Assert.IsNotNull (ex.ParamName, "#5");
414 Assert.AreEqual ("address", ex.ParamName, "#6");
418 [Test] // OpenRead (Uri)
419 public void OpenRead2_Address_SchemeNotSupported ()
421 WebClient wc = new WebClient ();
423 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
425 } catch (WebException ex) {
426 // An error occurred performing a WebClient request
427 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
428 Assert.IsNotNull (ex.InnerException, "#3");
429 Assert.IsNotNull (ex.Message, "#4");
430 Assert.IsNull (ex.Response, "#5");
431 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
433 // The URI prefix is not recognized
434 Exception inner = ex.InnerException;
435 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
436 Assert.IsNull (inner.InnerException, "#8");
437 Assert.IsNotNull (inner.Message, "#9");
441 [Test] // OpenWrite (string)
442 public void OpenWrite1_Address_Null ()
444 WebClient wc = new WebClient ();
446 wc.OpenWrite ((string) null);
448 } catch (ArgumentNullException ex) {
449 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
450 Assert.IsNull (ex.InnerException, "#3");
451 Assert.IsNotNull (ex.Message, "#4");
452 Assert.IsNotNull (ex.ParamName, "#5");
453 Assert.AreEqual ("address", ex.ParamName, "#6");
457 [Test] // OpenWrite (string)
458 public void OpenWrite1_Address_SchemeNotSupported ()
460 WebClient wc = new WebClient ();
462 wc.OpenWrite ("tp://scheme.notsupported");
464 } catch (WebException ex) {
465 // An error occurred performing a WebClient request
466 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
467 Assert.IsNotNull (ex.InnerException, "#3");
468 Assert.IsNotNull (ex.Message, "#4");
469 Assert.IsNull (ex.Response, "#5");
470 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
472 // The URI prefix is not recognized
473 Exception inner = ex.InnerException;
474 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
475 Assert.IsNull (inner.InnerException, "#8");
476 Assert.IsNotNull (inner.Message, "#9");
480 [Test] // OpenWrite (string, string)
481 public void OpenWrite2_Address_Null ()
483 WebClient wc = new WebClient ();
485 wc.OpenWrite ((string) null, "PUT");
487 } catch (ArgumentNullException ex) {
488 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
489 Assert.IsNull (ex.InnerException, "#3");
490 Assert.IsNotNull (ex.Message, "#4");
491 Assert.IsNotNull (ex.ParamName, "#5");
492 Assert.AreEqual ("address", ex.ParamName, "#6");
496 [Test] // OpenWrite (string, string)
497 public void OpenWrite2_Address_SchemeNotSupported ()
499 WebClient wc = new WebClient ();
501 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
503 } catch (WebException ex) {
504 // An error occurred performing a WebClient request
505 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
506 Assert.IsNotNull (ex.InnerException, "#3");
507 Assert.IsNotNull (ex.Message, "#4");
508 Assert.IsNull (ex.Response, "#5");
509 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
511 // The URI prefix is not recognized
512 Exception inner = ex.InnerException;
513 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
514 Assert.IsNull (inner.InnerException, "#8");
515 Assert.IsNotNull (inner.Message, "#9");
519 [Test] // OpenWrite (Uri)
520 public void OpenWrite3_Address_Null ()
522 WebClient wc = new WebClient ();
524 wc.OpenWrite ((Uri) null);
526 } catch (ArgumentNullException ex) {
527 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
528 Assert.IsNull (ex.InnerException, "#3");
529 Assert.IsNotNull (ex.Message, "#4");
530 Assert.IsNotNull (ex.ParamName, "#5");
531 Assert.AreEqual ("address", ex.ParamName, "#6");
535 [Test] // OpenWrite (Uri)
536 public void OpenWrite3_Address_SchemeNotSupported ()
538 WebClient wc = new WebClient ();
540 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
542 } catch (WebException ex) {
543 // An error occurred performing a WebClient request
544 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
545 Assert.IsNotNull (ex.InnerException, "#3");
546 Assert.IsNotNull (ex.Message, "#4");
547 Assert.IsNull (ex.Response, "#5");
548 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
550 // The URI prefix is not recognized
551 Exception inner = ex.InnerException;
552 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
553 Assert.IsNull (inner.InnerException, "#8");
554 Assert.IsNotNull (inner.Message, "#9");
558 [Test] // OpenWrite (Uri, string)
559 public void OpenWrite4_Address_Null ()
561 WebClient wc = new WebClient ();
563 wc.OpenWrite ((Uri) null, "POST");
565 } catch (ArgumentNullException ex) {
566 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
567 Assert.IsNull (ex.InnerException, "#3");
568 Assert.IsNotNull (ex.Message, "#4");
569 Assert.IsNotNull (ex.ParamName, "#5");
570 Assert.AreEqual ("address", ex.ParamName, "#6");
574 [Test] // OpenWrite (Uri, string)
575 public void OpenWrite4_Address_SchemeNotSupported ()
577 WebClient wc = new WebClient ();
579 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
582 } catch (WebException ex) {
583 // An error occurred performing a WebClient request
584 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
585 Assert.IsNotNull (ex.InnerException, "#3");
586 Assert.IsNotNull (ex.Message, "#4");
587 Assert.IsNull (ex.Response, "#5");
588 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
590 // The URI prefix is not recognized
591 Exception inner = ex.InnerException;
592 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
593 Assert.IsNull (inner.InnerException, "#8");
594 Assert.IsNotNull (inner.Message, "#9");
598 [Test] // UploadData (string, byte [])
599 public void UploadData1_Address_Null ()
601 WebClient wc = new WebClient ();
603 wc.UploadData ((string) null, new byte [] { 0x1a });
605 } catch (ArgumentNullException ex) {
606 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
607 Assert.IsNull (ex.InnerException, "#3");
608 Assert.IsNotNull (ex.Message, "#4");
609 Assert.IsNotNull (ex.ParamName, "#5");
610 Assert.AreEqual ("address", ex.ParamName, "#6");
614 [Test] // UploadData (string, byte [])
615 public void UploadData1_Address_SchemeNotSupported ()
617 WebClient wc = new WebClient ();
619 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
621 } catch (WebException ex) {
622 // An error occurred performing a WebClient request
623 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
624 Assert.IsNotNull (ex.InnerException, "#3");
625 Assert.IsNotNull (ex.Message, "#4");
626 Assert.IsNull (ex.Response, "#5");
627 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
629 // The URI prefix is not recognized
630 Exception inner = ex.InnerException;
631 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
632 Assert.IsNull (inner.InnerException, "#8");
633 Assert.IsNotNull (inner.Message, "#9");
637 [Test] // UploadData (string, byte [])
638 public void UploadData1_Data_Null ()
640 WebClient wc = new WebClient ();
642 wc.UploadData ("http://www.mono-project.com",
645 } catch (ArgumentNullException ex) {
646 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
647 Assert.IsNull (ex.InnerException, "#3");
648 Assert.IsNotNull (ex.Message, "#4");
649 Assert.IsNotNull (ex.ParamName, "#5");
650 Assert.AreEqual ("data", ex.ParamName, "#6");
654 [Test] // UploadData (Uri, byte [])
655 public void UploadData2_Address_Null ()
657 WebClient wc = new WebClient ();
659 wc.UploadData ((Uri) null, new byte [] { 0x1a });
661 } catch (ArgumentNullException ex) {
662 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
663 Assert.IsNull (ex.InnerException, "#3");
664 Assert.IsNotNull (ex.Message, "#4");
665 Assert.IsNotNull (ex.ParamName, "#5");
666 Assert.AreEqual ("address", ex.ParamName, "#6");
670 [Test] // UploadData (Uri, byte [])
671 public void UploadData2_Address_SchemeNotSupported ()
673 WebClient wc = new WebClient ();
675 wc.UploadData (new Uri ("tp://scheme.notsupported"),
676 new byte [] { 0x1a });
678 } catch (WebException ex) {
679 // An error occurred performing a WebClient request
680 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
681 Assert.IsNotNull (ex.InnerException, "#3");
682 Assert.IsNotNull (ex.Message, "#4");
683 Assert.IsNull (ex.Response, "#5");
684 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
686 // The URI prefix is not recognized
687 Exception inner = ex.InnerException;
688 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
689 Assert.IsNull (inner.InnerException, "#8");
690 Assert.IsNotNull (inner.Message, "#9");
694 [Test] // UploadData (Uri, byte [])
695 public void UploadData2_Data_Null ()
697 WebClient wc = new WebClient ();
699 wc.UploadData (new Uri ("http://www.mono-project.com"),
702 } catch (ArgumentNullException ex) {
703 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
704 Assert.IsNull (ex.InnerException, "#3");
705 Assert.IsNotNull (ex.Message, "#4");
706 Assert.IsNotNull (ex.ParamName, "#5");
707 Assert.AreEqual ("data", ex.ParamName, "#6");
711 [Test] // UploadData (string, string, byte [])
712 public void UploadData3_Address_Null ()
714 WebClient wc = new WebClient ();
716 wc.UploadData ((string) null, "POST",
717 new byte [] { 0x1a });
719 } catch (ArgumentNullException ex) {
720 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
721 Assert.IsNull (ex.InnerException, "#3");
722 Assert.IsNotNull (ex.Message, "#4");
723 Assert.IsNotNull (ex.ParamName, "#5");
724 Assert.AreEqual ("address", ex.ParamName, "#6");
728 [Test] // UploadData (string, string, byte [])
729 public void UploadData3_Address_SchemeNotSupported ()
731 WebClient wc = new WebClient ();
733 wc.UploadData ("tp://scheme.notsupported",
734 "POST", new byte [] { 0x1a });
736 } catch (WebException ex) {
737 // An error occurred performing a WebClient request
738 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
739 Assert.IsNotNull (ex.InnerException, "#3");
740 Assert.IsNotNull (ex.Message, "#4");
741 Assert.IsNull (ex.Response, "#5");
742 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
744 // The URI prefix is not recognized
745 Exception inner = ex.InnerException;
746 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
747 Assert.IsNull (inner.InnerException, "#8");
748 Assert.IsNotNull (inner.Message, "#9");
752 [Test] // UploadData (string, string, byte [])
753 public void UploadData3_Data_Null ()
755 WebClient wc = new WebClient ();
757 wc.UploadData ("http://www.mono-project.com",
758 "POST", (byte []) null);
760 } catch (ArgumentNullException ex) {
761 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
762 Assert.IsNull (ex.InnerException, "#3");
763 Assert.IsNotNull (ex.Message, "#4");
764 Assert.IsNotNull (ex.ParamName, "#5");
765 Assert.AreEqual ("data", ex.ParamName, "#6");
769 [Test] // UploadData (Uri, string, byte [])
770 public void UploadData4_Address_Null ()
772 WebClient wc = new WebClient ();
774 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
776 } catch (ArgumentNullException ex) {
777 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
778 Assert.IsNull (ex.InnerException, "#3");
779 Assert.IsNotNull (ex.Message, "#4");
780 Assert.IsNotNull (ex.ParamName, "#5");
781 Assert.AreEqual ("address", ex.ParamName, "#6");
785 [Test] // UploadData (Uri, string, byte [])
786 public void UploadData4_Address_SchemeNotSupported ()
788 WebClient wc = new WebClient ();
790 wc.UploadData (new Uri ("tp://scheme.notsupported"),
791 "POST", new byte [] { 0x1a });
793 } catch (WebException ex) {
794 // An error occurred performing a WebClient request
795 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
796 Assert.IsNotNull (ex.InnerException, "#3");
797 Assert.IsNotNull (ex.Message, "#4");
798 Assert.IsNull (ex.Response, "#5");
799 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
801 // The URI prefix is not recognized
802 Exception inner = ex.InnerException;
803 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
804 Assert.IsNull (inner.InnerException, "#8");
805 Assert.IsNotNull (inner.Message, "#9");
809 [Test] // UploadData (Uri, string, byte [])
810 public void UploadData4_Data_Null ()
812 WebClient wc = new WebClient ();
814 wc.UploadData (new Uri ("http://www.mono-project.com"),
815 "POST", (byte []) null);
817 } catch (ArgumentNullException ex) {
818 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
819 Assert.IsNull (ex.InnerException, "#3");
820 Assert.IsNotNull (ex.Message, "#4");
821 Assert.IsNotNull (ex.ParamName, "#5");
822 Assert.AreEqual ("data", ex.ParamName, "#6");
826 [Test] // UploadFile (string, string)
827 public void UploadFile1_Address_Null ()
829 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
830 File.Create (tempFile).Close ();
832 WebClient wc = new WebClient ();
834 wc.UploadFile ((string) null, tempFile);
836 } catch (ArgumentNullException ex) {
837 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
838 Assert.IsNull (ex.InnerException, "#3");
839 Assert.IsNotNull (ex.Message, "#4");
840 Assert.IsNotNull (ex.ParamName, "#5");
841 Assert.AreEqual ("address", ex.ParamName, "#6");
845 [Test] // UploadFile (string, string)
846 public void UploadFile1_Address_SchemeNotSupported ()
848 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
849 File.Create (tempFile).Close ();
851 WebClient wc = new WebClient ();
853 wc.UploadFile ("tp://scheme.notsupported",
856 } catch (WebException ex) {
857 // An error occurred performing a WebClient request
858 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
859 Assert.IsNotNull (ex.InnerException, "#3");
860 Assert.IsNotNull (ex.Message, "#4");
861 Assert.IsNull (ex.Response, "#5");
862 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
864 // The URI prefix is not recognized
865 Exception inner = ex.InnerException;
866 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
867 Assert.IsNull (inner.InnerException, "#8");
868 Assert.IsNotNull (inner.Message, "#9");
872 [Test] // UploadFile (string, string)
873 public void UploadFile1_FileName_NotFound ()
875 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
877 WebClient wc = new WebClient ();
879 wc.UploadFile ("tp://scheme.notsupported",
882 } catch (WebException ex) {
883 // An error occurred performing a WebClient request
884 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
885 Assert.IsNotNull (ex.Message, "#3");
886 Assert.IsNull (ex.Response, "#4");
887 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
889 // Could not find file "..."
890 FileNotFoundException inner = ex.InnerException
891 as FileNotFoundException;
892 Assert.IsNotNull (inner, "#6");
893 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
894 Assert.IsNotNull (inner.FileName, "#8");
895 Assert.AreEqual (tempFile, inner.FileName, "#9");
896 Assert.IsNull (inner.InnerException, "#10");
897 Assert.IsNotNull (inner.Message, "#11");
901 [Test] // UploadFile (string, string)
902 public void UploadFile1_FileName_Null ()
904 WebClient wc = new WebClient ();
906 wc.UploadFile ("tp://scheme.notsupported",
909 } catch (ArgumentNullException ex) {
910 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
911 Assert.IsNull (ex.InnerException, "#3");
912 Assert.IsNotNull (ex.Message, "#4");
913 Assert.IsNotNull (ex.ParamName, "#5");
914 Assert.AreEqual ("fileName", ex.ParamName, "#6");
918 [Test] // UploadFile (Uri, string)
919 public void UploadFile2_Address_Null ()
921 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
923 WebClient wc = new WebClient ();
925 wc.UploadFile ((Uri) null, tempFile);
927 } catch (ArgumentNullException ex) {
928 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
929 Assert.IsNull (ex.InnerException, "#3");
930 Assert.IsNotNull (ex.Message, "#4");
931 Assert.IsNotNull (ex.ParamName, "#5");
932 Assert.AreEqual ("address", ex.ParamName, "#6");
936 [Test] // UploadFile (Uri, string)
937 public void UploadFile2_Address_SchemeNotSupported ()
939 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
940 File.Create (tempFile).Close ();
942 WebClient wc = new WebClient ();
944 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
947 } catch (WebException ex) {
948 // An error occurred performing a WebClient request
949 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
950 Assert.IsNotNull (ex.InnerException, "#3");
951 Assert.IsNotNull (ex.Message, "#4");
952 Assert.IsNull (ex.Response, "#5");
953 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
955 // The URI prefix is not recognized
956 Exception inner = ex.InnerException;
957 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
958 Assert.IsNull (inner.InnerException, "#8");
959 Assert.IsNotNull (inner.Message, "#9");
963 [Test] // UploadFile (Uri, string)
964 public void UploadFile2_FileName_NotFound ()
966 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
968 WebClient wc = new WebClient ();
970 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
973 } catch (WebException ex) {
974 // An error occurred performing a WebClient request
975 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
976 Assert.IsNotNull (ex.Message, "#3");
977 Assert.IsNull (ex.Response, "#4");
978 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
980 // Could not find file "..."
981 FileNotFoundException inner = ex.InnerException
982 as FileNotFoundException;
983 Assert.IsNotNull (inner, "#6");
984 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
985 Assert.IsNotNull (inner.FileName, "#8");
986 Assert.AreEqual (tempFile, inner.FileName, "#9");
987 Assert.IsNull (inner.InnerException, "#10");
988 Assert.IsNotNull (inner.Message, "#11");
992 [Test] // UploadFile (Uri, string)
993 public void UploadFile2_FileName_Null ()
995 WebClient wc = new WebClient ();
997 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1000 } catch (ArgumentNullException ex) {
1001 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1002 Assert.IsNull (ex.InnerException, "#3");
1003 Assert.IsNotNull (ex.Message, "#4");
1004 Assert.IsNotNull (ex.ParamName, "#5");
1005 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1009 [Test] // UploadFile (string, string, string)
1010 public void UploadFile3_Address_Null ()
1012 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1013 File.Create (tempFile).Close ();
1015 WebClient wc = new WebClient ();
1017 wc.UploadFile ((string) null, "POST", tempFile);
1019 } catch (ArgumentNullException ex) {
1020 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1021 Assert.IsNull (ex.InnerException, "#3");
1022 Assert.IsNotNull (ex.Message, "#4");
1023 Assert.IsNotNull (ex.ParamName, "#5");
1024 Assert.AreEqual ("path", ex.ParamName, "#6");
1028 [Test] // UploadFile (string, string, string)
1029 public void UploadFile3_Address_SchemeNotSupported ()
1031 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1032 File.Create (tempFile).Close ();
1034 WebClient wc = new WebClient ();
1036 wc.UploadFile ("tp://scheme.notsupported",
1039 } catch (WebException ex) {
1040 // An error occurred performing a WebClient request
1041 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1042 Assert.IsNotNull (ex.InnerException, "#3");
1043 Assert.IsNotNull (ex.Message, "#4");
1044 Assert.IsNull (ex.Response, "#5");
1045 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1047 // The URI prefix is not recognized
1048 Exception inner = ex.InnerException;
1049 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1050 Assert.IsNull (inner.InnerException, "#8");
1051 Assert.IsNotNull (inner.Message, "#9");
1055 [Test] // UploadFile (string, string, string)
1056 public void UploadFile3_FileName_NotFound ()
1058 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1060 WebClient wc = new WebClient ();
1062 wc.UploadFile ("tp://scheme.notsupported",
1065 } catch (WebException ex) {
1066 // An error occurred performing a WebClient request
1067 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1068 Assert.IsNotNull (ex.Message, "#3");
1069 Assert.IsNull (ex.Response, "#4");
1070 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1072 // Could not find file "..."
1073 FileNotFoundException inner = ex.InnerException
1074 as FileNotFoundException;
1075 Assert.IsNotNull (inner, "#6");
1076 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1077 Assert.IsNotNull (inner.FileName, "#8");
1078 Assert.AreEqual (tempFile, inner.FileName, "#9");
1079 Assert.IsNull (inner.InnerException, "#10");
1080 Assert.IsNotNull (inner.Message, "#11");
1084 [Test] // UploadFile (string, string, string)
1085 public void UploadFile3_FileName_Null ()
1087 WebClient wc = new WebClient ();
1089 wc.UploadFile ("tp://scheme.notsupported",
1090 "POST", (string) null);
1092 } catch (ArgumentNullException ex) {
1093 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1094 Assert.IsNull (ex.InnerException, "#3");
1095 Assert.IsNotNull (ex.Message, "#4");
1096 Assert.IsNotNull (ex.ParamName, "#5");
1097 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1101 [Test] // UploadFile (Uri, string, string)
1102 public void UploadFile4_Address_Null ()
1104 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1106 WebClient wc = new WebClient ();
1108 wc.UploadFile ((Uri) null, "POST", tempFile);
1110 } catch (ArgumentNullException ex) {
1111 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1112 Assert.IsNull (ex.InnerException, "#3");
1113 Assert.IsNotNull (ex.Message, "#4");
1114 Assert.IsNotNull (ex.ParamName, "#5");
1115 Assert.AreEqual ("address", ex.ParamName, "#6");
1119 [Test] // UploadFile (Uri, string, string)
1120 public void UploadFile4_Address_SchemeNotSupported ()
1122 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1123 File.Create (tempFile).Close ();
1125 WebClient wc = new WebClient ();
1127 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1130 } catch (WebException ex) {
1131 // An error occurred performing a WebClient request
1132 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1133 Assert.IsNotNull (ex.InnerException, "#3");
1134 Assert.IsNotNull (ex.Message, "#4");
1135 Assert.IsNull (ex.Response, "#5");
1136 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1138 // The URI prefix is not recognized
1139 Exception inner = ex.InnerException;
1140 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1141 Assert.IsNull (inner.InnerException, "#8");
1142 Assert.IsNotNull (inner.Message, "#9");
1146 [Test] // UploadFile (Uri, string, string)
1147 public void UploadFile4_FileName_NotFound ()
1149 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1151 WebClient wc = new WebClient ();
1153 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1156 } catch (WebException ex) {
1157 // An error occurred performing a WebClient request
1158 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1159 Assert.IsNotNull (ex.Message, "#3");
1160 Assert.IsNull (ex.Response, "#4");
1161 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1163 // Could not find file "..."
1164 FileNotFoundException inner = ex.InnerException
1165 as FileNotFoundException;
1166 Assert.IsNotNull (inner, "#6");
1167 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1168 Assert.IsNotNull (inner.FileName, "#8");
1169 Assert.AreEqual (tempFile, inner.FileName, "#9");
1170 Assert.IsNull (inner.InnerException, "#10");
1171 Assert.IsNotNull (inner.Message, "#11");
1175 [Test] // UploadFile (Uri, string, string)
1176 public void UploadFile4_FileName_Null ()
1178 WebClient wc = new WebClient ();
1180 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1181 "POST", (string) null);
1183 } catch (ArgumentNullException ex) {
1184 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1185 Assert.IsNull (ex.InnerException, "#3");
1186 Assert.IsNotNull (ex.Message, "#4");
1187 Assert.IsNotNull (ex.ParamName, "#5");
1188 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1192 [Test] // UploadString (string, string)
1193 public void UploadString1_Address_Null ()
1195 WebClient wc = new WebClient ();
1197 wc.UploadString ((string) null, (string) null);
1199 } catch (ArgumentNullException ex) {
1200 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1201 Assert.IsNull (ex.InnerException, "#3");
1202 Assert.IsNotNull (ex.Message, "#4");
1203 Assert.IsNotNull (ex.ParamName, "#5");
1204 Assert.AreEqual ("address", ex.ParamName, "#6");
1208 [Test] // UploadString (string, string)
1209 public void UploadString1_Address_SchemeNotSupported ()
1211 WebClient wc = new WebClient ();
1213 wc.UploadString ("tp://scheme.notsupported", "abc");
1215 } catch (WebException ex) {
1216 // An error occurred performing a WebClient request
1217 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1218 Assert.IsNotNull (ex.InnerException, "#3");
1219 Assert.IsNotNull (ex.Message, "#4");
1220 Assert.IsNull (ex.Response, "#5");
1221 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1223 // The URI prefix is not recognized
1224 Exception inner = ex.InnerException;
1225 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1226 Assert.IsNull (inner.InnerException, "#8");
1227 Assert.IsNotNull (inner.Message, "#9");
1231 [Test] // UploadString (string, string)
1232 public void UploadString1_Data_Null ()
1234 WebClient wc = new WebClient ();
1236 wc.UploadString ("tp://scheme.notsupported", (string) null);
1238 } catch (ArgumentNullException ex) {
1239 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1240 Assert.IsNull (ex.InnerException, "#3");
1241 Assert.IsNotNull (ex.Message, "#4");
1242 Assert.IsNotNull (ex.ParamName, "#5");
1243 Assert.AreEqual ("data", ex.ParamName, "#6");
1247 [Test] // UploadString (Uri, string)
1248 public void UploadString2_Address_Null ()
1250 WebClient wc = new WebClient ();
1252 wc.UploadString ((Uri) null, (string) null);
1254 } catch (ArgumentNullException ex) {
1255 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1256 Assert.IsNull (ex.InnerException, "#3");
1257 Assert.IsNotNull (ex.Message, "#4");
1258 Assert.IsNotNull (ex.ParamName, "#5");
1259 Assert.AreEqual ("address", ex.ParamName, "#6");
1263 [Test] // UploadString (Uri, string)
1264 public void UploadString2_Address_SchemeNotSupported ()
1266 WebClient wc = new WebClient ();
1268 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1270 } catch (WebException ex) {
1271 // An error occurred performing a WebClient request
1272 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1273 Assert.IsNotNull (ex.InnerException, "#3");
1274 Assert.IsNotNull (ex.Message, "#4");
1275 Assert.IsNull (ex.Response, "#5");
1276 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1278 // The URI prefix is not recognized
1279 Exception inner = ex.InnerException;
1280 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1281 Assert.IsNull (inner.InnerException, "#8");
1282 Assert.IsNotNull (inner.Message, "#9");
1286 [Test] // UploadString (Uri, string)
1287 public void UploadString2_Data_Null ()
1289 WebClient wc = new WebClient ();
1291 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1294 } catch (ArgumentNullException ex) {
1295 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1296 Assert.IsNull (ex.InnerException, "#3");
1297 Assert.IsNotNull (ex.Message, "#4");
1298 Assert.IsNotNull (ex.ParamName, "#5");
1299 Assert.AreEqual ("data", ex.ParamName, "#6");
1303 [Test] // UploadString (string, string, string)
1304 public void UploadString3_Address_Null ()
1306 WebClient wc = new WebClient ();
1308 wc.UploadString ((string) null, (string) null,
1311 } catch (ArgumentNullException ex) {
1312 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1313 Assert.IsNull (ex.InnerException, "#3");
1314 Assert.IsNotNull (ex.Message, "#4");
1315 Assert.IsNotNull (ex.ParamName, "#5");
1316 Assert.AreEqual ("address", ex.ParamName, "#6");
1320 [Test] // UploadString (string, string, string)
1321 public void UploadString3_Address_SchemeNotSupported ()
1323 WebClient wc = new WebClient ();
1325 wc.UploadString ("tp://scheme.notsupported",
1328 } catch (WebException ex) {
1329 // An error occurred performing a WebClient request
1330 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1331 Assert.IsNotNull (ex.InnerException, "#3");
1332 Assert.IsNotNull (ex.Message, "#4");
1333 Assert.IsNull (ex.Response, "#5");
1334 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1336 // The URI prefix is not recognized
1337 Exception inner = ex.InnerException;
1338 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1339 Assert.IsNull (inner.InnerException, "#8");
1340 Assert.IsNotNull (inner.Message, "#9");
1344 [Test] // UploadString (string, string, string)
1345 public void UploadString3_Data_Null ()
1347 WebClient wc = new WebClient ();
1349 wc.UploadString ("tp://scheme.notsupported",
1350 "POST", (string) null);
1352 } catch (ArgumentNullException ex) {
1353 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1354 Assert.IsNull (ex.InnerException, "#3");
1355 Assert.IsNotNull (ex.Message, "#4");
1356 Assert.IsNotNull (ex.ParamName, "#5");
1357 Assert.AreEqual ("data", ex.ParamName, "#6");
1361 [Test] // UploadString (Uri, string, string)
1362 public void UploadString4_Address_Null ()
1364 WebClient wc = new WebClient ();
1366 wc.UploadString ((Uri) null, (string) null,
1369 } catch (ArgumentNullException ex) {
1370 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1371 Assert.IsNull (ex.InnerException, "#3");
1372 Assert.IsNotNull (ex.Message, "#4");
1373 Assert.IsNotNull (ex.ParamName, "#5");
1374 Assert.AreEqual ("address", ex.ParamName, "#6");
1378 [Test] // UploadString (Uri, string, string)
1379 public void UploadString4_Address_SchemeNotSupported ()
1381 WebClient wc = new WebClient ();
1383 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1386 } catch (WebException ex) {
1387 // An error occurred performing a WebClient request
1388 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1389 Assert.IsNotNull (ex.InnerException, "#3");
1390 Assert.IsNotNull (ex.Message, "#4");
1391 Assert.IsNull (ex.Response, "#5");
1392 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1394 // The URI prefix is not recognized
1395 Exception inner = ex.InnerException;
1396 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1397 Assert.IsNull (inner.InnerException, "#8");
1398 Assert.IsNotNull (inner.Message, "#9");
1402 [Test] // UploadString (Uri, string, string)
1403 public void UploadString4_Data_Null ()
1405 WebClient wc = new WebClient ();
1407 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1408 "POST", (string) null);
1410 } catch (ArgumentNullException ex) {
1411 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1412 Assert.IsNull (ex.InnerException, "#3");
1413 Assert.IsNotNull (ex.Message, "#4");
1414 Assert.IsNotNull (ex.ParamName, "#5");
1415 Assert.AreEqual ("data", ex.ParamName, "#6");
1420 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1421 public void UploadValues1 ()
1423 IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
1424 string url = "http://" + ep.ToString () + "/test/";
1426 using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) {
1427 WebClient wc = new WebClient ();
1428 wc.Encoding = Encoding.ASCII;
1430 NameValueCollection nvc = new NameValueCollection ();
1431 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1432 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1434 byte [] buffer = wc.UploadValues (url, nvc);
1435 string response = Encoding.UTF8.GetString (buffer);
1436 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1440 [Test] // UploadValues (string, NameValueCollection)
1441 public void UploadValues1_Address_Null ()
1443 WebClient wc = new WebClient ();
1445 wc.UploadValues ((string) null, new NameValueCollection ());
1447 } catch (ArgumentNullException ex) {
1448 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1449 Assert.IsNull (ex.InnerException, "#3");
1450 Assert.IsNotNull (ex.Message, "#4");
1451 Assert.IsNotNull (ex.ParamName, "#5");
1452 Assert.AreEqual ("address", ex.ParamName, "#6");
1456 [Test] // UploadValues (string, NameValueCollection)
1457 public void UploadValues1_Address_SchemeNotSupported ()
1459 WebClient wc = new WebClient ();
1461 wc.UploadValues ("tp://scheme.notsupported",
1462 new NameValueCollection ());
1464 } catch (WebException ex) {
1465 // An error occurred performing a WebClient request
1466 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1467 Assert.IsNotNull (ex.InnerException, "#3");
1468 Assert.IsNotNull (ex.Message, "#4");
1469 Assert.IsNull (ex.Response, "#5");
1470 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1472 // The URI prefix is not recognized
1473 Exception inner = ex.InnerException;
1474 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1475 Assert.IsNull (inner.InnerException, "#8");
1476 Assert.IsNotNull (inner.Message, "#9");
1480 [Test] // UploadValues (string, NameValueCollection)
1481 public void UploadValues1_Data_Null ()
1483 WebClient wc = new WebClient ();
1485 wc.UploadValues ("http://www.mono-project.com",
1486 (NameValueCollection) null);
1488 } catch (ArgumentNullException ex) {
1489 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1490 Assert.IsNull (ex.InnerException, "#3");
1491 Assert.IsNotNull (ex.Message, "#4");
1492 Assert.IsNotNull (ex.ParamName, "#5");
1493 Assert.AreEqual ("data", ex.ParamName, "#6");
1497 [Test] // UploadValues (Uri, NameValueCollection)
1498 public void UploadValues2_Address_Null ()
1500 WebClient wc = new WebClient ();
1502 wc.UploadValues ((Uri) null, new NameValueCollection ());
1504 } catch (ArgumentNullException ex) {
1505 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1506 Assert.IsNull (ex.InnerException, "#3");
1507 Assert.IsNotNull (ex.Message, "#4");
1508 Assert.IsNotNull (ex.ParamName, "#5");
1509 Assert.AreEqual ("address", ex.ParamName, "#6");
1513 [Test] // UploadValues (Uri, NameValueCollection)
1514 public void UploadValues2_Address_SchemeNotSupported ()
1516 WebClient wc = new WebClient ();
1518 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1519 new NameValueCollection ());
1521 } catch (WebException ex) {
1522 // An error occurred performing a WebClient request
1523 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1524 Assert.IsNotNull (ex.InnerException, "#3");
1525 Assert.IsNotNull (ex.Message, "#4");
1526 Assert.IsNull (ex.Response, "#5");
1527 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1529 // The URI prefix is not recognized
1530 Exception inner = ex.InnerException;
1531 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1532 Assert.IsNull (inner.InnerException, "#8");
1533 Assert.IsNotNull (inner.Message, "#9");
1537 [Test] // UploadValues (Uri, NameValueCollection)
1538 public void UploadValues2_Data_Null ()
1540 WebClient wc = new WebClient ();
1542 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1543 (NameValueCollection) null);
1545 } catch (ArgumentNullException ex) {
1546 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1547 Assert.IsNull (ex.InnerException, "#3");
1548 Assert.IsNotNull (ex.Message, "#4");
1549 Assert.IsNotNull (ex.ParamName, "#5");
1550 Assert.AreEqual ("data", ex.ParamName, "#6");
1554 [Test] // UploadValues (string, string, NameValueCollection)
1555 public void UploadValues3_Address_Null ()
1557 WebClient wc = new WebClient ();
1559 wc.UploadValues ((string) null, "POST",
1560 new NameValueCollection ());
1562 } catch (ArgumentNullException ex) {
1563 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1564 Assert.IsNull (ex.InnerException, "#3");
1565 Assert.IsNotNull (ex.Message, "#4");
1566 Assert.IsNotNull (ex.ParamName, "#5");
1567 Assert.AreEqual ("address", ex.ParamName, "#6");
1571 [Test] // UploadValues (string, string, NameValueCollection)
1572 public void UploadValues3_Address_SchemeNotSupported ()
1574 WebClient wc = new WebClient ();
1576 wc.UploadValues ("tp://scheme.notsupported",
1577 "POST", new NameValueCollection ());
1579 } catch (WebException ex) {
1580 // An error occurred performing a WebClient request
1581 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1582 Assert.IsNotNull (ex.InnerException, "#3");
1583 Assert.IsNotNull (ex.Message, "#4");
1584 Assert.IsNull (ex.Response, "#5");
1585 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1587 // The URI prefix is not recognized
1588 Exception inner = ex.InnerException;
1589 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1590 Assert.IsNull (inner.InnerException, "#8");
1591 Assert.IsNotNull (inner.Message, "#9");
1595 [Test] // UploadValues (string, string, NameValueCollection)
1596 public void UploadValues3_Data_Null ()
1598 WebClient wc = new WebClient ();
1600 wc.UploadValues ("http://www.mono-project.com",
1601 "POST", (NameValueCollection) null);
1603 } catch (ArgumentNullException ex) {
1604 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1605 Assert.IsNull (ex.InnerException, "#3");
1606 Assert.IsNotNull (ex.Message, "#4");
1607 Assert.IsNotNull (ex.ParamName, "#5");
1608 Assert.AreEqual ("data", ex.ParamName, "#6");
1612 [Test] // UploadValues (Uri, string, NameValueCollection)
1613 public void UploadValues4_Address_Null ()
1615 WebClient wc = new WebClient ();
1617 wc.UploadValues ((Uri) null, "POST",
1618 new NameValueCollection ());
1620 } catch (ArgumentNullException ex) {
1621 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1622 Assert.IsNull (ex.InnerException, "#3");
1623 Assert.IsNotNull (ex.Message, "#4");
1624 Assert.IsNotNull (ex.ParamName, "#5");
1625 Assert.AreEqual ("address", ex.ParamName, "#6");
1629 [Test] // UploadValues (Uri, string, NameValueCollection)
1630 public void UploadValues4_Address_SchemeNotSupported ()
1632 WebClient wc = new WebClient ();
1634 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1635 "POST", new NameValueCollection ());
1637 } catch (WebException ex) {
1638 // An error occurred performing a WebClient request
1639 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1640 Assert.IsNotNull (ex.InnerException, "#3");
1641 Assert.IsNotNull (ex.Message, "#4");
1642 Assert.IsNull (ex.Response, "#5");
1643 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1645 // The URI prefix is not recognized
1646 Exception inner = ex.InnerException;
1647 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1648 Assert.IsNull (inner.InnerException, "#8");
1649 Assert.IsNotNull (inner.Message, "#9");
1653 [Test] // UploadValues (Uri, string, NameValueCollection)
1654 public void UploadValues4_Data_Null ()
1656 WebClient wc = new WebClient ();
1658 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1659 "POST", (NameValueCollection) null);
1661 } catch (ArgumentNullException ex) {
1662 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1663 Assert.IsNull (ex.InnerException, "#3");
1664 Assert.IsNotNull (ex.Message, "#4");
1665 Assert.IsNotNull (ex.ParamName, "#5");
1666 Assert.AreEqual ("data", ex.ParamName, "#6");
1671 public void GetWebRequestOverriding ()
1673 GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1674 testObject.DownloadData ("http://www.mono-project.com");
1676 Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1679 class GetWebRequestOverridingTestClass : WebClient
1681 internal bool overridedCodeRan = false;
1682 protected override WebRequest GetWebRequest(Uri address)
1684 overridedCodeRan = true;
1685 return base.GetWebRequest (address);
1689 static byte [] EchoRequestHandler (Socket socket)
1691 MemoryStream ms = new MemoryStream ();
1692 byte [] buffer = new byte [4096];
1693 int bytesReceived = socket.Receive (buffer);
1694 while (bytesReceived > 0) {
1695 ms.Write (buffer, 0, bytesReceived);
1696 // We don't check for Content-Length or anything else here, so we give the client a little time to write
1697 // after sending the headers
1699 if (socket.Available > 0) {
1700 bytesReceived = socket.Receive (buffer);
1708 StringBuilder sb = new StringBuilder ();
1710 string expect = null;
1712 StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1715 while ((line = sr.ReadLine ()) != null) {
1720 } if (line.Length == 0) {
1722 } else if (line.StartsWith ("Expect:")) {
1723 expect = line.Substring (8);
1727 StringWriter sw = new StringWriter ();
1729 if (expect == "100-continue" && state != 2) {
1730 sw.WriteLine ("HTTP/1.1 100 Continue");
1734 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1737 ms = new MemoryStream ();
1738 buffer = new byte [4096];
1739 bytesReceived = socket.Receive (buffer);
1740 while (bytesReceived > 0) {
1741 ms.Write (buffer, 0, bytesReceived);
1743 if (socket.Available > 0) {
1744 bytesReceived = socket.Receive (buffer);
1752 sb = new StringBuilder ();
1753 sr = new StreamReader (ms, Encoding.UTF8);
1754 line = sr.ReadLine ();
1755 while (line != null) {
1758 line = sr.ReadLine ();
1762 sw = new StringWriter ();
1763 sw.WriteLine ("HTTP/1.1 200 OK");
1764 sw.WriteLine ("Content-Type: text/xml");
1765 sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1767 sw.Write (sb.ToString ());
1770 return Encoding.UTF8.GetBytes (sw.ToString ());
1774 public void DefaultProxy ()
1776 WebClient wc = new WebClient ();
1777 // this is never null on .net
1778 Assert.IsNotNull (wc.Proxy);
1779 // and return the same instance as WebRequest.DefaultWebProxy
1780 Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1785 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1786 public void UploadStringAsyncCancelEvent ()
1788 UploadAsyncCancelEventTest (9301, (webClient, uri, cancelEvent) =>
1791 webClient.UploadStringCompleted += (sender, args) =>
1797 webClient.UploadStringAsync (uri, "PUT", "text");
1802 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1803 public void UploadDataAsyncCancelEvent ()
1805 UploadAsyncCancelEventTest (9302, (webClient, uri, cancelEvent) =>
1807 webClient.UploadDataCompleted += (sender, args) =>
1813 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1818 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1819 public void UploadValuesAsyncCancelEvent ()
1821 UploadAsyncCancelEventTest (9303, (webClient, uri, cancelEvent) =>
1823 webClient.UploadValuesCompleted += (sender, args) =>
1829 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1834 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1835 public void UploadFileAsyncCancelEvent ()
1837 UploadAsyncCancelEventTest (9304,(webClient, uri, cancelEvent) =>
1839 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1840 File.Create (tempFile).Close ();
1842 webClient.UploadFileCompleted += (sender, args) =>
1848 webClient.UploadFileAsync (uri, "PUT", tempFile);
1853 [Category ("AndroidNotWorking")] // Test suite hangs if the tests runs as part of the entire BCL suite. Works when only this fixture is ran
1854 public void UploadFileAsyncContentType ()
1856 var port = NetworkHelpers.FindFreePort ();
1857 var serverUri = "http://localhost:" + port + "/";
1858 var filename = Path.GetTempFileName ();
1860 HttpListener listener = new HttpListener ();
1861 listener.Prefixes.Add (serverUri);
1864 using (var client = new WebClient ())
1866 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1867 var request = listener.GetContext ().Request;
1869 var expected = "multipart/form-data; boundary=---------------------";
1870 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1871 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1877 public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
1879 var ep = NetworkHelpers.LocalEphemeralEndPoint ();
1880 string url = "http://" + ep.ToString() + "/test/";
1882 using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s)))
1884 var webClient = new WebClient ();
1886 var cancellationTokenSource = new CancellationTokenSource ();
1887 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1889 var cancelEvent = new ManualResetEvent (false);
1891 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1893 cancellationTokenSource.Cancel ();
1895 Assert.IsTrue (cancelEvent.WaitOne (1000));