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 public void DownloadTwice ()
48 WebClient wc = new WebClient();
49 string filename = Path.GetTempFileName();
51 // A new, but empty file has been created. This is a test case
53 wc.DownloadFile("http://google.com/", filename);
55 // Now, remove the file and attempt to download again.
56 File.Delete(filename);
57 wc.DownloadFile("http://google.com/", filename);
61 public void DownloadData1_Address_Null ()
63 WebClient wc = new WebClient ();
65 wc.DownloadData ((string) null);
67 } catch (ArgumentNullException ex) {
68 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
69 Assert.IsNull (ex.InnerException, "#3");
70 Assert.IsNotNull (ex.Message, "#4");
71 Assert.IsNotNull (ex.ParamName, "#5");
72 Assert.AreEqual ("address", ex.ParamName, "#6");
76 [Test] // DownloadData (string)
77 public void DownloadData1_Address_SchemeNotSupported ()
79 WebClient wc = new WebClient ();
81 wc.DownloadData ("tp://scheme.notsupported");
83 } catch (WebException ex) {
84 // An error occurred performing a WebClient request
85 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
86 Assert.IsNotNull (ex.InnerException, "#3");
87 Assert.IsNotNull (ex.Message, "#4");
88 Assert.IsNull (ex.Response, "#5");
89 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
91 // The URI prefix is not recognized
92 Exception inner = ex.InnerException;
93 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
94 Assert.IsNull (inner.InnerException, "#8");
95 Assert.IsNotNull (inner.Message, "#9");
99 [Test] // DownloadData (Uri)
100 public void DownloadData2_Address_Null ()
102 WebClient wc = new WebClient ();
104 wc.DownloadData ((Uri) null);
106 } catch (ArgumentNullException ex) {
107 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
108 Assert.IsNull (ex.InnerException, "#3");
109 Assert.IsNotNull (ex.Message, "#4");
110 Assert.IsNotNull (ex.ParamName, "#5");
111 Assert.AreEqual ("address", ex.ParamName, "#6");
115 [Test] // DownloadData (Uri)
116 public void DownloadData2_Address_SchemeNotSupported ()
118 WebClient wc = new WebClient ();
120 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
122 } catch (WebException ex) {
123 // An error occurred performing a WebClient request
124 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
125 Assert.IsNotNull (ex.InnerException, "#3");
126 Assert.IsNotNull (ex.Message, "#4");
127 Assert.IsNull (ex.Response, "#5");
128 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
130 // The URI prefix is not recognized
131 Exception inner = ex.InnerException;
132 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
133 Assert.IsNull (inner.InnerException, "#8");
134 Assert.IsNotNull (inner.Message, "#9");
139 public void DownloadFile1_Address_Null ()
141 WebClient wc = new WebClient ();
143 wc.DownloadFile ((string) null, "tmp.out");
145 } catch (ArgumentNullException ex) {
146 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
147 Assert.IsNull (ex.InnerException, "#3");
148 Assert.IsNotNull (ex.Message, "#4");
149 Assert.IsNotNull (ex.ParamName, "#5");
150 Assert.AreEqual ("address", ex.ParamName, "#6");
154 [Test] // DownloadFile (string, string)
155 public void DownloadFile1_Address_SchemeNotSupported ()
157 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
158 WebClient wc = new WebClient ();
160 wc.DownloadFile ("tp://scheme.notsupported", file);
162 } catch (WebException ex) {
163 // An error occurred performing a WebClient request
164 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
165 Assert.IsNotNull (ex.InnerException, "#3");
166 Assert.IsNotNull (ex.Message, "#4");
167 Assert.IsNull (ex.Response, "#5");
168 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
170 // The URI prefix is not recognized
171 Exception inner = ex.InnerException;
172 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
173 Assert.IsNull (inner.InnerException, "#8");
174 Assert.IsNotNull (inner.Message, "#9");
177 if (File.Exists (file))
182 [Test] // DownloadFile (string, string)
183 public void DownloadFile1_FileName_Null ()
185 WebClient wc = new WebClient ();
187 wc.DownloadFile ("tp://scheme.notsupported",
190 } catch (ArgumentNullException ex) {
191 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
192 Assert.IsNull (ex.InnerException, "#3");
193 Assert.IsNotNull (ex.Message, "#4");
194 Assert.IsNotNull (ex.ParamName, "#5");
195 Assert.AreEqual ("fileName", ex.ParamName, "#6");
199 [Test] // DownloadFile (Uri, string)
200 public void DownloadFile2_Address_Null ()
202 WebClient wc = new WebClient ();
204 wc.DownloadFile ((Uri) null, "tmp.out");
206 } catch (ArgumentNullException ex) {
207 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
208 Assert.IsNull (ex.InnerException, "#3");
209 Assert.IsNotNull (ex.Message, "#4");
210 Assert.IsNotNull (ex.ParamName, "#5");
211 Assert.AreEqual ("address", ex.ParamName, "#6");
215 [Test] // DownloadFile (Uri, string)
216 public void DownloadFile2_Address_SchemeNotSupported ()
218 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
219 WebClient wc = new WebClient ();
221 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
223 } catch (WebException ex) {
224 // An error occurred performing a WebClient request
225 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
226 Assert.IsNotNull (ex.InnerException, "#3");
227 Assert.IsNotNull (ex.Message, "#4");
228 Assert.IsNull (ex.Response, "#5");
229 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
231 // The URI prefix is not recognized
232 Exception inner = ex.InnerException;
233 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
234 Assert.IsNull (inner.InnerException, "#8");
235 Assert.IsNotNull (inner.Message, "#9");
238 if (File.Exists (file))
243 [Test] // DownloadFile (Uri, string)
244 public void DownloadFile2_FileName_Null ()
246 WebClient wc = new WebClient ();
248 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
251 } catch (ArgumentNullException ex) {
252 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
253 Assert.IsNull (ex.InnerException, "#3");
254 Assert.IsNotNull (ex.Message, "#4");
255 Assert.IsNotNull (ex.ParamName, "#5");
256 Assert.AreEqual ("fileName", ex.ParamName, "#6");
260 [Test] // DownloadString (string)
261 public void DownloadString1_Address_Null ()
263 WebClient wc = new WebClient ();
265 wc.DownloadString ((string) null);
267 } catch (ArgumentNullException ex) {
268 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
269 Assert.IsNull (ex.InnerException, "#3");
270 Assert.IsNotNull (ex.Message, "#4");
271 Assert.IsNotNull (ex.ParamName, "#5");
272 Assert.AreEqual ("address", ex.ParamName, "#6");
276 [Test] // DownloadString (string)
277 public void DownloadString1_Address_SchemeNotSupported ()
279 WebClient wc = new WebClient ();
281 wc.DownloadString ("tp://scheme.notsupported");
283 } catch (WebException ex) {
284 // An error occurred performing a WebClient request
285 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
286 Assert.IsNotNull (ex.InnerException, "#3");
287 Assert.IsNotNull (ex.Message, "#4");
288 Assert.IsNull (ex.Response, "#5");
289 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
291 // The URI prefix is not recognized
292 Exception inner = ex.InnerException;
293 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
294 Assert.IsNull (inner.InnerException, "#8");
295 Assert.IsNotNull (inner.Message, "#9");
299 [Test] // DownloadString (Uri)
300 public void DownloadString2_Address_Null ()
302 WebClient wc = new WebClient ();
304 wc.DownloadString ((Uri) null);
306 } catch (ArgumentNullException ex) {
307 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
308 Assert.IsNull (ex.InnerException, "#3");
309 Assert.IsNotNull (ex.Message, "#4");
310 Assert.IsNotNull (ex.ParamName, "#5");
311 Assert.AreEqual ("address", ex.ParamName, "#6");
315 [Test] // DownloadString (Uri)
316 public void DownloadString2_Address_SchemeNotSupported ()
318 WebClient wc = new WebClient ();
320 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
322 } catch (WebException ex) {
323 // An error occurred performing a WebClient request
324 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
325 Assert.IsNotNull (ex.InnerException, "#3");
326 Assert.IsNotNull (ex.Message, "#4");
327 Assert.IsNull (ex.Response, "#5");
328 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
330 // The URI prefix is not recognized
331 Exception inner = ex.InnerException;
332 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
333 Assert.IsNull (inner.InnerException, "#8");
334 Assert.IsNotNull (inner.Message, "#9");
339 public void EncodingTest ()
341 WebClient wc = new WebClient ();
342 Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
343 wc.Encoding = Encoding.ASCII;
344 Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
348 public void Encoding_Value_Null ()
350 WebClient wc = new WebClient ();
354 } catch (ArgumentNullException ex) {
355 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
356 Assert.IsNull (ex.InnerException, "#3");
357 Assert.IsNotNull (ex.Message, "#4");
358 Assert.AreEqual ("Encoding", ex.ParamName, "#6");
362 [Test] // OpenRead (string)
363 public void OpenRead1_Address_Null ()
365 WebClient wc = new WebClient ();
367 wc.OpenRead ((string) null);
369 } catch (ArgumentNullException ex) {
370 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
371 Assert.IsNull (ex.InnerException, "#3");
372 Assert.IsNotNull (ex.Message, "#4");
373 Assert.IsNotNull (ex.ParamName, "#5");
374 Assert.AreEqual ("address", ex.ParamName, "#6");
378 [Test] // OpenRead (string)
379 public void OpenRead1_Address_SchemeNotSupported ()
381 WebClient wc = new WebClient ();
383 wc.OpenRead ("tp://scheme.notsupported");
385 } catch (WebException ex) {
386 // An error occurred performing a WebClient request
387 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
388 Assert.IsNotNull (ex.InnerException, "#3");
389 Assert.IsNotNull (ex.Message, "#4");
390 Assert.IsNull (ex.Response, "#5");
391 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
393 // The URI prefix is not recognized
394 Exception inner = ex.InnerException;
395 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
396 Assert.IsNull (inner.InnerException, "#8");
397 Assert.IsNotNull (inner.Message, "#9");
401 [Test] // OpenRead (Uri)
402 public void OpenRead2_Address_Null ()
404 WebClient wc = new WebClient ();
406 wc.OpenRead ((Uri) null);
408 } catch (ArgumentNullException ex) {
409 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
410 Assert.IsNull (ex.InnerException, "#3");
411 Assert.IsNotNull (ex.Message, "#4");
412 Assert.IsNotNull (ex.ParamName, "#5");
413 Assert.AreEqual ("address", ex.ParamName, "#6");
417 [Test] // OpenRead (Uri)
418 public void OpenRead2_Address_SchemeNotSupported ()
420 WebClient wc = new WebClient ();
422 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
424 } catch (WebException ex) {
425 // An error occurred performing a WebClient request
426 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
427 Assert.IsNotNull (ex.InnerException, "#3");
428 Assert.IsNotNull (ex.Message, "#4");
429 Assert.IsNull (ex.Response, "#5");
430 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
432 // The URI prefix is not recognized
433 Exception inner = ex.InnerException;
434 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
435 Assert.IsNull (inner.InnerException, "#8");
436 Assert.IsNotNull (inner.Message, "#9");
441 public void OpenReadTaskAsyncOnFile ()
443 var tmp = Path.GetTempFileName ();
444 string url = "file://" + tmp;
446 var client = new WebClient ();
447 var task = client.OpenReadTaskAsync (url);
448 Assert.IsTrue (task.Wait (2000));
451 [Test] // OpenWrite (string)
452 public void OpenWrite1_Address_Null ()
454 WebClient wc = new WebClient ();
456 wc.OpenWrite ((string) null);
458 } catch (ArgumentNullException ex) {
459 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
460 Assert.IsNull (ex.InnerException, "#3");
461 Assert.IsNotNull (ex.Message, "#4");
462 Assert.IsNotNull (ex.ParamName, "#5");
463 Assert.AreEqual ("address", ex.ParamName, "#6");
467 [Test] // OpenWrite (string)
468 public void OpenWrite1_Address_SchemeNotSupported ()
470 WebClient wc = new WebClient ();
472 wc.OpenWrite ("tp://scheme.notsupported");
474 } catch (WebException ex) {
475 // An error occurred performing a WebClient request
476 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
477 Assert.IsNotNull (ex.InnerException, "#3");
478 Assert.IsNotNull (ex.Message, "#4");
479 Assert.IsNull (ex.Response, "#5");
480 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
482 // The URI prefix is not recognized
483 Exception inner = ex.InnerException;
484 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
485 Assert.IsNull (inner.InnerException, "#8");
486 Assert.IsNotNull (inner.Message, "#9");
490 [Test] // OpenWrite (string, string)
491 public void OpenWrite2_Address_Null ()
493 WebClient wc = new WebClient ();
495 wc.OpenWrite ((string) null, "PUT");
497 } catch (ArgumentNullException ex) {
498 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
499 Assert.IsNull (ex.InnerException, "#3");
500 Assert.IsNotNull (ex.Message, "#4");
501 Assert.IsNotNull (ex.ParamName, "#5");
502 Assert.AreEqual ("address", ex.ParamName, "#6");
506 [Test] // OpenWrite (string, string)
507 public void OpenWrite2_Address_SchemeNotSupported ()
509 WebClient wc = new WebClient ();
511 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
513 } catch (WebException ex) {
514 // An error occurred performing a WebClient request
515 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
516 Assert.IsNotNull (ex.InnerException, "#3");
517 Assert.IsNotNull (ex.Message, "#4");
518 Assert.IsNull (ex.Response, "#5");
519 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
521 // The URI prefix is not recognized
522 Exception inner = ex.InnerException;
523 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
524 Assert.IsNull (inner.InnerException, "#8");
525 Assert.IsNotNull (inner.Message, "#9");
529 [Test] // OpenWrite (Uri)
530 public void OpenWrite3_Address_Null ()
532 WebClient wc = new WebClient ();
534 wc.OpenWrite ((Uri) null);
536 } catch (ArgumentNullException ex) {
537 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
538 Assert.IsNull (ex.InnerException, "#3");
539 Assert.IsNotNull (ex.Message, "#4");
540 Assert.IsNotNull (ex.ParamName, "#5");
541 Assert.AreEqual ("address", ex.ParamName, "#6");
545 [Test] // OpenWrite (Uri)
546 public void OpenWrite3_Address_SchemeNotSupported ()
548 WebClient wc = new WebClient ();
550 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
552 } catch (WebException ex) {
553 // An error occurred performing a WebClient request
554 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
555 Assert.IsNotNull (ex.InnerException, "#3");
556 Assert.IsNotNull (ex.Message, "#4");
557 Assert.IsNull (ex.Response, "#5");
558 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
560 // The URI prefix is not recognized
561 Exception inner = ex.InnerException;
562 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
563 Assert.IsNull (inner.InnerException, "#8");
564 Assert.IsNotNull (inner.Message, "#9");
568 [Test] // OpenWrite (Uri, string)
569 public void OpenWrite4_Address_Null ()
571 WebClient wc = new WebClient ();
573 wc.OpenWrite ((Uri) null, "POST");
575 } catch (ArgumentNullException ex) {
576 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
577 Assert.IsNull (ex.InnerException, "#3");
578 Assert.IsNotNull (ex.Message, "#4");
579 Assert.IsNotNull (ex.ParamName, "#5");
580 Assert.AreEqual ("address", ex.ParamName, "#6");
584 [Test] // OpenWrite (Uri, string)
585 public void OpenWrite4_Address_SchemeNotSupported ()
587 WebClient wc = new WebClient ();
589 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
592 } catch (WebException ex) {
593 // An error occurred performing a WebClient request
594 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
595 Assert.IsNotNull (ex.InnerException, "#3");
596 Assert.IsNotNull (ex.Message, "#4");
597 Assert.IsNull (ex.Response, "#5");
598 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
600 // The URI prefix is not recognized
601 Exception inner = ex.InnerException;
602 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
603 Assert.IsNull (inner.InnerException, "#8");
604 Assert.IsNotNull (inner.Message, "#9");
608 [Test] // UploadData (string, byte [])
609 public void UploadData1_Address_Null ()
611 WebClient wc = new WebClient ();
613 wc.UploadData ((string) null, new byte [] { 0x1a });
615 } catch (ArgumentNullException ex) {
616 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
617 Assert.IsNull (ex.InnerException, "#3");
618 Assert.IsNotNull (ex.Message, "#4");
619 Assert.IsNotNull (ex.ParamName, "#5");
620 Assert.AreEqual ("address", ex.ParamName, "#6");
624 [Test] // UploadData (string, byte [])
625 public void UploadData1_Address_SchemeNotSupported ()
627 WebClient wc = new WebClient ();
629 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
631 } catch (WebException ex) {
632 // An error occurred performing a WebClient request
633 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
634 Assert.IsNotNull (ex.InnerException, "#3");
635 Assert.IsNotNull (ex.Message, "#4");
636 Assert.IsNull (ex.Response, "#5");
637 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
639 // The URI prefix is not recognized
640 Exception inner = ex.InnerException;
641 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
642 Assert.IsNull (inner.InnerException, "#8");
643 Assert.IsNotNull (inner.Message, "#9");
647 [Test] // UploadData (string, byte [])
648 public void UploadData1_Data_Null ()
650 WebClient wc = new WebClient ();
652 wc.UploadData ("http://www.mono-project.com",
655 } catch (ArgumentNullException ex) {
656 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
657 Assert.IsNull (ex.InnerException, "#3");
658 Assert.IsNotNull (ex.Message, "#4");
659 Assert.IsNotNull (ex.ParamName, "#5");
660 Assert.AreEqual ("data", ex.ParamName, "#6");
664 [Test] // UploadData (Uri, byte [])
665 public void UploadData2_Address_Null ()
667 WebClient wc = new WebClient ();
669 wc.UploadData ((Uri) null, new byte [] { 0x1a });
671 } catch (ArgumentNullException ex) {
672 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
673 Assert.IsNull (ex.InnerException, "#3");
674 Assert.IsNotNull (ex.Message, "#4");
675 Assert.IsNotNull (ex.ParamName, "#5");
676 Assert.AreEqual ("address", ex.ParamName, "#6");
680 [Test] // UploadData (Uri, byte [])
681 public void UploadData2_Address_SchemeNotSupported ()
683 WebClient wc = new WebClient ();
685 wc.UploadData (new Uri ("tp://scheme.notsupported"),
686 new byte [] { 0x1a });
688 } catch (WebException ex) {
689 // An error occurred performing a WebClient request
690 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
691 Assert.IsNotNull (ex.InnerException, "#3");
692 Assert.IsNotNull (ex.Message, "#4");
693 Assert.IsNull (ex.Response, "#5");
694 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
696 // The URI prefix is not recognized
697 Exception inner = ex.InnerException;
698 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
699 Assert.IsNull (inner.InnerException, "#8");
700 Assert.IsNotNull (inner.Message, "#9");
704 [Test] // UploadData (Uri, byte [])
705 public void UploadData2_Data_Null ()
707 WebClient wc = new WebClient ();
709 wc.UploadData (new Uri ("http://www.mono-project.com"),
712 } catch (ArgumentNullException ex) {
713 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
714 Assert.IsNull (ex.InnerException, "#3");
715 Assert.IsNotNull (ex.Message, "#4");
716 Assert.IsNotNull (ex.ParamName, "#5");
717 Assert.AreEqual ("data", ex.ParamName, "#6");
721 [Test] // UploadData (string, string, byte [])
722 public void UploadData3_Address_Null ()
724 WebClient wc = new WebClient ();
726 wc.UploadData ((string) null, "POST",
727 new byte [] { 0x1a });
729 } catch (ArgumentNullException ex) {
730 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
731 Assert.IsNull (ex.InnerException, "#3");
732 Assert.IsNotNull (ex.Message, "#4");
733 Assert.IsNotNull (ex.ParamName, "#5");
734 Assert.AreEqual ("address", ex.ParamName, "#6");
738 [Test] // UploadData (string, string, byte [])
739 public void UploadData3_Address_SchemeNotSupported ()
741 WebClient wc = new WebClient ();
743 wc.UploadData ("tp://scheme.notsupported",
744 "POST", new byte [] { 0x1a });
746 } catch (WebException ex) {
747 // An error occurred performing a WebClient request
748 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
749 Assert.IsNotNull (ex.InnerException, "#3");
750 Assert.IsNotNull (ex.Message, "#4");
751 Assert.IsNull (ex.Response, "#5");
752 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
754 // The URI prefix is not recognized
755 Exception inner = ex.InnerException;
756 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
757 Assert.IsNull (inner.InnerException, "#8");
758 Assert.IsNotNull (inner.Message, "#9");
762 [Test] // UploadData (string, string, byte [])
763 public void UploadData3_Data_Null ()
765 WebClient wc = new WebClient ();
767 wc.UploadData ("http://www.mono-project.com",
768 "POST", (byte []) null);
770 } catch (ArgumentNullException ex) {
771 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
772 Assert.IsNull (ex.InnerException, "#3");
773 Assert.IsNotNull (ex.Message, "#4");
774 Assert.IsNotNull (ex.ParamName, "#5");
775 Assert.AreEqual ("data", ex.ParamName, "#6");
779 [Test] // UploadData (Uri, string, byte [])
780 public void UploadData4_Address_Null ()
782 WebClient wc = new WebClient ();
784 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
786 } catch (ArgumentNullException ex) {
787 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
788 Assert.IsNull (ex.InnerException, "#3");
789 Assert.IsNotNull (ex.Message, "#4");
790 Assert.IsNotNull (ex.ParamName, "#5");
791 Assert.AreEqual ("address", ex.ParamName, "#6");
795 [Test] // UploadData (Uri, string, byte [])
796 public void UploadData4_Address_SchemeNotSupported ()
798 WebClient wc = new WebClient ();
800 wc.UploadData (new Uri ("tp://scheme.notsupported"),
801 "POST", new byte [] { 0x1a });
803 } catch (WebException ex) {
804 // An error occurred performing a WebClient request
805 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
806 Assert.IsNotNull (ex.InnerException, "#3");
807 Assert.IsNotNull (ex.Message, "#4");
808 Assert.IsNull (ex.Response, "#5");
809 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
811 // The URI prefix is not recognized
812 Exception inner = ex.InnerException;
813 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
814 Assert.IsNull (inner.InnerException, "#8");
815 Assert.IsNotNull (inner.Message, "#9");
819 [Test] // UploadData (Uri, string, byte [])
820 public void UploadData4_Data_Null ()
822 WebClient wc = new WebClient ();
824 wc.UploadData (new Uri ("http://www.mono-project.com"),
825 "POST", (byte []) null);
827 } catch (ArgumentNullException ex) {
828 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
829 Assert.IsNull (ex.InnerException, "#3");
830 Assert.IsNotNull (ex.Message, "#4");
831 Assert.IsNotNull (ex.ParamName, "#5");
832 Assert.AreEqual ("data", ex.ParamName, "#6");
836 [Test] // UploadFile (string, string)
837 public void UploadFile1_Address_Null ()
839 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
840 File.Create (tempFile).Close ();
842 WebClient wc = new WebClient ();
844 wc.UploadFile ((string) null, tempFile);
846 } catch (ArgumentNullException ex) {
847 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
848 Assert.IsNull (ex.InnerException, "#3");
849 Assert.IsNotNull (ex.Message, "#4");
850 Assert.IsNotNull (ex.ParamName, "#5");
851 Assert.AreEqual ("address", ex.ParamName, "#6");
855 [Test] // UploadFile (string, string)
856 public void UploadFile1_Address_SchemeNotSupported ()
858 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
859 File.Create (tempFile).Close ();
861 WebClient wc = new WebClient ();
863 wc.UploadFile ("tp://scheme.notsupported",
866 } catch (WebException ex) {
867 // An error occurred performing a WebClient request
868 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
869 Assert.IsNotNull (ex.InnerException, "#3");
870 Assert.IsNotNull (ex.Message, "#4");
871 Assert.IsNull (ex.Response, "#5");
872 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
874 // The URI prefix is not recognized
875 Exception inner = ex.InnerException;
876 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
877 Assert.IsNull (inner.InnerException, "#8");
878 Assert.IsNotNull (inner.Message, "#9");
882 [Test] // UploadFile (string, string)
883 public void UploadFile1_FileName_NotFound ()
885 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
887 WebClient wc = new WebClient ();
889 wc.UploadFile ("tp://scheme.notsupported",
892 } catch (WebException ex) {
893 // An error occurred performing a WebClient request
894 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
895 Assert.IsNotNull (ex.Message, "#3");
896 Assert.IsNull (ex.Response, "#4");
897 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
899 // Could not find file "..."
900 FileNotFoundException inner = ex.InnerException
901 as FileNotFoundException;
902 Assert.IsNotNull (inner, "#6");
903 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
904 Assert.IsNotNull (inner.FileName, "#8");
905 Assert.AreEqual (tempFile, inner.FileName, "#9");
906 Assert.IsNull (inner.InnerException, "#10");
907 Assert.IsNotNull (inner.Message, "#11");
911 [Test] // UploadFile (string, string)
912 public void UploadFile1_FileName_Null ()
914 WebClient wc = new WebClient ();
916 wc.UploadFile ("tp://scheme.notsupported",
919 } catch (ArgumentNullException ex) {
920 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
921 Assert.IsNull (ex.InnerException, "#3");
922 Assert.IsNotNull (ex.Message, "#4");
923 Assert.IsNotNull (ex.ParamName, "#5");
924 Assert.AreEqual ("fileName", ex.ParamName, "#6");
928 [Test] // UploadFile (Uri, string)
929 public void UploadFile2_Address_Null ()
931 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
933 WebClient wc = new WebClient ();
935 wc.UploadFile ((Uri) null, tempFile);
937 } catch (ArgumentNullException ex) {
938 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
939 Assert.IsNull (ex.InnerException, "#3");
940 Assert.IsNotNull (ex.Message, "#4");
941 Assert.IsNotNull (ex.ParamName, "#5");
942 Assert.AreEqual ("address", ex.ParamName, "#6");
946 [Test] // UploadFile (Uri, string)
947 public void UploadFile2_Address_SchemeNotSupported ()
949 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
950 File.Create (tempFile).Close ();
952 WebClient wc = new WebClient ();
954 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
957 } catch (WebException ex) {
958 // An error occurred performing a WebClient request
959 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
960 Assert.IsNotNull (ex.InnerException, "#3");
961 Assert.IsNotNull (ex.Message, "#4");
962 Assert.IsNull (ex.Response, "#5");
963 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
965 // The URI prefix is not recognized
966 Exception inner = ex.InnerException;
967 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
968 Assert.IsNull (inner.InnerException, "#8");
969 Assert.IsNotNull (inner.Message, "#9");
973 [Test] // UploadFile (Uri, string)
974 public void UploadFile2_FileName_NotFound ()
976 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
978 WebClient wc = new WebClient ();
980 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
983 } catch (WebException ex) {
984 // An error occurred performing a WebClient request
985 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
986 Assert.IsNotNull (ex.Message, "#3");
987 Assert.IsNull (ex.Response, "#4");
988 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
990 // Could not find file "..."
991 FileNotFoundException inner = ex.InnerException
992 as FileNotFoundException;
993 Assert.IsNotNull (inner, "#6");
994 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
995 Assert.IsNotNull (inner.FileName, "#8");
996 Assert.AreEqual (tempFile, inner.FileName, "#9");
997 Assert.IsNull (inner.InnerException, "#10");
998 Assert.IsNotNull (inner.Message, "#11");
1002 [Test] // UploadFile (Uri, string)
1003 public void UploadFile2_FileName_Null ()
1005 WebClient wc = new WebClient ();
1007 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1010 } catch (ArgumentNullException ex) {
1011 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1012 Assert.IsNull (ex.InnerException, "#3");
1013 Assert.IsNotNull (ex.Message, "#4");
1014 Assert.IsNotNull (ex.ParamName, "#5");
1015 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1019 [Test] // UploadFile (string, string, string)
1020 public void UploadFile3_Address_Null ()
1022 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1023 File.Create (tempFile).Close ();
1025 WebClient wc = new WebClient ();
1027 wc.UploadFile ((string) null, "POST", tempFile);
1029 } catch (ArgumentNullException ex) {
1030 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1031 Assert.IsNull (ex.InnerException, "#3");
1032 Assert.IsNotNull (ex.Message, "#4");
1033 Assert.IsNotNull (ex.ParamName, "#5");
1034 Assert.AreEqual ("path", ex.ParamName, "#6");
1038 [Test] // UploadFile (string, string, string)
1039 public void UploadFile3_Address_SchemeNotSupported ()
1041 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1042 File.Create (tempFile).Close ();
1044 WebClient wc = new WebClient ();
1046 wc.UploadFile ("tp://scheme.notsupported",
1049 } catch (WebException ex) {
1050 // An error occurred performing a WebClient request
1051 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1052 Assert.IsNotNull (ex.InnerException, "#3");
1053 Assert.IsNotNull (ex.Message, "#4");
1054 Assert.IsNull (ex.Response, "#5");
1055 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1057 // The URI prefix is not recognized
1058 Exception inner = ex.InnerException;
1059 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1060 Assert.IsNull (inner.InnerException, "#8");
1061 Assert.IsNotNull (inner.Message, "#9");
1065 [Test] // UploadFile (string, string, string)
1066 public void UploadFile3_FileName_NotFound ()
1068 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1070 WebClient wc = new WebClient ();
1072 wc.UploadFile ("tp://scheme.notsupported",
1075 } catch (WebException ex) {
1076 // An error occurred performing a WebClient request
1077 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1078 Assert.IsNotNull (ex.Message, "#3");
1079 Assert.IsNull (ex.Response, "#4");
1080 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1082 // Could not find file "..."
1083 FileNotFoundException inner = ex.InnerException
1084 as FileNotFoundException;
1085 Assert.IsNotNull (inner, "#6");
1086 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1087 Assert.IsNotNull (inner.FileName, "#8");
1088 Assert.AreEqual (tempFile, inner.FileName, "#9");
1089 Assert.IsNull (inner.InnerException, "#10");
1090 Assert.IsNotNull (inner.Message, "#11");
1094 [Test] // UploadFile (string, string, string)
1095 public void UploadFile3_FileName_Null ()
1097 WebClient wc = new WebClient ();
1099 wc.UploadFile ("tp://scheme.notsupported",
1100 "POST", (string) null);
1102 } catch (ArgumentNullException ex) {
1103 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1104 Assert.IsNull (ex.InnerException, "#3");
1105 Assert.IsNotNull (ex.Message, "#4");
1106 Assert.IsNotNull (ex.ParamName, "#5");
1107 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1111 [Test] // UploadFile (Uri, string, string)
1112 public void UploadFile4_Address_Null ()
1114 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1116 WebClient wc = new WebClient ();
1118 wc.UploadFile ((Uri) null, "POST", tempFile);
1120 } catch (ArgumentNullException ex) {
1121 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1122 Assert.IsNull (ex.InnerException, "#3");
1123 Assert.IsNotNull (ex.Message, "#4");
1124 Assert.IsNotNull (ex.ParamName, "#5");
1125 Assert.AreEqual ("address", ex.ParamName, "#6");
1129 [Test] // UploadFile (Uri, string, string)
1130 public void UploadFile4_Address_SchemeNotSupported ()
1132 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1133 File.Create (tempFile).Close ();
1135 WebClient wc = new WebClient ();
1137 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1140 } catch (WebException ex) {
1141 // An error occurred performing a WebClient request
1142 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1143 Assert.IsNotNull (ex.InnerException, "#3");
1144 Assert.IsNotNull (ex.Message, "#4");
1145 Assert.IsNull (ex.Response, "#5");
1146 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1148 // The URI prefix is not recognized
1149 Exception inner = ex.InnerException;
1150 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1151 Assert.IsNull (inner.InnerException, "#8");
1152 Assert.IsNotNull (inner.Message, "#9");
1156 [Test] // UploadFile (Uri, string, string)
1157 public void UploadFile4_FileName_NotFound ()
1159 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1161 WebClient wc = new WebClient ();
1163 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1166 } catch (WebException ex) {
1167 // An error occurred performing a WebClient request
1168 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1169 Assert.IsNotNull (ex.Message, "#3");
1170 Assert.IsNull (ex.Response, "#4");
1171 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1173 // Could not find file "..."
1174 FileNotFoundException inner = ex.InnerException
1175 as FileNotFoundException;
1176 Assert.IsNotNull (inner, "#6");
1177 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1178 Assert.IsNotNull (inner.FileName, "#8");
1179 Assert.AreEqual (tempFile, inner.FileName, "#9");
1180 Assert.IsNull (inner.InnerException, "#10");
1181 Assert.IsNotNull (inner.Message, "#11");
1185 [Test] // UploadFile (Uri, string, string)
1186 public void UploadFile4_FileName_Null ()
1188 WebClient wc = new WebClient ();
1190 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1191 "POST", (string) null);
1193 } catch (ArgumentNullException ex) {
1194 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1195 Assert.IsNull (ex.InnerException, "#3");
1196 Assert.IsNotNull (ex.Message, "#4");
1197 Assert.IsNotNull (ex.ParamName, "#5");
1198 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1202 [Test] // UploadString (string, string)
1203 public void UploadString1_Address_Null ()
1205 WebClient wc = new WebClient ();
1207 wc.UploadString ((string) null, (string) null);
1209 } catch (ArgumentNullException ex) {
1210 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1211 Assert.IsNull (ex.InnerException, "#3");
1212 Assert.IsNotNull (ex.Message, "#4");
1213 Assert.IsNotNull (ex.ParamName, "#5");
1214 Assert.AreEqual ("address", ex.ParamName, "#6");
1218 [Test] // UploadString (string, string)
1219 public void UploadString1_Address_SchemeNotSupported ()
1221 WebClient wc = new WebClient ();
1223 wc.UploadString ("tp://scheme.notsupported", "abc");
1225 } catch (WebException ex) {
1226 // An error occurred performing a WebClient request
1227 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1228 Assert.IsNotNull (ex.InnerException, "#3");
1229 Assert.IsNotNull (ex.Message, "#4");
1230 Assert.IsNull (ex.Response, "#5");
1231 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1233 // The URI prefix is not recognized
1234 Exception inner = ex.InnerException;
1235 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1236 Assert.IsNull (inner.InnerException, "#8");
1237 Assert.IsNotNull (inner.Message, "#9");
1241 [Test] // UploadString (string, string)
1242 public void UploadString1_Data_Null ()
1244 WebClient wc = new WebClient ();
1246 wc.UploadString ("tp://scheme.notsupported", (string) null);
1248 } catch (ArgumentNullException ex) {
1249 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1250 Assert.IsNull (ex.InnerException, "#3");
1251 Assert.IsNotNull (ex.Message, "#4");
1252 Assert.IsNotNull (ex.ParamName, "#5");
1253 Assert.AreEqual ("data", ex.ParamName, "#6");
1257 [Test] // UploadString (Uri, string)
1258 public void UploadString2_Address_Null ()
1260 WebClient wc = new WebClient ();
1262 wc.UploadString ((Uri) null, (string) null);
1264 } catch (ArgumentNullException ex) {
1265 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1266 Assert.IsNull (ex.InnerException, "#3");
1267 Assert.IsNotNull (ex.Message, "#4");
1268 Assert.IsNotNull (ex.ParamName, "#5");
1269 Assert.AreEqual ("address", ex.ParamName, "#6");
1273 [Test] // UploadString (Uri, string)
1274 public void UploadString2_Address_SchemeNotSupported ()
1276 WebClient wc = new WebClient ();
1278 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1280 } catch (WebException ex) {
1281 // An error occurred performing a WebClient request
1282 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1283 Assert.IsNotNull (ex.InnerException, "#3");
1284 Assert.IsNotNull (ex.Message, "#4");
1285 Assert.IsNull (ex.Response, "#5");
1286 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1288 // The URI prefix is not recognized
1289 Exception inner = ex.InnerException;
1290 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1291 Assert.IsNull (inner.InnerException, "#8");
1292 Assert.IsNotNull (inner.Message, "#9");
1296 [Test] // UploadString (Uri, string)
1297 public void UploadString2_Data_Null ()
1299 WebClient wc = new WebClient ();
1301 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1304 } catch (ArgumentNullException ex) {
1305 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1306 Assert.IsNull (ex.InnerException, "#3");
1307 Assert.IsNotNull (ex.Message, "#4");
1308 Assert.IsNotNull (ex.ParamName, "#5");
1309 Assert.AreEqual ("data", ex.ParamName, "#6");
1313 [Test] // UploadString (string, string, string)
1314 public void UploadString3_Address_Null ()
1316 WebClient wc = new WebClient ();
1318 wc.UploadString ((string) null, (string) null,
1321 } catch (ArgumentNullException ex) {
1322 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1323 Assert.IsNull (ex.InnerException, "#3");
1324 Assert.IsNotNull (ex.Message, "#4");
1325 Assert.IsNotNull (ex.ParamName, "#5");
1326 Assert.AreEqual ("address", ex.ParamName, "#6");
1330 [Test] // UploadString (string, string, string)
1331 public void UploadString3_Address_SchemeNotSupported ()
1333 WebClient wc = new WebClient ();
1335 wc.UploadString ("tp://scheme.notsupported",
1338 } catch (WebException ex) {
1339 // An error occurred performing a WebClient request
1340 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1341 Assert.IsNotNull (ex.InnerException, "#3");
1342 Assert.IsNotNull (ex.Message, "#4");
1343 Assert.IsNull (ex.Response, "#5");
1344 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1346 // The URI prefix is not recognized
1347 Exception inner = ex.InnerException;
1348 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1349 Assert.IsNull (inner.InnerException, "#8");
1350 Assert.IsNotNull (inner.Message, "#9");
1354 [Test] // UploadString (string, string, string)
1355 public void UploadString3_Data_Null ()
1357 WebClient wc = new WebClient ();
1359 wc.UploadString ("tp://scheme.notsupported",
1360 "POST", (string) null);
1362 } catch (ArgumentNullException ex) {
1363 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1364 Assert.IsNull (ex.InnerException, "#3");
1365 Assert.IsNotNull (ex.Message, "#4");
1366 Assert.IsNotNull (ex.ParamName, "#5");
1367 Assert.AreEqual ("data", ex.ParamName, "#6");
1371 [Test] // UploadString (Uri, string, string)
1372 public void UploadString4_Address_Null ()
1374 WebClient wc = new WebClient ();
1376 wc.UploadString ((Uri) null, (string) null,
1379 } catch (ArgumentNullException ex) {
1380 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1381 Assert.IsNull (ex.InnerException, "#3");
1382 Assert.IsNotNull (ex.Message, "#4");
1383 Assert.IsNotNull (ex.ParamName, "#5");
1384 Assert.AreEqual ("address", ex.ParamName, "#6");
1388 [Test] // UploadString (Uri, string, string)
1389 public void UploadString4_Address_SchemeNotSupported ()
1391 WebClient wc = new WebClient ();
1393 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1396 } catch (WebException ex) {
1397 // An error occurred performing a WebClient request
1398 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1399 Assert.IsNotNull (ex.InnerException, "#3");
1400 Assert.IsNotNull (ex.Message, "#4");
1401 Assert.IsNull (ex.Response, "#5");
1402 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1404 // The URI prefix is not recognized
1405 Exception inner = ex.InnerException;
1406 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1407 Assert.IsNull (inner.InnerException, "#8");
1408 Assert.IsNotNull (inner.Message, "#9");
1412 [Test] // UploadString (Uri, string, string)
1413 public void UploadString4_Data_Null ()
1415 WebClient wc = new WebClient ();
1417 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1418 "POST", (string) null);
1420 } catch (ArgumentNullException ex) {
1421 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1422 Assert.IsNull (ex.InnerException, "#3");
1423 Assert.IsNotNull (ex.Message, "#4");
1424 Assert.IsNotNull (ex.ParamName, "#5");
1425 Assert.AreEqual ("data", ex.ParamName, "#6");
1430 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1431 #if FEATURE_NO_BSD_SOCKETS
1432 [ExpectedException (typeof (PlatformNotSupportedException))]
1434 public void UploadValues1 ()
1436 IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
1437 string url = "http://" + ep.ToString () + "/test/";
1439 using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) {
1440 WebClient wc = new WebClient ();
1441 wc.Encoding = Encoding.ASCII;
1443 NameValueCollection nvc = new NameValueCollection ();
1444 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1445 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1447 byte [] buffer = wc.UploadValues (url, nvc);
1448 string response = Encoding.UTF8.GetString (buffer);
1449 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1453 [Test] // UploadValues (string, NameValueCollection)
1454 public void UploadValues1_Address_Null ()
1456 WebClient wc = new WebClient ();
1458 wc.UploadValues ((string) null, new NameValueCollection ());
1460 } catch (ArgumentNullException ex) {
1461 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1462 Assert.IsNull (ex.InnerException, "#3");
1463 Assert.IsNotNull (ex.Message, "#4");
1464 Assert.IsNotNull (ex.ParamName, "#5");
1465 Assert.AreEqual ("address", ex.ParamName, "#6");
1469 [Test] // UploadValues (string, NameValueCollection)
1470 public void UploadValues1_Address_SchemeNotSupported ()
1472 WebClient wc = new WebClient ();
1474 wc.UploadValues ("tp://scheme.notsupported",
1475 new NameValueCollection ());
1477 } catch (WebException ex) {
1478 // An error occurred performing a WebClient request
1479 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1480 Assert.IsNotNull (ex.InnerException, "#3");
1481 Assert.IsNotNull (ex.Message, "#4");
1482 Assert.IsNull (ex.Response, "#5");
1483 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1485 // The URI prefix is not recognized
1486 Exception inner = ex.InnerException;
1487 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1488 Assert.IsNull (inner.InnerException, "#8");
1489 Assert.IsNotNull (inner.Message, "#9");
1493 [Test] // UploadValues (string, NameValueCollection)
1494 public void UploadValues1_Data_Null ()
1496 WebClient wc = new WebClient ();
1498 wc.UploadValues ("http://www.mono-project.com",
1499 (NameValueCollection) null);
1501 } catch (ArgumentNullException ex) {
1502 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1503 Assert.IsNull (ex.InnerException, "#3");
1504 Assert.IsNotNull (ex.Message, "#4");
1505 Assert.IsNotNull (ex.ParamName, "#5");
1506 Assert.AreEqual ("data", ex.ParamName, "#6");
1510 [Test] // UploadValues (Uri, NameValueCollection)
1511 public void UploadValues2_Address_Null ()
1513 WebClient wc = new WebClient ();
1515 wc.UploadValues ((Uri) null, new NameValueCollection ());
1517 } catch (ArgumentNullException ex) {
1518 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1519 Assert.IsNull (ex.InnerException, "#3");
1520 Assert.IsNotNull (ex.Message, "#4");
1521 Assert.IsNotNull (ex.ParamName, "#5");
1522 Assert.AreEqual ("address", ex.ParamName, "#6");
1526 [Test] // UploadValues (Uri, NameValueCollection)
1527 public void UploadValues2_Address_SchemeNotSupported ()
1529 WebClient wc = new WebClient ();
1531 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1532 new NameValueCollection ());
1534 } catch (WebException ex) {
1535 // An error occurred performing a WebClient request
1536 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1537 Assert.IsNotNull (ex.InnerException, "#3");
1538 Assert.IsNotNull (ex.Message, "#4");
1539 Assert.IsNull (ex.Response, "#5");
1540 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1542 // The URI prefix is not recognized
1543 Exception inner = ex.InnerException;
1544 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1545 Assert.IsNull (inner.InnerException, "#8");
1546 Assert.IsNotNull (inner.Message, "#9");
1550 [Test] // UploadValues (Uri, NameValueCollection)
1551 public void UploadValues2_Data_Null ()
1553 WebClient wc = new WebClient ();
1555 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1556 (NameValueCollection) null);
1558 } catch (ArgumentNullException ex) {
1559 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1560 Assert.IsNull (ex.InnerException, "#3");
1561 Assert.IsNotNull (ex.Message, "#4");
1562 Assert.IsNotNull (ex.ParamName, "#5");
1563 Assert.AreEqual ("data", ex.ParamName, "#6");
1567 [Test] // UploadValues (string, string, NameValueCollection)
1568 public void UploadValues3_Address_Null ()
1570 WebClient wc = new WebClient ();
1572 wc.UploadValues ((string) null, "POST",
1573 new NameValueCollection ());
1575 } catch (ArgumentNullException ex) {
1576 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1577 Assert.IsNull (ex.InnerException, "#3");
1578 Assert.IsNotNull (ex.Message, "#4");
1579 Assert.IsNotNull (ex.ParamName, "#5");
1580 Assert.AreEqual ("address", ex.ParamName, "#6");
1584 [Test] // UploadValues (string, string, NameValueCollection)
1585 public void UploadValues3_Address_SchemeNotSupported ()
1587 WebClient wc = new WebClient ();
1589 wc.UploadValues ("tp://scheme.notsupported",
1590 "POST", new NameValueCollection ());
1592 } catch (WebException ex) {
1593 // An error occurred performing a WebClient request
1594 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1595 Assert.IsNotNull (ex.InnerException, "#3");
1596 Assert.IsNotNull (ex.Message, "#4");
1597 Assert.IsNull (ex.Response, "#5");
1598 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1600 // The URI prefix is not recognized
1601 Exception inner = ex.InnerException;
1602 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1603 Assert.IsNull (inner.InnerException, "#8");
1604 Assert.IsNotNull (inner.Message, "#9");
1608 [Test] // UploadValues (string, string, NameValueCollection)
1609 public void UploadValues3_Data_Null ()
1611 WebClient wc = new WebClient ();
1613 wc.UploadValues ("http://www.mono-project.com",
1614 "POST", (NameValueCollection) null);
1616 } catch (ArgumentNullException ex) {
1617 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1618 Assert.IsNull (ex.InnerException, "#3");
1619 Assert.IsNotNull (ex.Message, "#4");
1620 Assert.IsNotNull (ex.ParamName, "#5");
1621 Assert.AreEqual ("data", ex.ParamName, "#6");
1625 [Test] // UploadValues (Uri, string, NameValueCollection)
1626 public void UploadValues4_Address_Null ()
1628 WebClient wc = new WebClient ();
1630 wc.UploadValues ((Uri) null, "POST",
1631 new NameValueCollection ());
1633 } catch (ArgumentNullException ex) {
1634 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1635 Assert.IsNull (ex.InnerException, "#3");
1636 Assert.IsNotNull (ex.Message, "#4");
1637 Assert.IsNotNull (ex.ParamName, "#5");
1638 Assert.AreEqual ("address", ex.ParamName, "#6");
1642 [Test] // UploadValues (Uri, string, NameValueCollection)
1643 public void UploadValues4_Address_SchemeNotSupported ()
1645 WebClient wc = new WebClient ();
1647 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1648 "POST", new NameValueCollection ());
1650 } catch (WebException ex) {
1651 // An error occurred performing a WebClient request
1652 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1653 Assert.IsNotNull (ex.InnerException, "#3");
1654 Assert.IsNotNull (ex.Message, "#4");
1655 Assert.IsNull (ex.Response, "#5");
1656 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1658 // The URI prefix is not recognized
1659 Exception inner = ex.InnerException;
1660 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1661 Assert.IsNull (inner.InnerException, "#8");
1662 Assert.IsNotNull (inner.Message, "#9");
1666 [Test] // UploadValues (Uri, string, NameValueCollection)
1667 public void UploadValues4_Data_Null ()
1669 WebClient wc = new WebClient ();
1671 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1672 "POST", (NameValueCollection) null);
1674 } catch (ArgumentNullException ex) {
1675 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1676 Assert.IsNull (ex.InnerException, "#3");
1677 Assert.IsNotNull (ex.Message, "#4");
1678 Assert.IsNotNull (ex.ParamName, "#5");
1679 Assert.AreEqual ("data", ex.ParamName, "#6");
1684 #if FEATURE_NO_BSD_SOCKETS
1685 // We throw a PlatformNotSupportedException deeper, which is caught and re-thrown as WebException
1686 [ExpectedException (typeof (WebException))]
1688 public void GetWebRequestOverriding ()
1690 GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1691 testObject.DownloadData ("http://www.mono-project.com");
1693 Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1696 class GetWebRequestOverridingTestClass : WebClient
1698 internal bool overridedCodeRan = false;
1699 protected override WebRequest GetWebRequest(Uri address)
1701 overridedCodeRan = true;
1702 return base.GetWebRequest (address);
1706 static byte [] EchoRequestHandler (Socket socket)
1708 MemoryStream ms = new MemoryStream ();
1709 byte [] buffer = new byte [4096];
1710 int bytesReceived = socket.Receive (buffer);
1711 while (bytesReceived > 0) {
1712 ms.Write (buffer, 0, bytesReceived);
1713 // We don't check for Content-Length or anything else here, so we give the client a little time to write
1714 // after sending the headers
1716 if (socket.Available > 0) {
1717 bytesReceived = socket.Receive (buffer);
1725 StringBuilder sb = new StringBuilder ();
1727 string expect = null;
1729 StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1732 while ((line = sr.ReadLine ()) != null) {
1737 } if (line.Length == 0) {
1739 } else if (line.StartsWith ("Expect:")) {
1740 expect = line.Substring (8);
1744 StringWriter sw = new StringWriter ();
1746 if (expect == "100-continue" && state != 2) {
1747 sw.WriteLine ("HTTP/1.1 100 Continue");
1751 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1754 ms = new MemoryStream ();
1755 buffer = new byte [4096];
1756 bytesReceived = socket.Receive (buffer);
1757 while (bytesReceived > 0) {
1758 ms.Write (buffer, 0, bytesReceived);
1760 if (socket.Available > 0) {
1761 bytesReceived = socket.Receive (buffer);
1769 sb = new StringBuilder ();
1770 sr = new StreamReader (ms, Encoding.UTF8);
1771 line = sr.ReadLine ();
1772 while (line != null) {
1775 line = sr.ReadLine ();
1779 sw = new StringWriter ();
1780 sw.WriteLine ("HTTP/1.1 200 OK");
1781 sw.WriteLine ("Content-Type: text/xml");
1782 sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1784 sw.Write (sb.ToString ());
1787 return Encoding.UTF8.GetBytes (sw.ToString ());
1791 #if FEATURE_NO_BSD_SOCKETS
1792 [ExpectedException (typeof (PlatformNotSupportedException))]
1794 public void DefaultProxy ()
1796 WebClient wc = new WebClient ();
1797 // this is never null on .net
1798 Assert.IsNotNull (wc.Proxy);
1799 // and return the same instance as WebRequest.DefaultWebProxy
1800 Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1804 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1805 #if FEATURE_NO_BSD_SOCKETS
1806 [ExpectedException (typeof (PlatformNotSupportedException))]
1808 public void UploadStringAsyncCancelEvent ()
1810 UploadAsyncCancelEventTest (9301, (webClient, uri, cancelEvent) =>
1813 webClient.UploadStringCompleted += (sender, args) =>
1819 webClient.UploadStringAsync (uri, "PUT", "text");
1824 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1825 #if FEATURE_NO_BSD_SOCKETS
1826 [ExpectedException (typeof (PlatformNotSupportedException))]
1828 public void UploadDataAsyncCancelEvent ()
1830 UploadAsyncCancelEventTest (9302, (webClient, uri, cancelEvent) =>
1832 webClient.UploadDataCompleted += (sender, args) =>
1838 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1843 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1844 #if FEATURE_NO_BSD_SOCKETS
1845 [ExpectedException (typeof (PlatformNotSupportedException))]
1847 public void UploadValuesAsyncCancelEvent ()
1849 UploadAsyncCancelEventTest (9303, (webClient, uri, cancelEvent) =>
1851 webClient.UploadValuesCompleted += (sender, args) =>
1857 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1862 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1863 #if FEATURE_NO_BSD_SOCKETS
1864 [ExpectedException (typeof (PlatformNotSupportedException))]
1866 public void UploadFileAsyncCancelEvent ()
1868 UploadAsyncCancelEventTest (9304,(webClient, uri, cancelEvent) =>
1870 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1871 File.Create (tempFile).Close ();
1873 webClient.UploadFileCompleted += (sender, args) =>
1879 webClient.UploadFileAsync (uri, "PUT", tempFile);
1884 [Category ("AndroidNotWorking")] // Test suite hangs if the tests runs as part of the entire BCL suite. Works when only this fixture is ran
1885 #if FEATURE_NO_BSD_SOCKETS
1886 [ExpectedException (typeof (PlatformNotSupportedException))]
1888 public void UploadFileAsyncContentType ()
1890 var port = NetworkHelpers.FindFreePort ();
1891 var serverUri = "http://localhost:" + port + "/";
1892 var filename = Path.GetTempFileName ();
1894 HttpListener listener = new HttpListener ();
1895 listener.Prefixes.Add (serverUri);
1898 using (var client = new WebClient ())
1900 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1901 var request = listener.GetContext ().Request;
1903 var expected = "multipart/form-data; boundary=---------------------";
1904 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1905 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1910 public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
1912 var ep = NetworkHelpers.LocalEphemeralEndPoint ();
1913 string url = "http://" + ep.ToString() + "/test/";
1915 using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s)))
1917 var webClient = new WebClient ();
1919 var cancellationTokenSource = new CancellationTokenSource ();
1920 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1922 var cancelEvent = new ManualResetEvent (false);
1924 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1926 cancellationTokenSource.Cancel ();
1928 Assert.IsTrue (cancelEvent.WaitOne (1000));