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 [Category ("RequiresBSDSockets")]
25 public class WebClientTest
27 private string _tempFolder;
32 _tempFolder = Path.Combine (Path.GetTempPath (),
34 if (Directory.Exists (_tempFolder))
35 Directory.Delete (_tempFolder, true);
36 Directory.CreateDirectory (_tempFolder);
40 public void TearDown ()
42 if (Directory.Exists (_tempFolder))
43 Directory.Delete (_tempFolder, true);
47 [Category ("InetAccess")]
48 public void DownloadTwice ()
50 WebClient wc = new WebClient();
51 string filename = Path.GetTempFileName();
53 // A new, but empty file has been created. This is a test case
55 wc.DownloadFile("http://google.com/", filename);
57 // Now, remove the file and attempt to download again.
58 File.Delete(filename);
59 wc.DownloadFile("http://google.com/", filename);
63 public void DownloadData1_Address_Null ()
65 WebClient wc = new WebClient ();
67 wc.DownloadData ((string) null);
69 } catch (ArgumentNullException ex) {
70 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
71 Assert.IsNull (ex.InnerException, "#3");
72 Assert.IsNotNull (ex.Message, "#4");
73 Assert.IsNotNull (ex.ParamName, "#5");
74 Assert.AreEqual ("address", ex.ParamName, "#6");
78 [Test] // DownloadData (string)
79 public void DownloadData1_Address_SchemeNotSupported ()
81 WebClient wc = new WebClient ();
83 wc.DownloadData ("tp://scheme.notsupported");
85 } catch (WebException ex) {
86 // An error occurred performing a WebClient request
87 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
88 Assert.IsNotNull (ex.InnerException, "#3");
89 Assert.IsNotNull (ex.Message, "#4");
90 Assert.IsNull (ex.Response, "#5");
91 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
93 // The URI prefix is not recognized
94 Exception inner = ex.InnerException;
95 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
96 Assert.IsNull (inner.InnerException, "#8");
97 Assert.IsNotNull (inner.Message, "#9");
101 [Test] // DownloadData (Uri)
102 public void DownloadData2_Address_Null ()
104 WebClient wc = new WebClient ();
106 wc.DownloadData ((Uri) null);
108 } catch (ArgumentNullException ex) {
109 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
110 Assert.IsNull (ex.InnerException, "#3");
111 Assert.IsNotNull (ex.Message, "#4");
112 Assert.IsNotNull (ex.ParamName, "#5");
113 Assert.AreEqual ("address", ex.ParamName, "#6");
117 [Test] // DownloadData (Uri)
118 public void DownloadData2_Address_SchemeNotSupported ()
120 WebClient wc = new WebClient ();
122 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
124 } catch (WebException ex) {
125 // An error occurred performing a WebClient request
126 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
127 Assert.IsNotNull (ex.InnerException, "#3");
128 Assert.IsNotNull (ex.Message, "#4");
129 Assert.IsNull (ex.Response, "#5");
130 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
132 // The URI prefix is not recognized
133 Exception inner = ex.InnerException;
134 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
135 Assert.IsNull (inner.InnerException, "#8");
136 Assert.IsNotNull (inner.Message, "#9");
141 public void DownloadFile1_Address_Null ()
143 WebClient wc = new WebClient ();
145 wc.DownloadFile ((string) null, "tmp.out");
147 } catch (ArgumentNullException ex) {
148 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
149 Assert.IsNull (ex.InnerException, "#3");
150 Assert.IsNotNull (ex.Message, "#4");
151 Assert.IsNotNull (ex.ParamName, "#5");
152 Assert.AreEqual ("address", ex.ParamName, "#6");
156 [Test] // DownloadFile (string, string)
157 public void DownloadFile1_Address_SchemeNotSupported ()
159 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
160 WebClient wc = new WebClient ();
162 wc.DownloadFile ("tp://scheme.notsupported", file);
164 } catch (WebException ex) {
165 // An error occurred performing a WebClient request
166 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
167 Assert.IsNotNull (ex.InnerException, "#3");
168 Assert.IsNotNull (ex.Message, "#4");
169 Assert.IsNull (ex.Response, "#5");
170 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
172 // The URI prefix is not recognized
173 Exception inner = ex.InnerException;
174 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
175 Assert.IsNull (inner.InnerException, "#8");
176 Assert.IsNotNull (inner.Message, "#9");
179 if (File.Exists (file))
184 [Test] // DownloadFile (string, string)
185 public void DownloadFile1_FileName_Null ()
187 WebClient wc = new WebClient ();
189 wc.DownloadFile ("tp://scheme.notsupported",
192 } catch (ArgumentNullException ex) {
193 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
194 Assert.IsNull (ex.InnerException, "#3");
195 Assert.IsNotNull (ex.Message, "#4");
196 Assert.IsNotNull (ex.ParamName, "#5");
197 Assert.AreEqual ("fileName", ex.ParamName, "#6");
201 [Test] // DownloadFile (Uri, string)
202 public void DownloadFile2_Address_Null ()
204 WebClient wc = new WebClient ();
206 wc.DownloadFile ((Uri) null, "tmp.out");
208 } catch (ArgumentNullException ex) {
209 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
210 Assert.IsNull (ex.InnerException, "#3");
211 Assert.IsNotNull (ex.Message, "#4");
212 Assert.IsNotNull (ex.ParamName, "#5");
213 Assert.AreEqual ("address", ex.ParamName, "#6");
217 [Test] // DownloadFile (Uri, string)
218 public void DownloadFile2_Address_SchemeNotSupported ()
220 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
221 WebClient wc = new WebClient ();
223 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
225 } catch (WebException ex) {
226 // An error occurred performing a WebClient request
227 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
228 Assert.IsNotNull (ex.InnerException, "#3");
229 Assert.IsNotNull (ex.Message, "#4");
230 Assert.IsNull (ex.Response, "#5");
231 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
233 // The URI prefix is not recognized
234 Exception inner = ex.InnerException;
235 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
236 Assert.IsNull (inner.InnerException, "#8");
237 Assert.IsNotNull (inner.Message, "#9");
240 if (File.Exists (file))
245 [Test] // DownloadFile (Uri, string)
246 public void DownloadFile2_FileName_Null ()
248 WebClient wc = new WebClient ();
250 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
253 } catch (ArgumentNullException ex) {
254 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
255 Assert.IsNull (ex.InnerException, "#3");
256 Assert.IsNotNull (ex.Message, "#4");
257 Assert.IsNotNull (ex.ParamName, "#5");
258 Assert.AreEqual ("fileName", ex.ParamName, "#6");
262 [Test] // DownloadString (string)
263 public void DownloadString1_Address_Null ()
265 WebClient wc = new WebClient ();
267 wc.DownloadString ((string) null);
269 } catch (ArgumentNullException ex) {
270 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
271 Assert.IsNull (ex.InnerException, "#3");
272 Assert.IsNotNull (ex.Message, "#4");
273 Assert.IsNotNull (ex.ParamName, "#5");
274 Assert.AreEqual ("address", ex.ParamName, "#6");
278 [Test] // DownloadString (string)
279 public void DownloadString1_Address_SchemeNotSupported ()
281 WebClient wc = new WebClient ();
283 wc.DownloadString ("tp://scheme.notsupported");
285 } catch (WebException ex) {
286 // An error occurred performing a WebClient request
287 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
288 Assert.IsNotNull (ex.InnerException, "#3");
289 Assert.IsNotNull (ex.Message, "#4");
290 Assert.IsNull (ex.Response, "#5");
291 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
293 // The URI prefix is not recognized
294 Exception inner = ex.InnerException;
295 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
296 Assert.IsNull (inner.InnerException, "#8");
297 Assert.IsNotNull (inner.Message, "#9");
301 [Test] // DownloadString (Uri)
302 public void DownloadString2_Address_Null ()
304 WebClient wc = new WebClient ();
306 wc.DownloadString ((Uri) null);
308 } catch (ArgumentNullException ex) {
309 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
310 Assert.IsNull (ex.InnerException, "#3");
311 Assert.IsNotNull (ex.Message, "#4");
312 Assert.IsNotNull (ex.ParamName, "#5");
313 Assert.AreEqual ("address", ex.ParamName, "#6");
317 [Test] // DownloadString (Uri)
318 public void DownloadString2_Address_SchemeNotSupported ()
320 WebClient wc = new WebClient ();
322 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
324 } catch (WebException ex) {
325 // An error occurred performing a WebClient request
326 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
327 Assert.IsNotNull (ex.InnerException, "#3");
328 Assert.IsNotNull (ex.Message, "#4");
329 Assert.IsNull (ex.Response, "#5");
330 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
332 // The URI prefix is not recognized
333 Exception inner = ex.InnerException;
334 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
335 Assert.IsNull (inner.InnerException, "#8");
336 Assert.IsNotNull (inner.Message, "#9");
341 public void EncodingTest ()
343 WebClient wc = new WebClient ();
344 Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
345 wc.Encoding = Encoding.ASCII;
346 Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
350 public void Encoding_Value_Null ()
352 WebClient wc = new WebClient ();
356 } catch (ArgumentNullException ex) {
357 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
358 Assert.IsNull (ex.InnerException, "#3");
359 Assert.IsNotNull (ex.Message, "#4");
360 Assert.AreEqual ("Encoding", ex.ParamName, "#6");
364 [Test] // OpenRead (string)
365 public void OpenRead1_Address_Null ()
367 WebClient wc = new WebClient ();
369 wc.OpenRead ((string) null);
371 } catch (ArgumentNullException ex) {
372 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
373 Assert.IsNull (ex.InnerException, "#3");
374 Assert.IsNotNull (ex.Message, "#4");
375 Assert.IsNotNull (ex.ParamName, "#5");
376 Assert.AreEqual ("address", ex.ParamName, "#6");
380 [Test] // OpenRead (string)
381 public void OpenRead1_Address_SchemeNotSupported ()
383 WebClient wc = new WebClient ();
385 wc.OpenRead ("tp://scheme.notsupported");
387 } catch (WebException ex) {
388 // An error occurred performing a WebClient request
389 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
390 Assert.IsNotNull (ex.InnerException, "#3");
391 Assert.IsNotNull (ex.Message, "#4");
392 Assert.IsNull (ex.Response, "#5");
393 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
395 // The URI prefix is not recognized
396 Exception inner = ex.InnerException;
397 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
398 Assert.IsNull (inner.InnerException, "#8");
399 Assert.IsNotNull (inner.Message, "#9");
403 [Test] // OpenRead (Uri)
404 public void OpenRead2_Address_Null ()
406 WebClient wc = new WebClient ();
408 wc.OpenRead ((Uri) null);
410 } catch (ArgumentNullException ex) {
411 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
412 Assert.IsNull (ex.InnerException, "#3");
413 Assert.IsNotNull (ex.Message, "#4");
414 Assert.IsNotNull (ex.ParamName, "#5");
415 Assert.AreEqual ("address", ex.ParamName, "#6");
419 [Test] // OpenRead (Uri)
420 public void OpenRead2_Address_SchemeNotSupported ()
422 WebClient wc = new WebClient ();
424 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
426 } catch (WebException ex) {
427 // An error occurred performing a WebClient request
428 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
429 Assert.IsNotNull (ex.InnerException, "#3");
430 Assert.IsNotNull (ex.Message, "#4");
431 Assert.IsNull (ex.Response, "#5");
432 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
434 // The URI prefix is not recognized
435 Exception inner = ex.InnerException;
436 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
437 Assert.IsNull (inner.InnerException, "#8");
438 Assert.IsNotNull (inner.Message, "#9");
442 [Test] // OpenWrite (string)
443 public void OpenWrite1_Address_Null ()
445 WebClient wc = new WebClient ();
447 wc.OpenWrite ((string) null);
449 } catch (ArgumentNullException ex) {
450 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
451 Assert.IsNull (ex.InnerException, "#3");
452 Assert.IsNotNull (ex.Message, "#4");
453 Assert.IsNotNull (ex.ParamName, "#5");
454 Assert.AreEqual ("address", ex.ParamName, "#6");
458 [Test] // OpenWrite (string)
459 public void OpenWrite1_Address_SchemeNotSupported ()
461 WebClient wc = new WebClient ();
463 wc.OpenWrite ("tp://scheme.notsupported");
465 } catch (WebException ex) {
466 // An error occurred performing a WebClient request
467 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
468 Assert.IsNotNull (ex.InnerException, "#3");
469 Assert.IsNotNull (ex.Message, "#4");
470 Assert.IsNull (ex.Response, "#5");
471 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
473 // The URI prefix is not recognized
474 Exception inner = ex.InnerException;
475 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
476 Assert.IsNull (inner.InnerException, "#8");
477 Assert.IsNotNull (inner.Message, "#9");
481 [Test] // OpenWrite (string, string)
482 public void OpenWrite2_Address_Null ()
484 WebClient wc = new WebClient ();
486 wc.OpenWrite ((string) null, "PUT");
488 } catch (ArgumentNullException ex) {
489 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
490 Assert.IsNull (ex.InnerException, "#3");
491 Assert.IsNotNull (ex.Message, "#4");
492 Assert.IsNotNull (ex.ParamName, "#5");
493 Assert.AreEqual ("address", ex.ParamName, "#6");
497 [Test] // OpenWrite (string, string)
498 public void OpenWrite2_Address_SchemeNotSupported ()
500 WebClient wc = new WebClient ();
502 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
504 } catch (WebException ex) {
505 // An error occurred performing a WebClient request
506 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
507 Assert.IsNotNull (ex.InnerException, "#3");
508 Assert.IsNotNull (ex.Message, "#4");
509 Assert.IsNull (ex.Response, "#5");
510 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
512 // The URI prefix is not recognized
513 Exception inner = ex.InnerException;
514 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
515 Assert.IsNull (inner.InnerException, "#8");
516 Assert.IsNotNull (inner.Message, "#9");
520 [Test] // OpenWrite (Uri)
521 public void OpenWrite3_Address_Null ()
523 WebClient wc = new WebClient ();
525 wc.OpenWrite ((Uri) null);
527 } catch (ArgumentNullException ex) {
528 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
529 Assert.IsNull (ex.InnerException, "#3");
530 Assert.IsNotNull (ex.Message, "#4");
531 Assert.IsNotNull (ex.ParamName, "#5");
532 Assert.AreEqual ("address", ex.ParamName, "#6");
536 [Test] // OpenWrite (Uri)
537 public void OpenWrite3_Address_SchemeNotSupported ()
539 WebClient wc = new WebClient ();
541 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
543 } catch (WebException ex) {
544 // An error occurred performing a WebClient request
545 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
546 Assert.IsNotNull (ex.InnerException, "#3");
547 Assert.IsNotNull (ex.Message, "#4");
548 Assert.IsNull (ex.Response, "#5");
549 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
551 // The URI prefix is not recognized
552 Exception inner = ex.InnerException;
553 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
554 Assert.IsNull (inner.InnerException, "#8");
555 Assert.IsNotNull (inner.Message, "#9");
559 [Test] // OpenWrite (Uri, string)
560 public void OpenWrite4_Address_Null ()
562 WebClient wc = new WebClient ();
564 wc.OpenWrite ((Uri) null, "POST");
566 } catch (ArgumentNullException ex) {
567 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
568 Assert.IsNull (ex.InnerException, "#3");
569 Assert.IsNotNull (ex.Message, "#4");
570 Assert.IsNotNull (ex.ParamName, "#5");
571 Assert.AreEqual ("address", ex.ParamName, "#6");
575 [Test] // OpenWrite (Uri, string)
576 public void OpenWrite4_Address_SchemeNotSupported ()
578 WebClient wc = new WebClient ();
580 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
583 } catch (WebException ex) {
584 // An error occurred performing a WebClient request
585 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
586 Assert.IsNotNull (ex.InnerException, "#3");
587 Assert.IsNotNull (ex.Message, "#4");
588 Assert.IsNull (ex.Response, "#5");
589 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
591 // The URI prefix is not recognized
592 Exception inner = ex.InnerException;
593 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
594 Assert.IsNull (inner.InnerException, "#8");
595 Assert.IsNotNull (inner.Message, "#9");
599 [Test] // UploadData (string, byte [])
600 public void UploadData1_Address_Null ()
602 WebClient wc = new WebClient ();
604 wc.UploadData ((string) null, new byte [] { 0x1a });
606 } catch (ArgumentNullException ex) {
607 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
608 Assert.IsNull (ex.InnerException, "#3");
609 Assert.IsNotNull (ex.Message, "#4");
610 Assert.IsNotNull (ex.ParamName, "#5");
611 Assert.AreEqual ("address", ex.ParamName, "#6");
615 [Test] // UploadData (string, byte [])
616 public void UploadData1_Address_SchemeNotSupported ()
618 WebClient wc = new WebClient ();
620 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
622 } catch (WebException ex) {
623 // An error occurred performing a WebClient request
624 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
625 Assert.IsNotNull (ex.InnerException, "#3");
626 Assert.IsNotNull (ex.Message, "#4");
627 Assert.IsNull (ex.Response, "#5");
628 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
630 // The URI prefix is not recognized
631 Exception inner = ex.InnerException;
632 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
633 Assert.IsNull (inner.InnerException, "#8");
634 Assert.IsNotNull (inner.Message, "#9");
638 [Test] // UploadData (string, byte [])
639 public void UploadData1_Data_Null ()
641 WebClient wc = new WebClient ();
643 wc.UploadData ("http://www.mono-project.com",
646 } catch (ArgumentNullException ex) {
647 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
648 Assert.IsNull (ex.InnerException, "#3");
649 Assert.IsNotNull (ex.Message, "#4");
650 Assert.IsNotNull (ex.ParamName, "#5");
651 Assert.AreEqual ("data", ex.ParamName, "#6");
655 [Test] // UploadData (Uri, byte [])
656 public void UploadData2_Address_Null ()
658 WebClient wc = new WebClient ();
660 wc.UploadData ((Uri) null, new byte [] { 0x1a });
662 } catch (ArgumentNullException ex) {
663 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
664 Assert.IsNull (ex.InnerException, "#3");
665 Assert.IsNotNull (ex.Message, "#4");
666 Assert.IsNotNull (ex.ParamName, "#5");
667 Assert.AreEqual ("address", ex.ParamName, "#6");
671 [Test] // UploadData (Uri, byte [])
672 public void UploadData2_Address_SchemeNotSupported ()
674 WebClient wc = new WebClient ();
676 wc.UploadData (new Uri ("tp://scheme.notsupported"),
677 new byte [] { 0x1a });
679 } catch (WebException ex) {
680 // An error occurred performing a WebClient request
681 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
682 Assert.IsNotNull (ex.InnerException, "#3");
683 Assert.IsNotNull (ex.Message, "#4");
684 Assert.IsNull (ex.Response, "#5");
685 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
687 // The URI prefix is not recognized
688 Exception inner = ex.InnerException;
689 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
690 Assert.IsNull (inner.InnerException, "#8");
691 Assert.IsNotNull (inner.Message, "#9");
695 [Test] // UploadData (Uri, byte [])
696 public void UploadData2_Data_Null ()
698 WebClient wc = new WebClient ();
700 wc.UploadData (new Uri ("http://www.mono-project.com"),
703 } catch (ArgumentNullException ex) {
704 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
705 Assert.IsNull (ex.InnerException, "#3");
706 Assert.IsNotNull (ex.Message, "#4");
707 Assert.IsNotNull (ex.ParamName, "#5");
708 Assert.AreEqual ("data", ex.ParamName, "#6");
712 [Test] // UploadData (string, string, byte [])
713 public void UploadData3_Address_Null ()
715 WebClient wc = new WebClient ();
717 wc.UploadData ((string) null, "POST",
718 new byte [] { 0x1a });
720 } catch (ArgumentNullException ex) {
721 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
722 Assert.IsNull (ex.InnerException, "#3");
723 Assert.IsNotNull (ex.Message, "#4");
724 Assert.IsNotNull (ex.ParamName, "#5");
725 Assert.AreEqual ("address", ex.ParamName, "#6");
729 [Test] // UploadData (string, string, byte [])
730 public void UploadData3_Address_SchemeNotSupported ()
732 WebClient wc = new WebClient ();
734 wc.UploadData ("tp://scheme.notsupported",
735 "POST", new byte [] { 0x1a });
737 } catch (WebException ex) {
738 // An error occurred performing a WebClient request
739 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
740 Assert.IsNotNull (ex.InnerException, "#3");
741 Assert.IsNotNull (ex.Message, "#4");
742 Assert.IsNull (ex.Response, "#5");
743 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
745 // The URI prefix is not recognized
746 Exception inner = ex.InnerException;
747 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
748 Assert.IsNull (inner.InnerException, "#8");
749 Assert.IsNotNull (inner.Message, "#9");
753 [Test] // UploadData (string, string, byte [])
754 public void UploadData3_Data_Null ()
756 WebClient wc = new WebClient ();
758 wc.UploadData ("http://www.mono-project.com",
759 "POST", (byte []) null);
761 } catch (ArgumentNullException ex) {
762 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
763 Assert.IsNull (ex.InnerException, "#3");
764 Assert.IsNotNull (ex.Message, "#4");
765 Assert.IsNotNull (ex.ParamName, "#5");
766 Assert.AreEqual ("data", ex.ParamName, "#6");
770 [Test] // UploadData (Uri, string, byte [])
771 public void UploadData4_Address_Null ()
773 WebClient wc = new WebClient ();
775 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
777 } catch (ArgumentNullException ex) {
778 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
779 Assert.IsNull (ex.InnerException, "#3");
780 Assert.IsNotNull (ex.Message, "#4");
781 Assert.IsNotNull (ex.ParamName, "#5");
782 Assert.AreEqual ("address", ex.ParamName, "#6");
786 [Test] // UploadData (Uri, string, byte [])
787 public void UploadData4_Address_SchemeNotSupported ()
789 WebClient wc = new WebClient ();
791 wc.UploadData (new Uri ("tp://scheme.notsupported"),
792 "POST", new byte [] { 0x1a });
794 } catch (WebException ex) {
795 // An error occurred performing a WebClient request
796 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
797 Assert.IsNotNull (ex.InnerException, "#3");
798 Assert.IsNotNull (ex.Message, "#4");
799 Assert.IsNull (ex.Response, "#5");
800 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
802 // The URI prefix is not recognized
803 Exception inner = ex.InnerException;
804 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
805 Assert.IsNull (inner.InnerException, "#8");
806 Assert.IsNotNull (inner.Message, "#9");
810 [Test] // UploadData (Uri, string, byte [])
811 public void UploadData4_Data_Null ()
813 WebClient wc = new WebClient ();
815 wc.UploadData (new Uri ("http://www.mono-project.com"),
816 "POST", (byte []) null);
818 } catch (ArgumentNullException ex) {
819 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
820 Assert.IsNull (ex.InnerException, "#3");
821 Assert.IsNotNull (ex.Message, "#4");
822 Assert.IsNotNull (ex.ParamName, "#5");
823 Assert.AreEqual ("data", ex.ParamName, "#6");
827 [Test] // UploadFile (string, string)
828 public void UploadFile1_Address_Null ()
830 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
831 File.Create (tempFile).Close ();
833 WebClient wc = new WebClient ();
835 wc.UploadFile ((string) null, tempFile);
837 } catch (ArgumentNullException ex) {
838 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
839 Assert.IsNull (ex.InnerException, "#3");
840 Assert.IsNotNull (ex.Message, "#4");
841 Assert.IsNotNull (ex.ParamName, "#5");
842 Assert.AreEqual ("address", ex.ParamName, "#6");
846 [Test] // UploadFile (string, string)
847 public void UploadFile1_Address_SchemeNotSupported ()
849 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
850 File.Create (tempFile).Close ();
852 WebClient wc = new WebClient ();
854 wc.UploadFile ("tp://scheme.notsupported",
857 } catch (WebException ex) {
858 // An error occurred performing a WebClient request
859 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
860 Assert.IsNotNull (ex.InnerException, "#3");
861 Assert.IsNotNull (ex.Message, "#4");
862 Assert.IsNull (ex.Response, "#5");
863 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
865 // The URI prefix is not recognized
866 Exception inner = ex.InnerException;
867 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
868 Assert.IsNull (inner.InnerException, "#8");
869 Assert.IsNotNull (inner.Message, "#9");
873 [Test] // UploadFile (string, string)
874 public void UploadFile1_FileName_NotFound ()
876 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
878 WebClient wc = new WebClient ();
880 wc.UploadFile ("tp://scheme.notsupported",
883 } catch (WebException ex) {
884 // An error occurred performing a WebClient request
885 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
886 Assert.IsNotNull (ex.Message, "#3");
887 Assert.IsNull (ex.Response, "#4");
888 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
890 // Could not find file "..."
891 FileNotFoundException inner = ex.InnerException
892 as FileNotFoundException;
893 Assert.IsNotNull (inner, "#6");
894 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
895 Assert.IsNotNull (inner.FileName, "#8");
896 Assert.AreEqual (tempFile, inner.FileName, "#9");
897 Assert.IsNull (inner.InnerException, "#10");
898 Assert.IsNotNull (inner.Message, "#11");
902 [Test] // UploadFile (string, string)
903 public void UploadFile1_FileName_Null ()
905 WebClient wc = new WebClient ();
907 wc.UploadFile ("tp://scheme.notsupported",
910 } catch (ArgumentNullException ex) {
911 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
912 Assert.IsNull (ex.InnerException, "#3");
913 Assert.IsNotNull (ex.Message, "#4");
914 Assert.IsNotNull (ex.ParamName, "#5");
915 Assert.AreEqual ("fileName", ex.ParamName, "#6");
919 [Test] // UploadFile (Uri, string)
920 public void UploadFile2_Address_Null ()
922 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
924 WebClient wc = new WebClient ();
926 wc.UploadFile ((Uri) null, tempFile);
928 } catch (ArgumentNullException ex) {
929 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
930 Assert.IsNull (ex.InnerException, "#3");
931 Assert.IsNotNull (ex.Message, "#4");
932 Assert.IsNotNull (ex.ParamName, "#5");
933 Assert.AreEqual ("address", ex.ParamName, "#6");
937 [Test] // UploadFile (Uri, string)
938 public void UploadFile2_Address_SchemeNotSupported ()
940 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
941 File.Create (tempFile).Close ();
943 WebClient wc = new WebClient ();
945 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
948 } catch (WebException ex) {
949 // An error occurred performing a WebClient request
950 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
951 Assert.IsNotNull (ex.InnerException, "#3");
952 Assert.IsNotNull (ex.Message, "#4");
953 Assert.IsNull (ex.Response, "#5");
954 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
956 // The URI prefix is not recognized
957 Exception inner = ex.InnerException;
958 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
959 Assert.IsNull (inner.InnerException, "#8");
960 Assert.IsNotNull (inner.Message, "#9");
964 [Test] // UploadFile (Uri, string)
965 public void UploadFile2_FileName_NotFound ()
967 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
969 WebClient wc = new WebClient ();
971 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
974 } catch (WebException ex) {
975 // An error occurred performing a WebClient request
976 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
977 Assert.IsNotNull (ex.Message, "#3");
978 Assert.IsNull (ex.Response, "#4");
979 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
981 // Could not find file "..."
982 FileNotFoundException inner = ex.InnerException
983 as FileNotFoundException;
984 Assert.IsNotNull (inner, "#6");
985 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
986 Assert.IsNotNull (inner.FileName, "#8");
987 Assert.AreEqual (tempFile, inner.FileName, "#9");
988 Assert.IsNull (inner.InnerException, "#10");
989 Assert.IsNotNull (inner.Message, "#11");
993 [Test] // UploadFile (Uri, string)
994 public void UploadFile2_FileName_Null ()
996 WebClient wc = new WebClient ();
998 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1001 } catch (ArgumentNullException ex) {
1002 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1003 Assert.IsNull (ex.InnerException, "#3");
1004 Assert.IsNotNull (ex.Message, "#4");
1005 Assert.IsNotNull (ex.ParamName, "#5");
1006 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1010 [Test] // UploadFile (string, string, string)
1011 public void UploadFile3_Address_Null ()
1013 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1014 File.Create (tempFile).Close ();
1016 WebClient wc = new WebClient ();
1018 wc.UploadFile ((string) null, "POST", tempFile);
1020 } catch (ArgumentNullException ex) {
1021 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1022 Assert.IsNull (ex.InnerException, "#3");
1023 Assert.IsNotNull (ex.Message, "#4");
1024 Assert.IsNotNull (ex.ParamName, "#5");
1025 Assert.AreEqual ("path", ex.ParamName, "#6");
1029 [Test] // UploadFile (string, string, string)
1030 public void UploadFile3_Address_SchemeNotSupported ()
1032 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1033 File.Create (tempFile).Close ();
1035 WebClient wc = new WebClient ();
1037 wc.UploadFile ("tp://scheme.notsupported",
1040 } catch (WebException ex) {
1041 // An error occurred performing a WebClient request
1042 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1043 Assert.IsNotNull (ex.InnerException, "#3");
1044 Assert.IsNotNull (ex.Message, "#4");
1045 Assert.IsNull (ex.Response, "#5");
1046 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1048 // The URI prefix is not recognized
1049 Exception inner = ex.InnerException;
1050 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1051 Assert.IsNull (inner.InnerException, "#8");
1052 Assert.IsNotNull (inner.Message, "#9");
1056 [Test] // UploadFile (string, string, string)
1057 public void UploadFile3_FileName_NotFound ()
1059 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1061 WebClient wc = new WebClient ();
1063 wc.UploadFile ("tp://scheme.notsupported",
1066 } catch (WebException ex) {
1067 // An error occurred performing a WebClient request
1068 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1069 Assert.IsNotNull (ex.Message, "#3");
1070 Assert.IsNull (ex.Response, "#4");
1071 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1073 // Could not find file "..."
1074 FileNotFoundException inner = ex.InnerException
1075 as FileNotFoundException;
1076 Assert.IsNotNull (inner, "#6");
1077 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1078 Assert.IsNotNull (inner.FileName, "#8");
1079 Assert.AreEqual (tempFile, inner.FileName, "#9");
1080 Assert.IsNull (inner.InnerException, "#10");
1081 Assert.IsNotNull (inner.Message, "#11");
1085 [Test] // UploadFile (string, string, string)
1086 public void UploadFile3_FileName_Null ()
1088 WebClient wc = new WebClient ();
1090 wc.UploadFile ("tp://scheme.notsupported",
1091 "POST", (string) null);
1093 } catch (ArgumentNullException ex) {
1094 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1095 Assert.IsNull (ex.InnerException, "#3");
1096 Assert.IsNotNull (ex.Message, "#4");
1097 Assert.IsNotNull (ex.ParamName, "#5");
1098 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1102 [Test] // UploadFile (Uri, string, string)
1103 public void UploadFile4_Address_Null ()
1105 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1107 WebClient wc = new WebClient ();
1109 wc.UploadFile ((Uri) null, "POST", tempFile);
1111 } catch (ArgumentNullException ex) {
1112 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1113 Assert.IsNull (ex.InnerException, "#3");
1114 Assert.IsNotNull (ex.Message, "#4");
1115 Assert.IsNotNull (ex.ParamName, "#5");
1116 Assert.AreEqual ("address", ex.ParamName, "#6");
1120 [Test] // UploadFile (Uri, string, string)
1121 public void UploadFile4_Address_SchemeNotSupported ()
1123 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1124 File.Create (tempFile).Close ();
1126 WebClient wc = new WebClient ();
1128 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1131 } catch (WebException ex) {
1132 // An error occurred performing a WebClient request
1133 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1134 Assert.IsNotNull (ex.InnerException, "#3");
1135 Assert.IsNotNull (ex.Message, "#4");
1136 Assert.IsNull (ex.Response, "#5");
1137 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1139 // The URI prefix is not recognized
1140 Exception inner = ex.InnerException;
1141 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1142 Assert.IsNull (inner.InnerException, "#8");
1143 Assert.IsNotNull (inner.Message, "#9");
1147 [Test] // UploadFile (Uri, string, string)
1148 public void UploadFile4_FileName_NotFound ()
1150 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1152 WebClient wc = new WebClient ();
1154 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1157 } catch (WebException ex) {
1158 // An error occurred performing a WebClient request
1159 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1160 Assert.IsNotNull (ex.Message, "#3");
1161 Assert.IsNull (ex.Response, "#4");
1162 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1164 // Could not find file "..."
1165 FileNotFoundException inner = ex.InnerException
1166 as FileNotFoundException;
1167 Assert.IsNotNull (inner, "#6");
1168 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1169 Assert.IsNotNull (inner.FileName, "#8");
1170 Assert.AreEqual (tempFile, inner.FileName, "#9");
1171 Assert.IsNull (inner.InnerException, "#10");
1172 Assert.IsNotNull (inner.Message, "#11");
1176 [Test] // UploadFile (Uri, string, string)
1177 public void UploadFile4_FileName_Null ()
1179 WebClient wc = new WebClient ();
1181 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1182 "POST", (string) null);
1184 } catch (ArgumentNullException ex) {
1185 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1186 Assert.IsNull (ex.InnerException, "#3");
1187 Assert.IsNotNull (ex.Message, "#4");
1188 Assert.IsNotNull (ex.ParamName, "#5");
1189 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1193 [Test] // UploadString (string, string)
1194 public void UploadString1_Address_Null ()
1196 WebClient wc = new WebClient ();
1198 wc.UploadString ((string) null, (string) null);
1200 } catch (ArgumentNullException ex) {
1201 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1202 Assert.IsNull (ex.InnerException, "#3");
1203 Assert.IsNotNull (ex.Message, "#4");
1204 Assert.IsNotNull (ex.ParamName, "#5");
1205 Assert.AreEqual ("address", ex.ParamName, "#6");
1209 [Test] // UploadString (string, string)
1210 public void UploadString1_Address_SchemeNotSupported ()
1212 WebClient wc = new WebClient ();
1214 wc.UploadString ("tp://scheme.notsupported", "abc");
1216 } catch (WebException ex) {
1217 // An error occurred performing a WebClient request
1218 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1219 Assert.IsNotNull (ex.InnerException, "#3");
1220 Assert.IsNotNull (ex.Message, "#4");
1221 Assert.IsNull (ex.Response, "#5");
1222 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1224 // The URI prefix is not recognized
1225 Exception inner = ex.InnerException;
1226 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1227 Assert.IsNull (inner.InnerException, "#8");
1228 Assert.IsNotNull (inner.Message, "#9");
1232 [Test] // UploadString (string, string)
1233 public void UploadString1_Data_Null ()
1235 WebClient wc = new WebClient ();
1237 wc.UploadString ("tp://scheme.notsupported", (string) null);
1239 } catch (ArgumentNullException ex) {
1240 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1241 Assert.IsNull (ex.InnerException, "#3");
1242 Assert.IsNotNull (ex.Message, "#4");
1243 Assert.IsNotNull (ex.ParamName, "#5");
1244 Assert.AreEqual ("data", ex.ParamName, "#6");
1248 [Test] // UploadString (Uri, string)
1249 public void UploadString2_Address_Null ()
1251 WebClient wc = new WebClient ();
1253 wc.UploadString ((Uri) null, (string) null);
1255 } catch (ArgumentNullException ex) {
1256 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1257 Assert.IsNull (ex.InnerException, "#3");
1258 Assert.IsNotNull (ex.Message, "#4");
1259 Assert.IsNotNull (ex.ParamName, "#5");
1260 Assert.AreEqual ("address", ex.ParamName, "#6");
1264 [Test] // UploadString (Uri, string)
1265 public void UploadString2_Address_SchemeNotSupported ()
1267 WebClient wc = new WebClient ();
1269 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1271 } catch (WebException ex) {
1272 // An error occurred performing a WebClient request
1273 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1274 Assert.IsNotNull (ex.InnerException, "#3");
1275 Assert.IsNotNull (ex.Message, "#4");
1276 Assert.IsNull (ex.Response, "#5");
1277 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1279 // The URI prefix is not recognized
1280 Exception inner = ex.InnerException;
1281 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1282 Assert.IsNull (inner.InnerException, "#8");
1283 Assert.IsNotNull (inner.Message, "#9");
1287 [Test] // UploadString (Uri, string)
1288 public void UploadString2_Data_Null ()
1290 WebClient wc = new WebClient ();
1292 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1295 } catch (ArgumentNullException ex) {
1296 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1297 Assert.IsNull (ex.InnerException, "#3");
1298 Assert.IsNotNull (ex.Message, "#4");
1299 Assert.IsNotNull (ex.ParamName, "#5");
1300 Assert.AreEqual ("data", ex.ParamName, "#6");
1304 [Test] // UploadString (string, string, string)
1305 public void UploadString3_Address_Null ()
1307 WebClient wc = new WebClient ();
1309 wc.UploadString ((string) null, (string) null,
1312 } catch (ArgumentNullException ex) {
1313 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1314 Assert.IsNull (ex.InnerException, "#3");
1315 Assert.IsNotNull (ex.Message, "#4");
1316 Assert.IsNotNull (ex.ParamName, "#5");
1317 Assert.AreEqual ("address", ex.ParamName, "#6");
1321 [Test] // UploadString (string, string, string)
1322 public void UploadString3_Address_SchemeNotSupported ()
1324 WebClient wc = new WebClient ();
1326 wc.UploadString ("tp://scheme.notsupported",
1329 } catch (WebException ex) {
1330 // An error occurred performing a WebClient request
1331 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1332 Assert.IsNotNull (ex.InnerException, "#3");
1333 Assert.IsNotNull (ex.Message, "#4");
1334 Assert.IsNull (ex.Response, "#5");
1335 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1337 // The URI prefix is not recognized
1338 Exception inner = ex.InnerException;
1339 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1340 Assert.IsNull (inner.InnerException, "#8");
1341 Assert.IsNotNull (inner.Message, "#9");
1345 [Test] // UploadString (string, string, string)
1346 public void UploadString3_Data_Null ()
1348 WebClient wc = new WebClient ();
1350 wc.UploadString ("tp://scheme.notsupported",
1351 "POST", (string) null);
1353 } catch (ArgumentNullException ex) {
1354 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1355 Assert.IsNull (ex.InnerException, "#3");
1356 Assert.IsNotNull (ex.Message, "#4");
1357 Assert.IsNotNull (ex.ParamName, "#5");
1358 Assert.AreEqual ("data", ex.ParamName, "#6");
1362 [Test] // UploadString (Uri, string, string)
1363 public void UploadString4_Address_Null ()
1365 WebClient wc = new WebClient ();
1367 wc.UploadString ((Uri) null, (string) null,
1370 } catch (ArgumentNullException ex) {
1371 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1372 Assert.IsNull (ex.InnerException, "#3");
1373 Assert.IsNotNull (ex.Message, "#4");
1374 Assert.IsNotNull (ex.ParamName, "#5");
1375 Assert.AreEqual ("address", ex.ParamName, "#6");
1379 [Test] // UploadString (Uri, string, string)
1380 public void UploadString4_Address_SchemeNotSupported ()
1382 WebClient wc = new WebClient ();
1384 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1387 } catch (WebException ex) {
1388 // An error occurred performing a WebClient request
1389 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1390 Assert.IsNotNull (ex.InnerException, "#3");
1391 Assert.IsNotNull (ex.Message, "#4");
1392 Assert.IsNull (ex.Response, "#5");
1393 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1395 // The URI prefix is not recognized
1396 Exception inner = ex.InnerException;
1397 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1398 Assert.IsNull (inner.InnerException, "#8");
1399 Assert.IsNotNull (inner.Message, "#9");
1403 [Test] // UploadString (Uri, string, string)
1404 public void UploadString4_Data_Null ()
1406 WebClient wc = new WebClient ();
1408 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1409 "POST", (string) null);
1411 } catch (ArgumentNullException ex) {
1412 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1413 Assert.IsNull (ex.InnerException, "#3");
1414 Assert.IsNotNull (ex.Message, "#4");
1415 Assert.IsNotNull (ex.ParamName, "#5");
1416 Assert.AreEqual ("data", ex.ParamName, "#6");
1421 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1422 public void UploadValues1 ()
1424 IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
1425 string url = "http://" + ep.ToString () + "/test/";
1427 using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) {
1428 WebClient wc = new WebClient ();
1429 wc.Encoding = Encoding.ASCII;
1431 NameValueCollection nvc = new NameValueCollection ();
1432 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1433 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1435 byte [] buffer = wc.UploadValues (url, nvc);
1436 string response = Encoding.UTF8.GetString (buffer);
1437 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1441 [Test] // UploadValues (string, NameValueCollection)
1442 public void UploadValues1_Address_Null ()
1444 WebClient wc = new WebClient ();
1446 wc.UploadValues ((string) null, new NameValueCollection ());
1448 } catch (ArgumentNullException ex) {
1449 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1450 Assert.IsNull (ex.InnerException, "#3");
1451 Assert.IsNotNull (ex.Message, "#4");
1452 Assert.IsNotNull (ex.ParamName, "#5");
1453 Assert.AreEqual ("address", ex.ParamName, "#6");
1457 [Test] // UploadValues (string, NameValueCollection)
1458 public void UploadValues1_Address_SchemeNotSupported ()
1460 WebClient wc = new WebClient ();
1462 wc.UploadValues ("tp://scheme.notsupported",
1463 new NameValueCollection ());
1465 } catch (WebException ex) {
1466 // An error occurred performing a WebClient request
1467 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1468 Assert.IsNotNull (ex.InnerException, "#3");
1469 Assert.IsNotNull (ex.Message, "#4");
1470 Assert.IsNull (ex.Response, "#5");
1471 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1473 // The URI prefix is not recognized
1474 Exception inner = ex.InnerException;
1475 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1476 Assert.IsNull (inner.InnerException, "#8");
1477 Assert.IsNotNull (inner.Message, "#9");
1481 [Test] // UploadValues (string, NameValueCollection)
1482 public void UploadValues1_Data_Null ()
1484 WebClient wc = new WebClient ();
1486 wc.UploadValues ("http://www.mono-project.com",
1487 (NameValueCollection) null);
1489 } catch (ArgumentNullException ex) {
1490 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1491 Assert.IsNull (ex.InnerException, "#3");
1492 Assert.IsNotNull (ex.Message, "#4");
1493 Assert.IsNotNull (ex.ParamName, "#5");
1494 Assert.AreEqual ("data", ex.ParamName, "#6");
1498 [Test] // UploadValues (Uri, NameValueCollection)
1499 public void UploadValues2_Address_Null ()
1501 WebClient wc = new WebClient ();
1503 wc.UploadValues ((Uri) null, new NameValueCollection ());
1505 } catch (ArgumentNullException ex) {
1506 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1507 Assert.IsNull (ex.InnerException, "#3");
1508 Assert.IsNotNull (ex.Message, "#4");
1509 Assert.IsNotNull (ex.ParamName, "#5");
1510 Assert.AreEqual ("address", ex.ParamName, "#6");
1514 [Test] // UploadValues (Uri, NameValueCollection)
1515 public void UploadValues2_Address_SchemeNotSupported ()
1517 WebClient wc = new WebClient ();
1519 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1520 new NameValueCollection ());
1522 } catch (WebException ex) {
1523 // An error occurred performing a WebClient request
1524 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1525 Assert.IsNotNull (ex.InnerException, "#3");
1526 Assert.IsNotNull (ex.Message, "#4");
1527 Assert.IsNull (ex.Response, "#5");
1528 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1530 // The URI prefix is not recognized
1531 Exception inner = ex.InnerException;
1532 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1533 Assert.IsNull (inner.InnerException, "#8");
1534 Assert.IsNotNull (inner.Message, "#9");
1538 [Test] // UploadValues (Uri, NameValueCollection)
1539 public void UploadValues2_Data_Null ()
1541 WebClient wc = new WebClient ();
1543 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1544 (NameValueCollection) null);
1546 } catch (ArgumentNullException ex) {
1547 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1548 Assert.IsNull (ex.InnerException, "#3");
1549 Assert.IsNotNull (ex.Message, "#4");
1550 Assert.IsNotNull (ex.ParamName, "#5");
1551 Assert.AreEqual ("data", ex.ParamName, "#6");
1555 [Test] // UploadValues (string, string, NameValueCollection)
1556 public void UploadValues3_Address_Null ()
1558 WebClient wc = new WebClient ();
1560 wc.UploadValues ((string) null, "POST",
1561 new NameValueCollection ());
1563 } catch (ArgumentNullException ex) {
1564 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1565 Assert.IsNull (ex.InnerException, "#3");
1566 Assert.IsNotNull (ex.Message, "#4");
1567 Assert.IsNotNull (ex.ParamName, "#5");
1568 Assert.AreEqual ("address", ex.ParamName, "#6");
1572 [Test] // UploadValues (string, string, NameValueCollection)
1573 public void UploadValues3_Address_SchemeNotSupported ()
1575 WebClient wc = new WebClient ();
1577 wc.UploadValues ("tp://scheme.notsupported",
1578 "POST", new NameValueCollection ());
1580 } catch (WebException ex) {
1581 // An error occurred performing a WebClient request
1582 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1583 Assert.IsNotNull (ex.InnerException, "#3");
1584 Assert.IsNotNull (ex.Message, "#4");
1585 Assert.IsNull (ex.Response, "#5");
1586 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1588 // The URI prefix is not recognized
1589 Exception inner = ex.InnerException;
1590 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1591 Assert.IsNull (inner.InnerException, "#8");
1592 Assert.IsNotNull (inner.Message, "#9");
1596 [Test] // UploadValues (string, string, NameValueCollection)
1597 public void UploadValues3_Data_Null ()
1599 WebClient wc = new WebClient ();
1601 wc.UploadValues ("http://www.mono-project.com",
1602 "POST", (NameValueCollection) null);
1604 } catch (ArgumentNullException ex) {
1605 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1606 Assert.IsNull (ex.InnerException, "#3");
1607 Assert.IsNotNull (ex.Message, "#4");
1608 Assert.IsNotNull (ex.ParamName, "#5");
1609 Assert.AreEqual ("data", ex.ParamName, "#6");
1613 [Test] // UploadValues (Uri, string, NameValueCollection)
1614 public void UploadValues4_Address_Null ()
1616 WebClient wc = new WebClient ();
1618 wc.UploadValues ((Uri) null, "POST",
1619 new NameValueCollection ());
1621 } catch (ArgumentNullException ex) {
1622 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1623 Assert.IsNull (ex.InnerException, "#3");
1624 Assert.IsNotNull (ex.Message, "#4");
1625 Assert.IsNotNull (ex.ParamName, "#5");
1626 Assert.AreEqual ("address", ex.ParamName, "#6");
1630 [Test] // UploadValues (Uri, string, NameValueCollection)
1631 public void UploadValues4_Address_SchemeNotSupported ()
1633 WebClient wc = new WebClient ();
1635 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1636 "POST", new NameValueCollection ());
1638 } catch (WebException ex) {
1639 // An error occurred performing a WebClient request
1640 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1641 Assert.IsNotNull (ex.InnerException, "#3");
1642 Assert.IsNotNull (ex.Message, "#4");
1643 Assert.IsNull (ex.Response, "#5");
1644 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1646 // The URI prefix is not recognized
1647 Exception inner = ex.InnerException;
1648 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1649 Assert.IsNull (inner.InnerException, "#8");
1650 Assert.IsNotNull (inner.Message, "#9");
1654 [Test] // UploadValues (Uri, string, NameValueCollection)
1655 public void UploadValues4_Data_Null ()
1657 WebClient wc = new WebClient ();
1659 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1660 "POST", (NameValueCollection) null);
1662 } catch (ArgumentNullException ex) {
1663 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1664 Assert.IsNull (ex.InnerException, "#3");
1665 Assert.IsNotNull (ex.Message, "#4");
1666 Assert.IsNotNull (ex.ParamName, "#5");
1667 Assert.AreEqual ("data", ex.ParamName, "#6");
1672 public void GetWebRequestOverriding ()
1674 GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1675 testObject.DownloadData ("http://www.mono-project.com");
1677 Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1680 class GetWebRequestOverridingTestClass : WebClient
1682 internal bool overridedCodeRan = false;
1683 protected override WebRequest GetWebRequest(Uri address)
1685 overridedCodeRan = true;
1686 return base.GetWebRequest (address);
1690 static byte [] EchoRequestHandler (Socket socket)
1692 MemoryStream ms = new MemoryStream ();
1693 byte [] buffer = new byte [4096];
1694 int bytesReceived = socket.Receive (buffer);
1695 while (bytesReceived > 0) {
1696 ms.Write (buffer, 0, bytesReceived);
1697 // We don't check for Content-Length or anything else here, so we give the client a little time to write
1698 // after sending the headers
1700 if (socket.Available > 0) {
1701 bytesReceived = socket.Receive (buffer);
1709 StringBuilder sb = new StringBuilder ();
1711 string expect = null;
1713 StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1716 while ((line = sr.ReadLine ()) != null) {
1721 } if (line.Length == 0) {
1723 } else if (line.StartsWith ("Expect:")) {
1724 expect = line.Substring (8);
1728 StringWriter sw = new StringWriter ();
1730 if (expect == "100-continue" && state != 2) {
1731 sw.WriteLine ("HTTP/1.1 100 Continue");
1735 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1738 ms = new MemoryStream ();
1739 buffer = new byte [4096];
1740 bytesReceived = socket.Receive (buffer);
1741 while (bytesReceived > 0) {
1742 ms.Write (buffer, 0, bytesReceived);
1744 if (socket.Available > 0) {
1745 bytesReceived = socket.Receive (buffer);
1753 sb = new StringBuilder ();
1754 sr = new StreamReader (ms, Encoding.UTF8);
1755 line = sr.ReadLine ();
1756 while (line != null) {
1759 line = sr.ReadLine ();
1763 sw = new StringWriter ();
1764 sw.WriteLine ("HTTP/1.1 200 OK");
1765 sw.WriteLine ("Content-Type: text/xml");
1766 sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1768 sw.Write (sb.ToString ());
1771 return Encoding.UTF8.GetBytes (sw.ToString ());
1775 public void DefaultProxy ()
1777 WebClient wc = new WebClient ();
1778 // this is never null on .net
1779 Assert.IsNotNull (wc.Proxy);
1780 // and return the same instance as WebRequest.DefaultWebProxy
1781 Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1786 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1787 public void UploadStringAsyncCancelEvent ()
1789 UploadAsyncCancelEventTest (9301, (webClient, uri, cancelEvent) =>
1792 webClient.UploadStringCompleted += (sender, args) =>
1798 webClient.UploadStringAsync (uri, "PUT", "text");
1803 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1804 public void UploadDataAsyncCancelEvent ()
1806 UploadAsyncCancelEventTest (9302, (webClient, uri, cancelEvent) =>
1808 webClient.UploadDataCompleted += (sender, args) =>
1814 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1819 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1820 public void UploadValuesAsyncCancelEvent ()
1822 UploadAsyncCancelEventTest (9303, (webClient, uri, cancelEvent) =>
1824 webClient.UploadValuesCompleted += (sender, args) =>
1830 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1835 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1836 public void UploadFileAsyncCancelEvent ()
1838 UploadAsyncCancelEventTest (9304,(webClient, uri, cancelEvent) =>
1840 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1841 File.Create (tempFile).Close ();
1843 webClient.UploadFileCompleted += (sender, args) =>
1849 webClient.UploadFileAsync (uri, "PUT", tempFile);
1854 [Category ("AndroidNotWorking")] // Test suite hangs if the tests runs as part of the entire BCL suite. Works when only this fixture is ran
1855 public void UploadFileAsyncContentType ()
1857 var port = NetworkHelpers.FindFreePort ();
1858 var serverUri = "http://localhost:" + port + "/";
1859 var filename = Path.GetTempFileName ();
1861 HttpListener listener = new HttpListener ();
1862 listener.Prefixes.Add (serverUri);
1865 using (var client = new WebClient ())
1867 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1868 var request = listener.GetContext ().Request;
1870 var expected = "multipart/form-data; boundary=---------------------";
1871 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1872 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1878 public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
1880 var ep = NetworkHelpers.LocalEphemeralEndPoint ();
1881 string url = "http://" + ep.ToString() + "/test/";
1883 using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s)))
1885 var webClient = new WebClient ();
1887 var cancellationTokenSource = new CancellationTokenSource ();
1888 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1890 var cancelEvent = new ManualResetEvent (false);
1892 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1894 cancellationTokenSource.Cancel ();
1896 Assert.IsTrue (cancelEvent.WaitOne (1000));