2 // WebClientTest.cs - NUnit Test Cases for System.Net.WebClient
4 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8 using System.Collections;
9 using System.Collections.Specialized;
10 using System.Globalization;
13 using System.Net.Sockets;
14 using System.Runtime.Serialization;
16 using System.Threading;
17 using NUnit.Framework;
19 using MonoTests.Helpers;
21 namespace MonoTests.System.Net
24 public class WebClientTest
26 private string _tempFolder;
31 _tempFolder = Path.Combine (Path.GetTempPath (),
33 if (Directory.Exists (_tempFolder))
34 Directory.Delete (_tempFolder, true);
35 Directory.CreateDirectory (_tempFolder);
39 public void TearDown ()
41 if (Directory.Exists (_tempFolder))
42 Directory.Delete (_tempFolder, true);
46 [Category ("InetAccess")]
47 public void DownloadTwice ()
49 WebClient wc = new WebClient();
50 string filename = Path.GetTempFileName();
52 // A new, but empty file has been created. This is a test case
54 wc.DownloadFile("http://google.com/", filename);
56 // Now, remove the file and attempt to download again.
57 File.Delete(filename);
58 wc.DownloadFile("http://google.com/", filename);
62 public void DownloadData1_Address_Null ()
64 WebClient wc = new WebClient ();
66 wc.DownloadData ((string) null);
68 } catch (ArgumentNullException ex) {
69 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
70 Assert.IsNull (ex.InnerException, "#3");
71 Assert.IsNotNull (ex.Message, "#4");
72 Assert.IsNotNull (ex.ParamName, "#5");
73 Assert.AreEqual ("address", ex.ParamName, "#6");
77 [Test] // DownloadData (string)
78 public void DownloadData1_Address_SchemeNotSupported ()
80 WebClient wc = new WebClient ();
82 wc.DownloadData ("tp://scheme.notsupported");
84 } catch (WebException ex) {
85 // An error occurred performing a WebClient request
86 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
87 Assert.IsNotNull (ex.InnerException, "#3");
88 Assert.IsNotNull (ex.Message, "#4");
89 Assert.IsNull (ex.Response, "#5");
90 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
92 // The URI prefix is not recognized
93 Exception inner = ex.InnerException;
94 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
95 Assert.IsNull (inner.InnerException, "#8");
96 Assert.IsNotNull (inner.Message, "#9");
100 [Test] // DownloadData (Uri)
101 public void DownloadData2_Address_Null ()
103 WebClient wc = new WebClient ();
105 wc.DownloadData ((Uri) null);
107 } catch (ArgumentNullException ex) {
108 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
109 Assert.IsNull (ex.InnerException, "#3");
110 Assert.IsNotNull (ex.Message, "#4");
111 Assert.IsNotNull (ex.ParamName, "#5");
112 Assert.AreEqual ("address", ex.ParamName, "#6");
116 [Test] // DownloadData (Uri)
117 public void DownloadData2_Address_SchemeNotSupported ()
119 WebClient wc = new WebClient ();
121 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
123 } catch (WebException ex) {
124 // An error occurred performing a WebClient request
125 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
126 Assert.IsNotNull (ex.InnerException, "#3");
127 Assert.IsNotNull (ex.Message, "#4");
128 Assert.IsNull (ex.Response, "#5");
129 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
131 // The URI prefix is not recognized
132 Exception inner = ex.InnerException;
133 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
134 Assert.IsNull (inner.InnerException, "#8");
135 Assert.IsNotNull (inner.Message, "#9");
140 public void DownloadFile1_Address_Null ()
142 WebClient wc = new WebClient ();
144 wc.DownloadFile ((string) null, "tmp.out");
146 } catch (ArgumentNullException ex) {
147 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
148 Assert.IsNull (ex.InnerException, "#3");
149 Assert.IsNotNull (ex.Message, "#4");
150 Assert.IsNotNull (ex.ParamName, "#5");
151 Assert.AreEqual ("address", ex.ParamName, "#6");
155 [Test] // DownloadFile (string, string)
156 public void DownloadFile1_Address_SchemeNotSupported ()
158 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
159 WebClient wc = new WebClient ();
161 wc.DownloadFile ("tp://scheme.notsupported", file);
163 } catch (WebException ex) {
164 // An error occurred performing a WebClient request
165 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
166 Assert.IsNotNull (ex.InnerException, "#3");
167 Assert.IsNotNull (ex.Message, "#4");
168 Assert.IsNull (ex.Response, "#5");
169 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
171 // The URI prefix is not recognized
172 Exception inner = ex.InnerException;
173 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
174 Assert.IsNull (inner.InnerException, "#8");
175 Assert.IsNotNull (inner.Message, "#9");
178 if (File.Exists (file))
183 [Test] // DownloadFile (string, string)
184 public void DownloadFile1_FileName_Null ()
186 WebClient wc = new WebClient ();
188 wc.DownloadFile ("tp://scheme.notsupported",
191 } catch (ArgumentNullException ex) {
192 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
193 Assert.IsNull (ex.InnerException, "#3");
194 Assert.IsNotNull (ex.Message, "#4");
195 Assert.IsNotNull (ex.ParamName, "#5");
196 Assert.AreEqual ("fileName", ex.ParamName, "#6");
200 [Test] // DownloadFile (Uri, string)
201 public void DownloadFile2_Address_Null ()
203 WebClient wc = new WebClient ();
205 wc.DownloadFile ((Uri) null, "tmp.out");
207 } catch (ArgumentNullException ex) {
208 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
209 Assert.IsNull (ex.InnerException, "#3");
210 Assert.IsNotNull (ex.Message, "#4");
211 Assert.IsNotNull (ex.ParamName, "#5");
212 Assert.AreEqual ("address", ex.ParamName, "#6");
216 [Test] // DownloadFile (Uri, string)
217 public void DownloadFile2_Address_SchemeNotSupported ()
219 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
220 WebClient wc = new WebClient ();
222 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
224 } catch (WebException ex) {
225 // An error occurred performing a WebClient request
226 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
227 Assert.IsNotNull (ex.InnerException, "#3");
228 Assert.IsNotNull (ex.Message, "#4");
229 Assert.IsNull (ex.Response, "#5");
230 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
232 // The URI prefix is not recognized
233 Exception inner = ex.InnerException;
234 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
235 Assert.IsNull (inner.InnerException, "#8");
236 Assert.IsNotNull (inner.Message, "#9");
239 if (File.Exists (file))
244 [Test] // DownloadFile (Uri, string)
245 public void DownloadFile2_FileName_Null ()
247 WebClient wc = new WebClient ();
249 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
252 } catch (ArgumentNullException ex) {
253 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
254 Assert.IsNull (ex.InnerException, "#3");
255 Assert.IsNotNull (ex.Message, "#4");
256 Assert.IsNotNull (ex.ParamName, "#5");
257 Assert.AreEqual ("fileName", ex.ParamName, "#6");
261 [Test] // DownloadString (string)
262 public void DownloadString1_Address_Null ()
264 WebClient wc = new WebClient ();
266 wc.DownloadString ((string) null);
268 } catch (ArgumentNullException ex) {
269 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
270 Assert.IsNull (ex.InnerException, "#3");
271 Assert.IsNotNull (ex.Message, "#4");
272 Assert.IsNotNull (ex.ParamName, "#5");
273 Assert.AreEqual ("address", ex.ParamName, "#6");
277 [Test] // DownloadString (string)
278 public void DownloadString1_Address_SchemeNotSupported ()
280 WebClient wc = new WebClient ();
282 wc.DownloadString ("tp://scheme.notsupported");
284 } catch (WebException ex) {
285 // An error occurred performing a WebClient request
286 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
287 Assert.IsNotNull (ex.InnerException, "#3");
288 Assert.IsNotNull (ex.Message, "#4");
289 Assert.IsNull (ex.Response, "#5");
290 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
292 // The URI prefix is not recognized
293 Exception inner = ex.InnerException;
294 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
295 Assert.IsNull (inner.InnerException, "#8");
296 Assert.IsNotNull (inner.Message, "#9");
300 [Test] // DownloadString (Uri)
301 public void DownloadString2_Address_Null ()
303 WebClient wc = new WebClient ();
305 wc.DownloadString ((Uri) null);
307 } catch (ArgumentNullException ex) {
308 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
309 Assert.IsNull (ex.InnerException, "#3");
310 Assert.IsNotNull (ex.Message, "#4");
311 Assert.IsNotNull (ex.ParamName, "#5");
312 Assert.AreEqual ("address", ex.ParamName, "#6");
316 [Test] // DownloadString (Uri)
317 public void DownloadString2_Address_SchemeNotSupported ()
319 WebClient wc = new WebClient ();
321 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
323 } catch (WebException ex) {
324 // An error occurred performing a WebClient request
325 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
326 Assert.IsNotNull (ex.InnerException, "#3");
327 Assert.IsNotNull (ex.Message, "#4");
328 Assert.IsNull (ex.Response, "#5");
329 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
331 // The URI prefix is not recognized
332 Exception inner = ex.InnerException;
333 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
334 Assert.IsNull (inner.InnerException, "#8");
335 Assert.IsNotNull (inner.Message, "#9");
340 public void EncodingTest ()
342 WebClient wc = new WebClient ();
343 Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
344 wc.Encoding = Encoding.ASCII;
345 Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
349 public void Encoding_Value_Null ()
351 WebClient wc = new WebClient ();
355 } catch (ArgumentNullException ex) {
356 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
357 Assert.IsNull (ex.InnerException, "#3");
358 Assert.IsNotNull (ex.Message, "#4");
359 Assert.AreEqual ("Encoding", ex.ParamName, "#6");
363 [Test] // OpenRead (string)
364 public void OpenRead1_Address_Null ()
366 WebClient wc = new WebClient ();
368 wc.OpenRead ((string) null);
370 } catch (ArgumentNullException ex) {
371 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
372 Assert.IsNull (ex.InnerException, "#3");
373 Assert.IsNotNull (ex.Message, "#4");
374 Assert.IsNotNull (ex.ParamName, "#5");
375 Assert.AreEqual ("address", ex.ParamName, "#6");
379 [Test] // OpenRead (string)
380 public void OpenRead1_Address_SchemeNotSupported ()
382 WebClient wc = new WebClient ();
384 wc.OpenRead ("tp://scheme.notsupported");
386 } catch (WebException ex) {
387 // An error occurred performing a WebClient request
388 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
389 Assert.IsNotNull (ex.InnerException, "#3");
390 Assert.IsNotNull (ex.Message, "#4");
391 Assert.IsNull (ex.Response, "#5");
392 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
394 // The URI prefix is not recognized
395 Exception inner = ex.InnerException;
396 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
397 Assert.IsNull (inner.InnerException, "#8");
398 Assert.IsNotNull (inner.Message, "#9");
402 [Test] // OpenRead (Uri)
403 public void OpenRead2_Address_Null ()
405 WebClient wc = new WebClient ();
407 wc.OpenRead ((Uri) null);
409 } catch (ArgumentNullException ex) {
410 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
411 Assert.IsNull (ex.InnerException, "#3");
412 Assert.IsNotNull (ex.Message, "#4");
413 Assert.IsNotNull (ex.ParamName, "#5");
414 Assert.AreEqual ("address", ex.ParamName, "#6");
418 [Test] // OpenRead (Uri)
419 public void OpenRead2_Address_SchemeNotSupported ()
421 WebClient wc = new WebClient ();
423 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
425 } catch (WebException ex) {
426 // An error occurred performing a WebClient request
427 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
428 Assert.IsNotNull (ex.InnerException, "#3");
429 Assert.IsNotNull (ex.Message, "#4");
430 Assert.IsNull (ex.Response, "#5");
431 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
433 // The URI prefix is not recognized
434 Exception inner = ex.InnerException;
435 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
436 Assert.IsNull (inner.InnerException, "#8");
437 Assert.IsNotNull (inner.Message, "#9");
442 public void OpenReadTaskAsyncOnFile ()
444 var tmp = Path.GetTempFileName ();
445 string url = "file://" + tmp;
447 var client = new WebClient ();
448 var task = client.OpenReadTaskAsync (url);
449 Assert.IsTrue (task.Wait (2000));
452 [Test] // OpenWrite (string)
453 public void OpenWrite1_Address_Null ()
455 WebClient wc = new WebClient ();
457 wc.OpenWrite ((string) null);
459 } catch (ArgumentNullException ex) {
460 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
461 Assert.IsNull (ex.InnerException, "#3");
462 Assert.IsNotNull (ex.Message, "#4");
463 Assert.IsNotNull (ex.ParamName, "#5");
464 Assert.AreEqual ("address", ex.ParamName, "#6");
468 [Test] // OpenWrite (string)
469 public void OpenWrite1_Address_SchemeNotSupported ()
471 WebClient wc = new WebClient ();
473 wc.OpenWrite ("tp://scheme.notsupported");
475 } catch (WebException ex) {
476 // An error occurred performing a WebClient request
477 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
478 Assert.IsNotNull (ex.InnerException, "#3");
479 Assert.IsNotNull (ex.Message, "#4");
480 Assert.IsNull (ex.Response, "#5");
481 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
483 // The URI prefix is not recognized
484 Exception inner = ex.InnerException;
485 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
486 Assert.IsNull (inner.InnerException, "#8");
487 Assert.IsNotNull (inner.Message, "#9");
491 [Test] // OpenWrite (string, string)
492 public void OpenWrite2_Address_Null ()
494 WebClient wc = new WebClient ();
496 wc.OpenWrite ((string) null, "PUT");
498 } catch (ArgumentNullException ex) {
499 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
500 Assert.IsNull (ex.InnerException, "#3");
501 Assert.IsNotNull (ex.Message, "#4");
502 Assert.IsNotNull (ex.ParamName, "#5");
503 Assert.AreEqual ("address", ex.ParamName, "#6");
507 [Test] // OpenWrite (string, string)
508 public void OpenWrite2_Address_SchemeNotSupported ()
510 WebClient wc = new WebClient ();
512 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
514 } catch (WebException ex) {
515 // An error occurred performing a WebClient request
516 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
517 Assert.IsNotNull (ex.InnerException, "#3");
518 Assert.IsNotNull (ex.Message, "#4");
519 Assert.IsNull (ex.Response, "#5");
520 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
522 // The URI prefix is not recognized
523 Exception inner = ex.InnerException;
524 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
525 Assert.IsNull (inner.InnerException, "#8");
526 Assert.IsNotNull (inner.Message, "#9");
530 [Test] // OpenWrite (Uri)
531 public void OpenWrite3_Address_Null ()
533 WebClient wc = new WebClient ();
535 wc.OpenWrite ((Uri) null);
537 } catch (ArgumentNullException ex) {
538 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
539 Assert.IsNull (ex.InnerException, "#3");
540 Assert.IsNotNull (ex.Message, "#4");
541 Assert.IsNotNull (ex.ParamName, "#5");
542 Assert.AreEqual ("address", ex.ParamName, "#6");
546 [Test] // OpenWrite (Uri)
547 public void OpenWrite3_Address_SchemeNotSupported ()
549 WebClient wc = new WebClient ();
551 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
553 } catch (WebException ex) {
554 // An error occurred performing a WebClient request
555 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
556 Assert.IsNotNull (ex.InnerException, "#3");
557 Assert.IsNotNull (ex.Message, "#4");
558 Assert.IsNull (ex.Response, "#5");
559 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
561 // The URI prefix is not recognized
562 Exception inner = ex.InnerException;
563 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
564 Assert.IsNull (inner.InnerException, "#8");
565 Assert.IsNotNull (inner.Message, "#9");
569 [Test] // OpenWrite (Uri, string)
570 public void OpenWrite4_Address_Null ()
572 WebClient wc = new WebClient ();
574 wc.OpenWrite ((Uri) null, "POST");
576 } catch (ArgumentNullException ex) {
577 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
578 Assert.IsNull (ex.InnerException, "#3");
579 Assert.IsNotNull (ex.Message, "#4");
580 Assert.IsNotNull (ex.ParamName, "#5");
581 Assert.AreEqual ("address", ex.ParamName, "#6");
585 [Test] // OpenWrite (Uri, string)
586 public void OpenWrite4_Address_SchemeNotSupported ()
588 WebClient wc = new WebClient ();
590 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
593 } catch (WebException ex) {
594 // An error occurred performing a WebClient request
595 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
596 Assert.IsNotNull (ex.InnerException, "#3");
597 Assert.IsNotNull (ex.Message, "#4");
598 Assert.IsNull (ex.Response, "#5");
599 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
601 // The URI prefix is not recognized
602 Exception inner = ex.InnerException;
603 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
604 Assert.IsNull (inner.InnerException, "#8");
605 Assert.IsNotNull (inner.Message, "#9");
609 [Test] // UploadData (string, byte [])
610 public void UploadData1_Address_Null ()
612 WebClient wc = new WebClient ();
614 wc.UploadData ((string) null, new byte [] { 0x1a });
616 } catch (ArgumentNullException ex) {
617 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
618 Assert.IsNull (ex.InnerException, "#3");
619 Assert.IsNotNull (ex.Message, "#4");
620 Assert.IsNotNull (ex.ParamName, "#5");
621 Assert.AreEqual ("address", ex.ParamName, "#6");
625 [Test] // UploadData (string, byte [])
626 public void UploadData1_Address_SchemeNotSupported ()
628 WebClient wc = new WebClient ();
630 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
632 } catch (WebException ex) {
633 // An error occurred performing a WebClient request
634 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
635 Assert.IsNotNull (ex.InnerException, "#3");
636 Assert.IsNotNull (ex.Message, "#4");
637 Assert.IsNull (ex.Response, "#5");
638 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
640 // The URI prefix is not recognized
641 Exception inner = ex.InnerException;
642 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
643 Assert.IsNull (inner.InnerException, "#8");
644 Assert.IsNotNull (inner.Message, "#9");
648 [Test] // UploadData (string, byte [])
649 public void UploadData1_Data_Null ()
651 WebClient wc = new WebClient ();
653 wc.UploadData ("http://www.mono-project.com",
656 } catch (ArgumentNullException ex) {
657 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
658 Assert.IsNull (ex.InnerException, "#3");
659 Assert.IsNotNull (ex.Message, "#4");
660 Assert.IsNotNull (ex.ParamName, "#5");
661 Assert.AreEqual ("data", ex.ParamName, "#6");
665 [Test] // UploadData (Uri, byte [])
666 public void UploadData2_Address_Null ()
668 WebClient wc = new WebClient ();
670 wc.UploadData ((Uri) null, new byte [] { 0x1a });
672 } catch (ArgumentNullException ex) {
673 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
674 Assert.IsNull (ex.InnerException, "#3");
675 Assert.IsNotNull (ex.Message, "#4");
676 Assert.IsNotNull (ex.ParamName, "#5");
677 Assert.AreEqual ("address", ex.ParamName, "#6");
681 [Test] // UploadData (Uri, byte [])
682 public void UploadData2_Address_SchemeNotSupported ()
684 WebClient wc = new WebClient ();
686 wc.UploadData (new Uri ("tp://scheme.notsupported"),
687 new byte [] { 0x1a });
689 } catch (WebException ex) {
690 // An error occurred performing a WebClient request
691 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
692 Assert.IsNotNull (ex.InnerException, "#3");
693 Assert.IsNotNull (ex.Message, "#4");
694 Assert.IsNull (ex.Response, "#5");
695 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
697 // The URI prefix is not recognized
698 Exception inner = ex.InnerException;
699 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
700 Assert.IsNull (inner.InnerException, "#8");
701 Assert.IsNotNull (inner.Message, "#9");
705 [Test] // UploadData (Uri, byte [])
706 public void UploadData2_Data_Null ()
708 WebClient wc = new WebClient ();
710 wc.UploadData (new Uri ("http://www.mono-project.com"),
713 } catch (ArgumentNullException ex) {
714 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
715 Assert.IsNull (ex.InnerException, "#3");
716 Assert.IsNotNull (ex.Message, "#4");
717 Assert.IsNotNull (ex.ParamName, "#5");
718 Assert.AreEqual ("data", ex.ParamName, "#6");
722 [Test] // UploadData (string, string, byte [])
723 public void UploadData3_Address_Null ()
725 WebClient wc = new WebClient ();
727 wc.UploadData ((string) null, "POST",
728 new byte [] { 0x1a });
730 } catch (ArgumentNullException ex) {
731 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
732 Assert.IsNull (ex.InnerException, "#3");
733 Assert.IsNotNull (ex.Message, "#4");
734 Assert.IsNotNull (ex.ParamName, "#5");
735 Assert.AreEqual ("address", ex.ParamName, "#6");
739 [Test] // UploadData (string, string, byte [])
740 public void UploadData3_Address_SchemeNotSupported ()
742 WebClient wc = new WebClient ();
744 wc.UploadData ("tp://scheme.notsupported",
745 "POST", new byte [] { 0x1a });
747 } catch (WebException ex) {
748 // An error occurred performing a WebClient request
749 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
750 Assert.IsNotNull (ex.InnerException, "#3");
751 Assert.IsNotNull (ex.Message, "#4");
752 Assert.IsNull (ex.Response, "#5");
753 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
755 // The URI prefix is not recognized
756 Exception inner = ex.InnerException;
757 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
758 Assert.IsNull (inner.InnerException, "#8");
759 Assert.IsNotNull (inner.Message, "#9");
763 [Test] // UploadData (string, string, byte [])
764 public void UploadData3_Data_Null ()
766 WebClient wc = new WebClient ();
768 wc.UploadData ("http://www.mono-project.com",
769 "POST", (byte []) null);
771 } catch (ArgumentNullException ex) {
772 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
773 Assert.IsNull (ex.InnerException, "#3");
774 Assert.IsNotNull (ex.Message, "#4");
775 Assert.IsNotNull (ex.ParamName, "#5");
776 Assert.AreEqual ("data", ex.ParamName, "#6");
780 [Test] // UploadData (Uri, string, byte [])
781 public void UploadData4_Address_Null ()
783 WebClient wc = new WebClient ();
785 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
787 } catch (ArgumentNullException ex) {
788 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
789 Assert.IsNull (ex.InnerException, "#3");
790 Assert.IsNotNull (ex.Message, "#4");
791 Assert.IsNotNull (ex.ParamName, "#5");
792 Assert.AreEqual ("address", ex.ParamName, "#6");
796 [Test] // UploadData (Uri, string, byte [])
797 public void UploadData4_Address_SchemeNotSupported ()
799 WebClient wc = new WebClient ();
801 wc.UploadData (new Uri ("tp://scheme.notsupported"),
802 "POST", new byte [] { 0x1a });
804 } catch (WebException ex) {
805 // An error occurred performing a WebClient request
806 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
807 Assert.IsNotNull (ex.InnerException, "#3");
808 Assert.IsNotNull (ex.Message, "#4");
809 Assert.IsNull (ex.Response, "#5");
810 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
812 // The URI prefix is not recognized
813 Exception inner = ex.InnerException;
814 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
815 Assert.IsNull (inner.InnerException, "#8");
816 Assert.IsNotNull (inner.Message, "#9");
820 [Test] // UploadData (Uri, string, byte [])
821 public void UploadData4_Data_Null ()
823 WebClient wc = new WebClient ();
825 wc.UploadData (new Uri ("http://www.mono-project.com"),
826 "POST", (byte []) null);
828 } catch (ArgumentNullException ex) {
829 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
830 Assert.IsNull (ex.InnerException, "#3");
831 Assert.IsNotNull (ex.Message, "#4");
832 Assert.IsNotNull (ex.ParamName, "#5");
833 Assert.AreEqual ("data", ex.ParamName, "#6");
837 [Test] // UploadFile (string, string)
838 public void UploadFile1_Address_Null ()
840 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
841 File.Create (tempFile).Close ();
843 WebClient wc = new WebClient ();
845 wc.UploadFile ((string) null, tempFile);
847 } catch (ArgumentNullException ex) {
848 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
849 Assert.IsNull (ex.InnerException, "#3");
850 Assert.IsNotNull (ex.Message, "#4");
851 Assert.IsNotNull (ex.ParamName, "#5");
852 Assert.AreEqual ("address", ex.ParamName, "#6");
856 [Test] // UploadFile (string, string)
857 public void UploadFile1_Address_SchemeNotSupported ()
859 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
860 File.Create (tempFile).Close ();
862 WebClient wc = new WebClient ();
864 wc.UploadFile ("tp://scheme.notsupported",
867 } catch (WebException ex) {
868 // An error occurred performing a WebClient request
869 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
870 Assert.IsNotNull (ex.InnerException, "#3");
871 Assert.IsNotNull (ex.Message, "#4");
872 Assert.IsNull (ex.Response, "#5");
873 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
875 // The URI prefix is not recognized
876 Exception inner = ex.InnerException;
877 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
878 Assert.IsNull (inner.InnerException, "#8");
879 Assert.IsNotNull (inner.Message, "#9");
883 [Test] // UploadFile (string, string)
884 public void UploadFile1_FileName_NotFound ()
886 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
888 WebClient wc = new WebClient ();
890 wc.UploadFile ("tp://scheme.notsupported",
893 } catch (WebException ex) {
894 // An error occurred performing a WebClient request
895 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
896 Assert.IsNotNull (ex.Message, "#3");
897 Assert.IsNull (ex.Response, "#4");
898 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
900 // Could not find file "..."
901 FileNotFoundException inner = ex.InnerException
902 as FileNotFoundException;
903 Assert.IsNotNull (inner, "#6");
904 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
905 Assert.IsNotNull (inner.FileName, "#8");
906 Assert.AreEqual (tempFile, inner.FileName, "#9");
907 Assert.IsNull (inner.InnerException, "#10");
908 Assert.IsNotNull (inner.Message, "#11");
912 [Test] // UploadFile (string, string)
913 public void UploadFile1_FileName_Null ()
915 WebClient wc = new WebClient ();
917 wc.UploadFile ("tp://scheme.notsupported",
920 } catch (ArgumentNullException ex) {
921 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
922 Assert.IsNull (ex.InnerException, "#3");
923 Assert.IsNotNull (ex.Message, "#4");
924 Assert.IsNotNull (ex.ParamName, "#5");
925 Assert.AreEqual ("fileName", ex.ParamName, "#6");
929 [Test] // UploadFile (Uri, string)
930 public void UploadFile2_Address_Null ()
932 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
934 WebClient wc = new WebClient ();
936 wc.UploadFile ((Uri) null, tempFile);
938 } catch (ArgumentNullException ex) {
939 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
940 Assert.IsNull (ex.InnerException, "#3");
941 Assert.IsNotNull (ex.Message, "#4");
942 Assert.IsNotNull (ex.ParamName, "#5");
943 Assert.AreEqual ("address", ex.ParamName, "#6");
947 [Test] // UploadFile (Uri, string)
948 public void UploadFile2_Address_SchemeNotSupported ()
950 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
951 File.Create (tempFile).Close ();
953 WebClient wc = new WebClient ();
955 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
958 } catch (WebException ex) {
959 // An error occurred performing a WebClient request
960 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
961 Assert.IsNotNull (ex.InnerException, "#3");
962 Assert.IsNotNull (ex.Message, "#4");
963 Assert.IsNull (ex.Response, "#5");
964 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
966 // The URI prefix is not recognized
967 Exception inner = ex.InnerException;
968 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
969 Assert.IsNull (inner.InnerException, "#8");
970 Assert.IsNotNull (inner.Message, "#9");
974 [Test] // UploadFile (Uri, string)
975 public void UploadFile2_FileName_NotFound ()
977 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
979 WebClient wc = new WebClient ();
981 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
984 } catch (WebException ex) {
985 // An error occurred performing a WebClient request
986 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
987 Assert.IsNotNull (ex.Message, "#3");
988 Assert.IsNull (ex.Response, "#4");
989 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
991 // Could not find file "..."
992 FileNotFoundException inner = ex.InnerException
993 as FileNotFoundException;
994 Assert.IsNotNull (inner, "#6");
995 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
996 Assert.IsNotNull (inner.FileName, "#8");
997 Assert.AreEqual (tempFile, inner.FileName, "#9");
998 Assert.IsNull (inner.InnerException, "#10");
999 Assert.IsNotNull (inner.Message, "#11");
1003 [Test] // UploadFile (Uri, string)
1004 public void UploadFile2_FileName_Null ()
1006 WebClient wc = new WebClient ();
1008 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1011 } catch (ArgumentNullException ex) {
1012 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1013 Assert.IsNull (ex.InnerException, "#3");
1014 Assert.IsNotNull (ex.Message, "#4");
1015 Assert.IsNotNull (ex.ParamName, "#5");
1016 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1020 [Test] // UploadFile (string, string, string)
1021 public void UploadFile3_Address_Null ()
1023 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1024 File.Create (tempFile).Close ();
1026 WebClient wc = new WebClient ();
1028 wc.UploadFile ((string) null, "POST", tempFile);
1030 } catch (ArgumentNullException ex) {
1031 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1032 Assert.IsNull (ex.InnerException, "#3");
1033 Assert.IsNotNull (ex.Message, "#4");
1034 Assert.IsNotNull (ex.ParamName, "#5");
1035 Assert.AreEqual ("path", ex.ParamName, "#6");
1039 [Test] // UploadFile (string, string, string)
1040 public void UploadFile3_Address_SchemeNotSupported ()
1042 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1043 File.Create (tempFile).Close ();
1045 WebClient wc = new WebClient ();
1047 wc.UploadFile ("tp://scheme.notsupported",
1050 } catch (WebException ex) {
1051 // An error occurred performing a WebClient request
1052 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1053 Assert.IsNotNull (ex.InnerException, "#3");
1054 Assert.IsNotNull (ex.Message, "#4");
1055 Assert.IsNull (ex.Response, "#5");
1056 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1058 // The URI prefix is not recognized
1059 Exception inner = ex.InnerException;
1060 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1061 Assert.IsNull (inner.InnerException, "#8");
1062 Assert.IsNotNull (inner.Message, "#9");
1066 [Test] // UploadFile (string, string, string)
1067 public void UploadFile3_FileName_NotFound ()
1069 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1071 WebClient wc = new WebClient ();
1073 wc.UploadFile ("tp://scheme.notsupported",
1076 } catch (WebException ex) {
1077 // An error occurred performing a WebClient request
1078 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1079 Assert.IsNotNull (ex.Message, "#3");
1080 Assert.IsNull (ex.Response, "#4");
1081 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1083 // Could not find file "..."
1084 FileNotFoundException inner = ex.InnerException
1085 as FileNotFoundException;
1086 Assert.IsNotNull (inner, "#6");
1087 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1088 Assert.IsNotNull (inner.FileName, "#8");
1089 Assert.AreEqual (tempFile, inner.FileName, "#9");
1090 Assert.IsNull (inner.InnerException, "#10");
1091 Assert.IsNotNull (inner.Message, "#11");
1095 [Test] // UploadFile (string, string, string)
1096 public void UploadFile3_FileName_Null ()
1098 WebClient wc = new WebClient ();
1100 wc.UploadFile ("tp://scheme.notsupported",
1101 "POST", (string) null);
1103 } catch (ArgumentNullException ex) {
1104 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1105 Assert.IsNull (ex.InnerException, "#3");
1106 Assert.IsNotNull (ex.Message, "#4");
1107 Assert.IsNotNull (ex.ParamName, "#5");
1108 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1112 [Test] // UploadFile (Uri, string, string)
1113 public void UploadFile4_Address_Null ()
1115 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1117 WebClient wc = new WebClient ();
1119 wc.UploadFile ((Uri) null, "POST", tempFile);
1121 } catch (ArgumentNullException ex) {
1122 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1123 Assert.IsNull (ex.InnerException, "#3");
1124 Assert.IsNotNull (ex.Message, "#4");
1125 Assert.IsNotNull (ex.ParamName, "#5");
1126 Assert.AreEqual ("address", ex.ParamName, "#6");
1130 [Test] // UploadFile (Uri, string, string)
1131 public void UploadFile4_Address_SchemeNotSupported ()
1133 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1134 File.Create (tempFile).Close ();
1136 WebClient wc = new WebClient ();
1138 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1141 } catch (WebException ex) {
1142 // An error occurred performing a WebClient request
1143 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1144 Assert.IsNotNull (ex.InnerException, "#3");
1145 Assert.IsNotNull (ex.Message, "#4");
1146 Assert.IsNull (ex.Response, "#5");
1147 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1149 // The URI prefix is not recognized
1150 Exception inner = ex.InnerException;
1151 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1152 Assert.IsNull (inner.InnerException, "#8");
1153 Assert.IsNotNull (inner.Message, "#9");
1157 [Test] // UploadFile (Uri, string, string)
1158 public void UploadFile4_FileName_NotFound ()
1160 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1162 WebClient wc = new WebClient ();
1164 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1167 } catch (WebException ex) {
1168 // An error occurred performing a WebClient request
1169 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1170 Assert.IsNotNull (ex.Message, "#3");
1171 Assert.IsNull (ex.Response, "#4");
1172 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1174 // Could not find file "..."
1175 FileNotFoundException inner = ex.InnerException
1176 as FileNotFoundException;
1177 Assert.IsNotNull (inner, "#6");
1178 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1179 Assert.IsNotNull (inner.FileName, "#8");
1180 Assert.AreEqual (tempFile, inner.FileName, "#9");
1181 Assert.IsNull (inner.InnerException, "#10");
1182 Assert.IsNotNull (inner.Message, "#11");
1186 [Test] // UploadFile (Uri, string, string)
1187 public void UploadFile4_FileName_Null ()
1189 WebClient wc = new WebClient ();
1191 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1192 "POST", (string) null);
1194 } catch (ArgumentNullException ex) {
1195 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1196 Assert.IsNull (ex.InnerException, "#3");
1197 Assert.IsNotNull (ex.Message, "#4");
1198 Assert.IsNotNull (ex.ParamName, "#5");
1199 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1203 [Test] // UploadString (string, string)
1204 public void UploadString1_Address_Null ()
1206 WebClient wc = new WebClient ();
1208 wc.UploadString ((string) null, (string) null);
1210 } catch (ArgumentNullException ex) {
1211 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1212 Assert.IsNull (ex.InnerException, "#3");
1213 Assert.IsNotNull (ex.Message, "#4");
1214 Assert.IsNotNull (ex.ParamName, "#5");
1215 Assert.AreEqual ("address", ex.ParamName, "#6");
1219 [Test] // UploadString (string, string)
1220 public void UploadString1_Address_SchemeNotSupported ()
1222 WebClient wc = new WebClient ();
1224 wc.UploadString ("tp://scheme.notsupported", "abc");
1226 } catch (WebException ex) {
1227 // An error occurred performing a WebClient request
1228 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1229 Assert.IsNotNull (ex.InnerException, "#3");
1230 Assert.IsNotNull (ex.Message, "#4");
1231 Assert.IsNull (ex.Response, "#5");
1232 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1234 // The URI prefix is not recognized
1235 Exception inner = ex.InnerException;
1236 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1237 Assert.IsNull (inner.InnerException, "#8");
1238 Assert.IsNotNull (inner.Message, "#9");
1242 [Test] // UploadString (string, string)
1243 public void UploadString1_Data_Null ()
1245 WebClient wc = new WebClient ();
1247 wc.UploadString ("tp://scheme.notsupported", (string) null);
1249 } catch (ArgumentNullException ex) {
1250 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1251 Assert.IsNull (ex.InnerException, "#3");
1252 Assert.IsNotNull (ex.Message, "#4");
1253 Assert.IsNotNull (ex.ParamName, "#5");
1254 Assert.AreEqual ("data", ex.ParamName, "#6");
1258 [Test] // UploadString (Uri, string)
1259 public void UploadString2_Address_Null ()
1261 WebClient wc = new WebClient ();
1263 wc.UploadString ((Uri) null, (string) null);
1265 } catch (ArgumentNullException ex) {
1266 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1267 Assert.IsNull (ex.InnerException, "#3");
1268 Assert.IsNotNull (ex.Message, "#4");
1269 Assert.IsNotNull (ex.ParamName, "#5");
1270 Assert.AreEqual ("address", ex.ParamName, "#6");
1274 [Test] // UploadString (Uri, string)
1275 public void UploadString2_Address_SchemeNotSupported ()
1277 WebClient wc = new WebClient ();
1279 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1281 } catch (WebException ex) {
1282 // An error occurred performing a WebClient request
1283 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1284 Assert.IsNotNull (ex.InnerException, "#3");
1285 Assert.IsNotNull (ex.Message, "#4");
1286 Assert.IsNull (ex.Response, "#5");
1287 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1289 // The URI prefix is not recognized
1290 Exception inner = ex.InnerException;
1291 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1292 Assert.IsNull (inner.InnerException, "#8");
1293 Assert.IsNotNull (inner.Message, "#9");
1297 [Test] // UploadString (Uri, string)
1298 public void UploadString2_Data_Null ()
1300 WebClient wc = new WebClient ();
1302 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1305 } catch (ArgumentNullException ex) {
1306 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1307 Assert.IsNull (ex.InnerException, "#3");
1308 Assert.IsNotNull (ex.Message, "#4");
1309 Assert.IsNotNull (ex.ParamName, "#5");
1310 Assert.AreEqual ("data", ex.ParamName, "#6");
1314 [Test] // UploadString (string, string, string)
1315 public void UploadString3_Address_Null ()
1317 WebClient wc = new WebClient ();
1319 wc.UploadString ((string) null, (string) null,
1322 } catch (ArgumentNullException ex) {
1323 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1324 Assert.IsNull (ex.InnerException, "#3");
1325 Assert.IsNotNull (ex.Message, "#4");
1326 Assert.IsNotNull (ex.ParamName, "#5");
1327 Assert.AreEqual ("address", ex.ParamName, "#6");
1331 [Test] // UploadString (string, string, string)
1332 public void UploadString3_Address_SchemeNotSupported ()
1334 WebClient wc = new WebClient ();
1336 wc.UploadString ("tp://scheme.notsupported",
1339 } catch (WebException ex) {
1340 // An error occurred performing a WebClient request
1341 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1342 Assert.IsNotNull (ex.InnerException, "#3");
1343 Assert.IsNotNull (ex.Message, "#4");
1344 Assert.IsNull (ex.Response, "#5");
1345 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1347 // The URI prefix is not recognized
1348 Exception inner = ex.InnerException;
1349 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1350 Assert.IsNull (inner.InnerException, "#8");
1351 Assert.IsNotNull (inner.Message, "#9");
1355 [Test] // UploadString (string, string, string)
1356 public void UploadString3_Data_Null ()
1358 WebClient wc = new WebClient ();
1360 wc.UploadString ("tp://scheme.notsupported",
1361 "POST", (string) null);
1363 } catch (ArgumentNullException ex) {
1364 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1365 Assert.IsNull (ex.InnerException, "#3");
1366 Assert.IsNotNull (ex.Message, "#4");
1367 Assert.IsNotNull (ex.ParamName, "#5");
1368 Assert.AreEqual ("data", ex.ParamName, "#6");
1372 [Test] // UploadString (Uri, string, string)
1373 public void UploadString4_Address_Null ()
1375 WebClient wc = new WebClient ();
1377 wc.UploadString ((Uri) null, (string) null,
1380 } catch (ArgumentNullException ex) {
1381 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1382 Assert.IsNull (ex.InnerException, "#3");
1383 Assert.IsNotNull (ex.Message, "#4");
1384 Assert.IsNotNull (ex.ParamName, "#5");
1385 Assert.AreEqual ("address", ex.ParamName, "#6");
1389 [Test] // UploadString (Uri, string, string)
1390 public void UploadString4_Address_SchemeNotSupported ()
1392 WebClient wc = new WebClient ();
1394 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1397 } catch (WebException ex) {
1398 // An error occurred performing a WebClient request
1399 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1400 Assert.IsNotNull (ex.InnerException, "#3");
1401 Assert.IsNotNull (ex.Message, "#4");
1402 Assert.IsNull (ex.Response, "#5");
1403 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1405 // The URI prefix is not recognized
1406 Exception inner = ex.InnerException;
1407 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1408 Assert.IsNull (inner.InnerException, "#8");
1409 Assert.IsNotNull (inner.Message, "#9");
1413 [Test] // UploadString (Uri, string, string)
1414 public void UploadString4_Data_Null ()
1416 WebClient wc = new WebClient ();
1418 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1419 "POST", (string) null);
1421 } catch (ArgumentNullException ex) {
1422 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1423 Assert.IsNull (ex.InnerException, "#3");
1424 Assert.IsNotNull (ex.Message, "#4");
1425 Assert.IsNotNull (ex.ParamName, "#5");
1426 Assert.AreEqual ("data", ex.ParamName, "#6");
1431 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1432 #if FEATURE_NO_BSD_SOCKETS
1433 [ExpectedException (typeof (PlatformNotSupportedException))]
1435 public void UploadValues1 ()
1437 IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
1438 string url = "http://" + ep.ToString () + "/test/";
1440 using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) {
1441 WebClient wc = new WebClient ();
1442 wc.Encoding = Encoding.ASCII;
1444 NameValueCollection nvc = new NameValueCollection ();
1445 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1446 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1448 byte [] buffer = wc.UploadValues (url, nvc);
1449 string response = Encoding.UTF8.GetString (buffer);
1450 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1454 [Test] // UploadValues (string, NameValueCollection)
1455 public void UploadValues1_Address_Null ()
1457 WebClient wc = new WebClient ();
1459 wc.UploadValues ((string) null, new NameValueCollection ());
1461 } catch (ArgumentNullException ex) {
1462 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1463 Assert.IsNull (ex.InnerException, "#3");
1464 Assert.IsNotNull (ex.Message, "#4");
1465 Assert.IsNotNull (ex.ParamName, "#5");
1466 Assert.AreEqual ("address", ex.ParamName, "#6");
1470 [Test] // UploadValues (string, NameValueCollection)
1471 public void UploadValues1_Address_SchemeNotSupported ()
1473 WebClient wc = new WebClient ();
1475 wc.UploadValues ("tp://scheme.notsupported",
1476 new NameValueCollection ());
1478 } catch (WebException ex) {
1479 // An error occurred performing a WebClient request
1480 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1481 Assert.IsNotNull (ex.InnerException, "#3");
1482 Assert.IsNotNull (ex.Message, "#4");
1483 Assert.IsNull (ex.Response, "#5");
1484 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1486 // The URI prefix is not recognized
1487 Exception inner = ex.InnerException;
1488 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1489 Assert.IsNull (inner.InnerException, "#8");
1490 Assert.IsNotNull (inner.Message, "#9");
1494 [Test] // UploadValues (string, NameValueCollection)
1495 public void UploadValues1_Data_Null ()
1497 WebClient wc = new WebClient ();
1499 wc.UploadValues ("http://www.mono-project.com",
1500 (NameValueCollection) null);
1502 } catch (ArgumentNullException ex) {
1503 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1504 Assert.IsNull (ex.InnerException, "#3");
1505 Assert.IsNotNull (ex.Message, "#4");
1506 Assert.IsNotNull (ex.ParamName, "#5");
1507 Assert.AreEqual ("data", ex.ParamName, "#6");
1511 [Test] // UploadValues (Uri, NameValueCollection)
1512 public void UploadValues2_Address_Null ()
1514 WebClient wc = new WebClient ();
1516 wc.UploadValues ((Uri) null, new NameValueCollection ());
1518 } catch (ArgumentNullException ex) {
1519 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1520 Assert.IsNull (ex.InnerException, "#3");
1521 Assert.IsNotNull (ex.Message, "#4");
1522 Assert.IsNotNull (ex.ParamName, "#5");
1523 Assert.AreEqual ("address", ex.ParamName, "#6");
1527 [Test] // UploadValues (Uri, NameValueCollection)
1528 public void UploadValues2_Address_SchemeNotSupported ()
1530 WebClient wc = new WebClient ();
1532 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1533 new NameValueCollection ());
1535 } catch (WebException ex) {
1536 // An error occurred performing a WebClient request
1537 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1538 Assert.IsNotNull (ex.InnerException, "#3");
1539 Assert.IsNotNull (ex.Message, "#4");
1540 Assert.IsNull (ex.Response, "#5");
1541 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1543 // The URI prefix is not recognized
1544 Exception inner = ex.InnerException;
1545 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1546 Assert.IsNull (inner.InnerException, "#8");
1547 Assert.IsNotNull (inner.Message, "#9");
1551 [Test] // UploadValues (Uri, NameValueCollection)
1552 public void UploadValues2_Data_Null ()
1554 WebClient wc = new WebClient ();
1556 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1557 (NameValueCollection) null);
1559 } catch (ArgumentNullException ex) {
1560 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1561 Assert.IsNull (ex.InnerException, "#3");
1562 Assert.IsNotNull (ex.Message, "#4");
1563 Assert.IsNotNull (ex.ParamName, "#5");
1564 Assert.AreEqual ("data", ex.ParamName, "#6");
1568 [Test] // UploadValues (string, string, NameValueCollection)
1569 public void UploadValues3_Address_Null ()
1571 WebClient wc = new WebClient ();
1573 wc.UploadValues ((string) null, "POST",
1574 new NameValueCollection ());
1576 } catch (ArgumentNullException ex) {
1577 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1578 Assert.IsNull (ex.InnerException, "#3");
1579 Assert.IsNotNull (ex.Message, "#4");
1580 Assert.IsNotNull (ex.ParamName, "#5");
1581 Assert.AreEqual ("address", ex.ParamName, "#6");
1585 [Test] // UploadValues (string, string, NameValueCollection)
1586 public void UploadValues3_Address_SchemeNotSupported ()
1588 WebClient wc = new WebClient ();
1590 wc.UploadValues ("tp://scheme.notsupported",
1591 "POST", new NameValueCollection ());
1593 } catch (WebException ex) {
1594 // An error occurred performing a WebClient request
1595 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1596 Assert.IsNotNull (ex.InnerException, "#3");
1597 Assert.IsNotNull (ex.Message, "#4");
1598 Assert.IsNull (ex.Response, "#5");
1599 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1601 // The URI prefix is not recognized
1602 Exception inner = ex.InnerException;
1603 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1604 Assert.IsNull (inner.InnerException, "#8");
1605 Assert.IsNotNull (inner.Message, "#9");
1609 [Test] // UploadValues (string, string, NameValueCollection)
1610 public void UploadValues3_Data_Null ()
1612 WebClient wc = new WebClient ();
1614 wc.UploadValues ("http://www.mono-project.com",
1615 "POST", (NameValueCollection) null);
1617 } catch (ArgumentNullException ex) {
1618 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1619 Assert.IsNull (ex.InnerException, "#3");
1620 Assert.IsNotNull (ex.Message, "#4");
1621 Assert.IsNotNull (ex.ParamName, "#5");
1622 Assert.AreEqual ("data", ex.ParamName, "#6");
1626 [Test] // UploadValues (Uri, string, NameValueCollection)
1627 public void UploadValues4_Address_Null ()
1629 WebClient wc = new WebClient ();
1631 wc.UploadValues ((Uri) null, "POST",
1632 new NameValueCollection ());
1634 } catch (ArgumentNullException ex) {
1635 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1636 Assert.IsNull (ex.InnerException, "#3");
1637 Assert.IsNotNull (ex.Message, "#4");
1638 Assert.IsNotNull (ex.ParamName, "#5");
1639 Assert.AreEqual ("address", ex.ParamName, "#6");
1643 [Test] // UploadValues (Uri, string, NameValueCollection)
1644 public void UploadValues4_Address_SchemeNotSupported ()
1646 WebClient wc = new WebClient ();
1648 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1649 "POST", new NameValueCollection ());
1651 } catch (WebException ex) {
1652 // An error occurred performing a WebClient request
1653 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1654 Assert.IsNotNull (ex.InnerException, "#3");
1655 Assert.IsNotNull (ex.Message, "#4");
1656 Assert.IsNull (ex.Response, "#5");
1657 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1659 // The URI prefix is not recognized
1660 Exception inner = ex.InnerException;
1661 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1662 Assert.IsNull (inner.InnerException, "#8");
1663 Assert.IsNotNull (inner.Message, "#9");
1667 [Test] // UploadValues (Uri, string, NameValueCollection)
1668 public void UploadValues4_Data_Null ()
1670 WebClient wc = new WebClient ();
1672 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1673 "POST", (NameValueCollection) null);
1675 } catch (ArgumentNullException ex) {
1676 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1677 Assert.IsNull (ex.InnerException, "#3");
1678 Assert.IsNotNull (ex.Message, "#4");
1679 Assert.IsNotNull (ex.ParamName, "#5");
1680 Assert.AreEqual ("data", ex.ParamName, "#6");
1685 #if FEATURE_NO_BSD_SOCKETS
1686 // We throw a PlatformNotSupportedException deeper, which is caught and re-thrown as WebException
1687 [ExpectedException (typeof (WebException))]
1689 public void GetWebRequestOverriding ()
1691 GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1692 testObject.DownloadData ("http://www.mono-project.com");
1694 Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1697 class GetWebRequestOverridingTestClass : WebClient
1699 internal bool overridedCodeRan = false;
1700 protected override WebRequest GetWebRequest(Uri address)
1702 overridedCodeRan = true;
1703 return base.GetWebRequest (address);
1707 static byte [] EchoRequestHandler (Socket socket)
1709 MemoryStream ms = new MemoryStream ();
1710 byte [] buffer = new byte [4096];
1711 int bytesReceived = socket.Receive (buffer);
1712 while (bytesReceived > 0) {
1713 ms.Write (buffer, 0, bytesReceived);
1714 // We don't check for Content-Length or anything else here, so we give the client a little time to write
1715 // after sending the headers
1717 if (socket.Available > 0) {
1718 bytesReceived = socket.Receive (buffer);
1726 StringBuilder sb = new StringBuilder ();
1728 string expect = null;
1730 StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1733 while ((line = sr.ReadLine ()) != null) {
1738 } if (line.Length == 0) {
1740 } else if (line.StartsWith ("Expect:")) {
1741 expect = line.Substring (8);
1745 StringWriter sw = new StringWriter ();
1747 if (expect == "100-continue" && state != 2) {
1748 sw.WriteLine ("HTTP/1.1 100 Continue");
1752 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1755 ms = new MemoryStream ();
1756 buffer = new byte [4096];
1757 bytesReceived = socket.Receive (buffer);
1758 while (bytesReceived > 0) {
1759 ms.Write (buffer, 0, bytesReceived);
1761 if (socket.Available > 0) {
1762 bytesReceived = socket.Receive (buffer);
1770 sb = new StringBuilder ();
1771 sr = new StreamReader (ms, Encoding.UTF8);
1772 line = sr.ReadLine ();
1773 while (line != null) {
1776 line = sr.ReadLine ();
1780 sw = new StringWriter ();
1781 sw.WriteLine ("HTTP/1.1 200 OK");
1782 sw.WriteLine ("Content-Type: text/xml");
1783 sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1785 sw.Write (sb.ToString ());
1788 return Encoding.UTF8.GetBytes (sw.ToString ());
1792 #if FEATURE_NO_BSD_SOCKETS
1793 [ExpectedException (typeof (PlatformNotSupportedException))]
1795 public void DefaultProxy ()
1797 WebClient wc = new WebClient ();
1798 // this is never null on .net
1799 Assert.IsNotNull (wc.Proxy);
1800 // and return the same instance as WebRequest.DefaultWebProxy
1801 Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1805 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1806 #if FEATURE_NO_BSD_SOCKETS
1807 [ExpectedException (typeof (PlatformNotSupportedException))]
1809 public void UploadStringAsyncCancelEvent ()
1811 UploadAsyncCancelEventTest (9301, (webClient, uri, cancelEvent) =>
1814 webClient.UploadStringCompleted += (sender, args) =>
1820 webClient.UploadStringAsync (uri, "PUT", "text");
1825 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1826 #if FEATURE_NO_BSD_SOCKETS
1827 [ExpectedException (typeof (PlatformNotSupportedException))]
1829 public void UploadDataAsyncCancelEvent ()
1831 UploadAsyncCancelEventTest (9302, (webClient, uri, cancelEvent) =>
1833 webClient.UploadDataCompleted += (sender, args) =>
1839 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1844 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1845 #if FEATURE_NO_BSD_SOCKETS
1846 [ExpectedException (typeof (PlatformNotSupportedException))]
1848 public void UploadValuesAsyncCancelEvent ()
1850 UploadAsyncCancelEventTest (9303, (webClient, uri, cancelEvent) =>
1852 webClient.UploadValuesCompleted += (sender, args) =>
1858 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1863 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1864 #if FEATURE_NO_BSD_SOCKETS
1865 [ExpectedException (typeof (PlatformNotSupportedException))]
1867 public void UploadFileAsyncCancelEvent ()
1869 UploadAsyncCancelEventTest (9304,(webClient, uri, cancelEvent) =>
1871 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1872 File.Create (tempFile).Close ();
1874 webClient.UploadFileCompleted += (sender, args) =>
1880 webClient.UploadFileAsync (uri, "PUT", tempFile);
1885 [Category ("AndroidNotWorking")] // Test suite hangs if the tests runs as part of the entire BCL suite. Works when only this fixture is ran
1886 #if FEATURE_NO_BSD_SOCKETS
1887 [ExpectedException (typeof (PlatformNotSupportedException))]
1889 public void UploadFileAsyncContentType ()
1891 var port = NetworkHelpers.FindFreePort ();
1892 var serverUri = "http://localhost:" + port + "/";
1893 var filename = Path.GetTempFileName ();
1895 HttpListener listener = new HttpListener ();
1896 listener.Prefixes.Add (serverUri);
1899 using (var client = new WebClient ())
1901 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1902 var request = listener.GetContext ().Request;
1904 var expected = "multipart/form-data; boundary=---------------------";
1905 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1906 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1911 public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
1913 var ep = NetworkHelpers.LocalEphemeralEndPoint ();
1914 string url = "http://" + ep.ToString() + "/test/";
1916 using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s)))
1918 var webClient = new WebClient ();
1920 var cancellationTokenSource = new CancellationTokenSource ();
1921 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1923 var cancelEvent = new ManualResetEvent (false);
1925 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1927 cancellationTokenSource.Cancel ();
1929 Assert.IsTrue (cancelEvent.WaitOne (1000));