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 namespace MonoTests.System.Net
22 public class WebClientTest
24 private string _tempFolder;
29 _tempFolder = Path.Combine (Path.GetTempPath (),
31 if (Directory.Exists (_tempFolder))
32 Directory.Delete (_tempFolder, true);
33 Directory.CreateDirectory (_tempFolder);
37 public void TearDown ()
39 if (Directory.Exists (_tempFolder))
40 Directory.Delete (_tempFolder, true);
44 [Category ("InetAccess")]
45 public void DownloadTwice ()
47 WebClient wc = new WebClient();
48 string filename = Path.GetTempFileName();
50 // A new, but empty file has been created. This is a test case
52 wc.DownloadFile("http://google.com/", filename);
54 // Now, remove the file and attempt to download again.
55 File.Delete(filename);
56 wc.DownloadFile("http://google.com/", filename);
60 public void DownloadData1_Address_Null ()
62 WebClient wc = new WebClient ();
64 wc.DownloadData ((string) null);
66 } catch (ArgumentNullException ex) {
67 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
68 Assert.IsNull (ex.InnerException, "#3");
69 Assert.IsNotNull (ex.Message, "#4");
70 Assert.IsNotNull (ex.ParamName, "#5");
71 Assert.AreEqual ("address", ex.ParamName, "#6");
75 [Test] // DownloadData (string)
76 public void DownloadData1_Address_SchemeNotSupported ()
78 WebClient wc = new WebClient ();
80 wc.DownloadData ("tp://scheme.notsupported");
82 } catch (WebException ex) {
83 // An error occurred performing a WebClient request
84 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
85 Assert.IsNotNull (ex.InnerException, "#3");
86 Assert.IsNotNull (ex.Message, "#4");
87 Assert.IsNull (ex.Response, "#5");
88 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
90 // The URI prefix is not recognized
91 Exception inner = ex.InnerException;
92 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
93 Assert.IsNull (inner.InnerException, "#8");
94 Assert.IsNotNull (inner.Message, "#9");
98 [Test] // DownloadData (Uri)
99 public void DownloadData2_Address_Null ()
101 WebClient wc = new WebClient ();
103 wc.DownloadData ((Uri) null);
105 } catch (ArgumentNullException ex) {
106 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
107 Assert.IsNull (ex.InnerException, "#3");
108 Assert.IsNotNull (ex.Message, "#4");
109 Assert.IsNotNull (ex.ParamName, "#5");
110 Assert.AreEqual ("address", ex.ParamName, "#6");
114 [Test] // DownloadData (Uri)
115 public void DownloadData2_Address_SchemeNotSupported ()
117 WebClient wc = new WebClient ();
119 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
121 } catch (WebException ex) {
122 // An error occurred performing a WebClient request
123 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
124 Assert.IsNotNull (ex.InnerException, "#3");
125 Assert.IsNotNull (ex.Message, "#4");
126 Assert.IsNull (ex.Response, "#5");
127 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
129 // The URI prefix is not recognized
130 Exception inner = ex.InnerException;
131 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
132 Assert.IsNull (inner.InnerException, "#8");
133 Assert.IsNotNull (inner.Message, "#9");
138 public void DownloadFile1_Address_Null ()
140 WebClient wc = new WebClient ();
142 wc.DownloadFile ((string) null, "tmp.out");
144 } catch (ArgumentNullException ex) {
145 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
146 Assert.IsNull (ex.InnerException, "#3");
147 Assert.IsNotNull (ex.Message, "#4");
148 Assert.IsNotNull (ex.ParamName, "#5");
149 Assert.AreEqual ("address", ex.ParamName, "#6");
153 [Test] // DownloadFile (string, string)
154 public void DownloadFile1_Address_SchemeNotSupported ()
156 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
157 WebClient wc = new WebClient ();
159 wc.DownloadFile ("tp://scheme.notsupported", file);
161 } catch (WebException ex) {
162 // An error occurred performing a WebClient request
163 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
164 Assert.IsNotNull (ex.InnerException, "#3");
165 Assert.IsNotNull (ex.Message, "#4");
166 Assert.IsNull (ex.Response, "#5");
167 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
169 // The URI prefix is not recognized
170 Exception inner = ex.InnerException;
171 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
172 Assert.IsNull (inner.InnerException, "#8");
173 Assert.IsNotNull (inner.Message, "#9");
176 if (File.Exists (file))
181 [Test] // DownloadFile (string, string)
182 public void DownloadFile1_FileName_Null ()
184 WebClient wc = new WebClient ();
186 wc.DownloadFile ("tp://scheme.notsupported",
189 } catch (ArgumentNullException ex) {
190 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
191 Assert.IsNull (ex.InnerException, "#3");
192 Assert.IsNotNull (ex.Message, "#4");
193 Assert.IsNotNull (ex.ParamName, "#5");
194 Assert.AreEqual ("fileName", ex.ParamName, "#6");
198 [Test] // DownloadFile (Uri, string)
199 public void DownloadFile2_Address_Null ()
201 WebClient wc = new WebClient ();
203 wc.DownloadFile ((Uri) null, "tmp.out");
205 } catch (ArgumentNullException ex) {
206 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
207 Assert.IsNull (ex.InnerException, "#3");
208 Assert.IsNotNull (ex.Message, "#4");
209 Assert.IsNotNull (ex.ParamName, "#5");
210 Assert.AreEqual ("address", ex.ParamName, "#6");
214 [Test] // DownloadFile (Uri, string)
215 public void DownloadFile2_Address_SchemeNotSupported ()
217 string file = Path.Combine (Path.GetTempPath (), "tmp.out");
218 WebClient wc = new WebClient ();
220 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
222 } catch (WebException ex) {
223 // An error occurred performing a WebClient request
224 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
225 Assert.IsNotNull (ex.InnerException, "#3");
226 Assert.IsNotNull (ex.Message, "#4");
227 Assert.IsNull (ex.Response, "#5");
228 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
230 // The URI prefix is not recognized
231 Exception inner = ex.InnerException;
232 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
233 Assert.IsNull (inner.InnerException, "#8");
234 Assert.IsNotNull (inner.Message, "#9");
237 if (File.Exists (file))
242 [Test] // DownloadFile (Uri, string)
243 public void DownloadFile2_FileName_Null ()
245 WebClient wc = new WebClient ();
247 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
250 } catch (ArgumentNullException ex) {
251 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
252 Assert.IsNull (ex.InnerException, "#3");
253 Assert.IsNotNull (ex.Message, "#4");
254 Assert.IsNotNull (ex.ParamName, "#5");
255 Assert.AreEqual ("fileName", ex.ParamName, "#6");
259 [Test] // DownloadString (string)
260 public void DownloadString1_Address_Null ()
262 WebClient wc = new WebClient ();
264 wc.DownloadString ((string) null);
266 } catch (ArgumentNullException ex) {
267 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
268 Assert.IsNull (ex.InnerException, "#3");
269 Assert.IsNotNull (ex.Message, "#4");
270 Assert.IsNotNull (ex.ParamName, "#5");
271 Assert.AreEqual ("address", ex.ParamName, "#6");
275 [Test] // DownloadString (string)
276 public void DownloadString1_Address_SchemeNotSupported ()
278 WebClient wc = new WebClient ();
280 wc.DownloadString ("tp://scheme.notsupported");
282 } catch (WebException ex) {
283 // An error occurred performing a WebClient request
284 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
285 Assert.IsNotNull (ex.InnerException, "#3");
286 Assert.IsNotNull (ex.Message, "#4");
287 Assert.IsNull (ex.Response, "#5");
288 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
290 // The URI prefix is not recognized
291 Exception inner = ex.InnerException;
292 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
293 Assert.IsNull (inner.InnerException, "#8");
294 Assert.IsNotNull (inner.Message, "#9");
298 [Test] // DownloadString (Uri)
299 public void DownloadString2_Address_Null ()
301 WebClient wc = new WebClient ();
303 wc.DownloadString ((Uri) null);
305 } catch (ArgumentNullException ex) {
306 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
307 Assert.IsNull (ex.InnerException, "#3");
308 Assert.IsNotNull (ex.Message, "#4");
309 Assert.IsNotNull (ex.ParamName, "#5");
310 Assert.AreEqual ("address", ex.ParamName, "#6");
314 [Test] // DownloadString (Uri)
315 public void DownloadString2_Address_SchemeNotSupported ()
317 WebClient wc = new WebClient ();
319 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
321 } catch (WebException ex) {
322 // An error occurred performing a WebClient request
323 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
324 Assert.IsNotNull (ex.InnerException, "#3");
325 Assert.IsNotNull (ex.Message, "#4");
326 Assert.IsNull (ex.Response, "#5");
327 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
329 // The URI prefix is not recognized
330 Exception inner = ex.InnerException;
331 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
332 Assert.IsNull (inner.InnerException, "#8");
333 Assert.IsNotNull (inner.Message, "#9");
338 public void EncodingTest ()
340 WebClient wc = new WebClient ();
341 Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
342 wc.Encoding = Encoding.ASCII;
343 Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
347 public void Encoding_Value_Null ()
349 WebClient wc = new WebClient ();
353 } catch (ArgumentNullException ex) {
354 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
355 Assert.IsNull (ex.InnerException, "#3");
356 Assert.IsNotNull (ex.Message, "#4");
357 Assert.AreEqual ("Encoding", ex.ParamName, "#6");
361 [Test] // OpenRead (string)
362 public void OpenRead1_Address_Null ()
364 WebClient wc = new WebClient ();
366 wc.OpenRead ((string) null);
368 } catch (ArgumentNullException ex) {
369 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
370 Assert.IsNull (ex.InnerException, "#3");
371 Assert.IsNotNull (ex.Message, "#4");
372 Assert.IsNotNull (ex.ParamName, "#5");
373 Assert.AreEqual ("address", ex.ParamName, "#6");
377 [Test] // OpenRead (string)
378 public void OpenRead1_Address_SchemeNotSupported ()
380 WebClient wc = new WebClient ();
382 wc.OpenRead ("tp://scheme.notsupported");
384 } catch (WebException ex) {
385 // An error occurred performing a WebClient request
386 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
387 Assert.IsNotNull (ex.InnerException, "#3");
388 Assert.IsNotNull (ex.Message, "#4");
389 Assert.IsNull (ex.Response, "#5");
390 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
392 // The URI prefix is not recognized
393 Exception inner = ex.InnerException;
394 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
395 Assert.IsNull (inner.InnerException, "#8");
396 Assert.IsNotNull (inner.Message, "#9");
400 [Test] // OpenRead (Uri)
401 public void OpenRead2_Address_Null ()
403 WebClient wc = new WebClient ();
405 wc.OpenRead ((Uri) null);
407 } catch (ArgumentNullException ex) {
408 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
409 Assert.IsNull (ex.InnerException, "#3");
410 Assert.IsNotNull (ex.Message, "#4");
411 Assert.IsNotNull (ex.ParamName, "#5");
412 Assert.AreEqual ("address", ex.ParamName, "#6");
416 [Test] // OpenRead (Uri)
417 public void OpenRead2_Address_SchemeNotSupported ()
419 WebClient wc = new WebClient ();
421 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
423 } catch (WebException ex) {
424 // An error occurred performing a WebClient request
425 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
426 Assert.IsNotNull (ex.InnerException, "#3");
427 Assert.IsNotNull (ex.Message, "#4");
428 Assert.IsNull (ex.Response, "#5");
429 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
431 // The URI prefix is not recognized
432 Exception inner = ex.InnerException;
433 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
434 Assert.IsNull (inner.InnerException, "#8");
435 Assert.IsNotNull (inner.Message, "#9");
439 [Test] // OpenWrite (string)
440 public void OpenWrite1_Address_Null ()
442 WebClient wc = new WebClient ();
444 wc.OpenWrite ((string) null);
446 } catch (ArgumentNullException ex) {
447 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
448 Assert.IsNull (ex.InnerException, "#3");
449 Assert.IsNotNull (ex.Message, "#4");
450 Assert.IsNotNull (ex.ParamName, "#5");
451 Assert.AreEqual ("address", ex.ParamName, "#6");
455 [Test] // OpenWrite (string)
456 public void OpenWrite1_Address_SchemeNotSupported ()
458 WebClient wc = new WebClient ();
460 wc.OpenWrite ("tp://scheme.notsupported");
462 } catch (WebException ex) {
463 // An error occurred performing a WebClient request
464 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
465 Assert.IsNotNull (ex.InnerException, "#3");
466 Assert.IsNotNull (ex.Message, "#4");
467 Assert.IsNull (ex.Response, "#5");
468 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
470 // The URI prefix is not recognized
471 Exception inner = ex.InnerException;
472 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
473 Assert.IsNull (inner.InnerException, "#8");
474 Assert.IsNotNull (inner.Message, "#9");
478 [Test] // OpenWrite (string, string)
479 public void OpenWrite2_Address_Null ()
481 WebClient wc = new WebClient ();
483 wc.OpenWrite ((string) null, "PUT");
485 } catch (ArgumentNullException ex) {
486 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
487 Assert.IsNull (ex.InnerException, "#3");
488 Assert.IsNotNull (ex.Message, "#4");
489 Assert.IsNotNull (ex.ParamName, "#5");
490 Assert.AreEqual ("address", ex.ParamName, "#6");
494 [Test] // OpenWrite (string, string)
495 public void OpenWrite2_Address_SchemeNotSupported ()
497 WebClient wc = new WebClient ();
499 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
501 } catch (WebException ex) {
502 // An error occurred performing a WebClient request
503 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
504 Assert.IsNotNull (ex.InnerException, "#3");
505 Assert.IsNotNull (ex.Message, "#4");
506 Assert.IsNull (ex.Response, "#5");
507 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
509 // The URI prefix is not recognized
510 Exception inner = ex.InnerException;
511 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
512 Assert.IsNull (inner.InnerException, "#8");
513 Assert.IsNotNull (inner.Message, "#9");
517 [Test] // OpenWrite (Uri)
518 public void OpenWrite3_Address_Null ()
520 WebClient wc = new WebClient ();
522 wc.OpenWrite ((Uri) null);
524 } catch (ArgumentNullException ex) {
525 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
526 Assert.IsNull (ex.InnerException, "#3");
527 Assert.IsNotNull (ex.Message, "#4");
528 Assert.IsNotNull (ex.ParamName, "#5");
529 Assert.AreEqual ("address", ex.ParamName, "#6");
533 [Test] // OpenWrite (Uri)
534 public void OpenWrite3_Address_SchemeNotSupported ()
536 WebClient wc = new WebClient ();
538 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
540 } catch (WebException ex) {
541 // An error occurred performing a WebClient request
542 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
543 Assert.IsNotNull (ex.InnerException, "#3");
544 Assert.IsNotNull (ex.Message, "#4");
545 Assert.IsNull (ex.Response, "#5");
546 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
548 // The URI prefix is not recognized
549 Exception inner = ex.InnerException;
550 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
551 Assert.IsNull (inner.InnerException, "#8");
552 Assert.IsNotNull (inner.Message, "#9");
556 [Test] // OpenWrite (Uri, string)
557 public void OpenWrite4_Address_Null ()
559 WebClient wc = new WebClient ();
561 wc.OpenWrite ((Uri) null, "POST");
563 } catch (ArgumentNullException ex) {
564 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
565 Assert.IsNull (ex.InnerException, "#3");
566 Assert.IsNotNull (ex.Message, "#4");
567 Assert.IsNotNull (ex.ParamName, "#5");
568 Assert.AreEqual ("address", ex.ParamName, "#6");
572 [Test] // OpenWrite (Uri, string)
573 public void OpenWrite4_Address_SchemeNotSupported ()
575 WebClient wc = new WebClient ();
577 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
580 } catch (WebException ex) {
581 // An error occurred performing a WebClient request
582 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
583 Assert.IsNotNull (ex.InnerException, "#3");
584 Assert.IsNotNull (ex.Message, "#4");
585 Assert.IsNull (ex.Response, "#5");
586 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
588 // The URI prefix is not recognized
589 Exception inner = ex.InnerException;
590 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
591 Assert.IsNull (inner.InnerException, "#8");
592 Assert.IsNotNull (inner.Message, "#9");
596 [Test] // UploadData (string, byte [])
597 public void UploadData1_Address_Null ()
599 WebClient wc = new WebClient ();
601 wc.UploadData ((string) null, new byte [] { 0x1a });
603 } catch (ArgumentNullException ex) {
604 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
605 Assert.IsNull (ex.InnerException, "#3");
606 Assert.IsNotNull (ex.Message, "#4");
607 Assert.IsNotNull (ex.ParamName, "#5");
608 Assert.AreEqual ("address", ex.ParamName, "#6");
612 [Test] // UploadData (string, byte [])
613 public void UploadData1_Address_SchemeNotSupported ()
615 WebClient wc = new WebClient ();
617 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
619 } catch (WebException ex) {
620 // An error occurred performing a WebClient request
621 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
622 Assert.IsNotNull (ex.InnerException, "#3");
623 Assert.IsNotNull (ex.Message, "#4");
624 Assert.IsNull (ex.Response, "#5");
625 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
627 // The URI prefix is not recognized
628 Exception inner = ex.InnerException;
629 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
630 Assert.IsNull (inner.InnerException, "#8");
631 Assert.IsNotNull (inner.Message, "#9");
635 [Test] // UploadData (string, byte [])
636 public void UploadData1_Data_Null ()
638 WebClient wc = new WebClient ();
640 wc.UploadData ("http://www.mono-project.com",
643 } catch (ArgumentNullException ex) {
644 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
645 Assert.IsNull (ex.InnerException, "#3");
646 Assert.IsNotNull (ex.Message, "#4");
647 Assert.IsNotNull (ex.ParamName, "#5");
648 Assert.AreEqual ("data", ex.ParamName, "#6");
652 [Test] // UploadData (Uri, byte [])
653 public void UploadData2_Address_Null ()
655 WebClient wc = new WebClient ();
657 wc.UploadData ((Uri) null, new byte [] { 0x1a });
659 } catch (ArgumentNullException ex) {
660 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
661 Assert.IsNull (ex.InnerException, "#3");
662 Assert.IsNotNull (ex.Message, "#4");
663 Assert.IsNotNull (ex.ParamName, "#5");
664 Assert.AreEqual ("address", ex.ParamName, "#6");
668 [Test] // UploadData (Uri, byte [])
669 public void UploadData2_Address_SchemeNotSupported ()
671 WebClient wc = new WebClient ();
673 wc.UploadData (new Uri ("tp://scheme.notsupported"),
674 new byte [] { 0x1a });
676 } catch (WebException ex) {
677 // An error occurred performing a WebClient request
678 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
679 Assert.IsNotNull (ex.InnerException, "#3");
680 Assert.IsNotNull (ex.Message, "#4");
681 Assert.IsNull (ex.Response, "#5");
682 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
684 // The URI prefix is not recognized
685 Exception inner = ex.InnerException;
686 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
687 Assert.IsNull (inner.InnerException, "#8");
688 Assert.IsNotNull (inner.Message, "#9");
692 [Test] // UploadData (Uri, byte [])
693 public void UploadData2_Data_Null ()
695 WebClient wc = new WebClient ();
697 wc.UploadData (new Uri ("http://www.mono-project.com"),
700 } catch (ArgumentNullException ex) {
701 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
702 Assert.IsNull (ex.InnerException, "#3");
703 Assert.IsNotNull (ex.Message, "#4");
704 Assert.IsNotNull (ex.ParamName, "#5");
705 Assert.AreEqual ("data", ex.ParamName, "#6");
709 [Test] // UploadData (string, string, byte [])
710 public void UploadData3_Address_Null ()
712 WebClient wc = new WebClient ();
714 wc.UploadData ((string) null, "POST",
715 new byte [] { 0x1a });
717 } catch (ArgumentNullException ex) {
718 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
719 Assert.IsNull (ex.InnerException, "#3");
720 Assert.IsNotNull (ex.Message, "#4");
721 Assert.IsNotNull (ex.ParamName, "#5");
722 Assert.AreEqual ("address", ex.ParamName, "#6");
726 [Test] // UploadData (string, string, byte [])
727 public void UploadData3_Address_SchemeNotSupported ()
729 WebClient wc = new WebClient ();
731 wc.UploadData ("tp://scheme.notsupported",
732 "POST", new byte [] { 0x1a });
734 } catch (WebException ex) {
735 // An error occurred performing a WebClient request
736 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
737 Assert.IsNotNull (ex.InnerException, "#3");
738 Assert.IsNotNull (ex.Message, "#4");
739 Assert.IsNull (ex.Response, "#5");
740 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
742 // The URI prefix is not recognized
743 Exception inner = ex.InnerException;
744 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
745 Assert.IsNull (inner.InnerException, "#8");
746 Assert.IsNotNull (inner.Message, "#9");
750 [Test] // UploadData (string, string, byte [])
751 public void UploadData3_Data_Null ()
753 WebClient wc = new WebClient ();
755 wc.UploadData ("http://www.mono-project.com",
756 "POST", (byte []) null);
758 } catch (ArgumentNullException ex) {
759 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
760 Assert.IsNull (ex.InnerException, "#3");
761 Assert.IsNotNull (ex.Message, "#4");
762 Assert.IsNotNull (ex.ParamName, "#5");
763 Assert.AreEqual ("data", ex.ParamName, "#6");
767 [Test] // UploadData (Uri, string, byte [])
768 public void UploadData4_Address_Null ()
770 WebClient wc = new WebClient ();
772 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
774 } catch (ArgumentNullException ex) {
775 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
776 Assert.IsNull (ex.InnerException, "#3");
777 Assert.IsNotNull (ex.Message, "#4");
778 Assert.IsNotNull (ex.ParamName, "#5");
779 Assert.AreEqual ("address", ex.ParamName, "#6");
783 [Test] // UploadData (Uri, string, byte [])
784 public void UploadData4_Address_SchemeNotSupported ()
786 WebClient wc = new WebClient ();
788 wc.UploadData (new Uri ("tp://scheme.notsupported"),
789 "POST", new byte [] { 0x1a });
791 } catch (WebException ex) {
792 // An error occurred performing a WebClient request
793 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
794 Assert.IsNotNull (ex.InnerException, "#3");
795 Assert.IsNotNull (ex.Message, "#4");
796 Assert.IsNull (ex.Response, "#5");
797 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
799 // The URI prefix is not recognized
800 Exception inner = ex.InnerException;
801 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
802 Assert.IsNull (inner.InnerException, "#8");
803 Assert.IsNotNull (inner.Message, "#9");
807 [Test] // UploadData (Uri, string, byte [])
808 public void UploadData4_Data_Null ()
810 WebClient wc = new WebClient ();
812 wc.UploadData (new Uri ("http://www.mono-project.com"),
813 "POST", (byte []) null);
815 } catch (ArgumentNullException ex) {
816 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
817 Assert.IsNull (ex.InnerException, "#3");
818 Assert.IsNotNull (ex.Message, "#4");
819 Assert.IsNotNull (ex.ParamName, "#5");
820 Assert.AreEqual ("data", ex.ParamName, "#6");
824 [Test] // UploadFile (string, string)
825 public void UploadFile1_Address_Null ()
827 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
828 File.Create (tempFile).Close ();
830 WebClient wc = new WebClient ();
832 wc.UploadFile ((string) null, tempFile);
834 } catch (ArgumentNullException ex) {
835 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
836 Assert.IsNull (ex.InnerException, "#3");
837 Assert.IsNotNull (ex.Message, "#4");
838 Assert.IsNotNull (ex.ParamName, "#5");
839 Assert.AreEqual ("address", ex.ParamName, "#6");
843 [Test] // UploadFile (string, string)
844 public void UploadFile1_Address_SchemeNotSupported ()
846 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
847 File.Create (tempFile).Close ();
849 WebClient wc = new WebClient ();
851 wc.UploadFile ("tp://scheme.notsupported",
854 } catch (WebException ex) {
855 // An error occurred performing a WebClient request
856 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
857 Assert.IsNotNull (ex.InnerException, "#3");
858 Assert.IsNotNull (ex.Message, "#4");
859 Assert.IsNull (ex.Response, "#5");
860 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
862 // The URI prefix is not recognized
863 Exception inner = ex.InnerException;
864 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
865 Assert.IsNull (inner.InnerException, "#8");
866 Assert.IsNotNull (inner.Message, "#9");
870 [Test] // UploadFile (string, string)
871 public void UploadFile1_FileName_NotFound ()
873 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
875 WebClient wc = new WebClient ();
877 wc.UploadFile ("tp://scheme.notsupported",
880 } catch (WebException ex) {
881 // An error occurred performing a WebClient request
882 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
883 Assert.IsNotNull (ex.Message, "#3");
884 Assert.IsNull (ex.Response, "#4");
885 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
887 // Could not find file "..."
888 FileNotFoundException inner = ex.InnerException
889 as FileNotFoundException;
890 Assert.IsNotNull (inner, "#6");
891 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
892 Assert.IsNotNull (inner.FileName, "#8");
893 Assert.AreEqual (tempFile, inner.FileName, "#9");
894 Assert.IsNull (inner.InnerException, "#10");
895 Assert.IsNotNull (inner.Message, "#11");
899 [Test] // UploadFile (string, string)
900 public void UploadFile1_FileName_Null ()
902 WebClient wc = new WebClient ();
904 wc.UploadFile ("tp://scheme.notsupported",
907 } catch (ArgumentNullException ex) {
908 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
909 Assert.IsNull (ex.InnerException, "#3");
910 Assert.IsNotNull (ex.Message, "#4");
911 Assert.IsNotNull (ex.ParamName, "#5");
912 Assert.AreEqual ("fileName", ex.ParamName, "#6");
916 [Test] // UploadFile (Uri, string)
917 public void UploadFile2_Address_Null ()
919 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
921 WebClient wc = new WebClient ();
923 wc.UploadFile ((Uri) null, tempFile);
925 } catch (ArgumentNullException ex) {
926 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
927 Assert.IsNull (ex.InnerException, "#3");
928 Assert.IsNotNull (ex.Message, "#4");
929 Assert.IsNotNull (ex.ParamName, "#5");
930 Assert.AreEqual ("address", ex.ParamName, "#6");
934 [Test] // UploadFile (Uri, string)
935 public void UploadFile2_Address_SchemeNotSupported ()
937 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
938 File.Create (tempFile).Close ();
940 WebClient wc = new WebClient ();
942 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
945 } catch (WebException ex) {
946 // An error occurred performing a WebClient request
947 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
948 Assert.IsNotNull (ex.InnerException, "#3");
949 Assert.IsNotNull (ex.Message, "#4");
950 Assert.IsNull (ex.Response, "#5");
951 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
953 // The URI prefix is not recognized
954 Exception inner = ex.InnerException;
955 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
956 Assert.IsNull (inner.InnerException, "#8");
957 Assert.IsNotNull (inner.Message, "#9");
961 [Test] // UploadFile (Uri, string)
962 public void UploadFile2_FileName_NotFound ()
964 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
966 WebClient wc = new WebClient ();
968 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
971 } catch (WebException ex) {
972 // An error occurred performing a WebClient request
973 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
974 Assert.IsNotNull (ex.Message, "#3");
975 Assert.IsNull (ex.Response, "#4");
976 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
978 // Could not find file "..."
979 FileNotFoundException inner = ex.InnerException
980 as FileNotFoundException;
981 Assert.IsNotNull (inner, "#6");
982 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
983 Assert.IsNotNull (inner.FileName, "#8");
984 Assert.AreEqual (tempFile, inner.FileName, "#9");
985 Assert.IsNull (inner.InnerException, "#10");
986 Assert.IsNotNull (inner.Message, "#11");
990 [Test] // UploadFile (Uri, string)
991 public void UploadFile2_FileName_Null ()
993 WebClient wc = new WebClient ();
995 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
998 } catch (ArgumentNullException ex) {
999 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1000 Assert.IsNull (ex.InnerException, "#3");
1001 Assert.IsNotNull (ex.Message, "#4");
1002 Assert.IsNotNull (ex.ParamName, "#5");
1003 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1007 [Test] // UploadFile (string, string, string)
1008 public void UploadFile3_Address_Null ()
1010 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1011 File.Create (tempFile).Close ();
1013 WebClient wc = new WebClient ();
1015 wc.UploadFile ((string) null, "POST", tempFile);
1017 } catch (ArgumentNullException ex) {
1018 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1019 Assert.IsNull (ex.InnerException, "#3");
1020 Assert.IsNotNull (ex.Message, "#4");
1021 Assert.IsNotNull (ex.ParamName, "#5");
1022 Assert.AreEqual ("path", ex.ParamName, "#6");
1026 [Test] // UploadFile (string, string, string)
1027 public void UploadFile3_Address_SchemeNotSupported ()
1029 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1030 File.Create (tempFile).Close ();
1032 WebClient wc = new WebClient ();
1034 wc.UploadFile ("tp://scheme.notsupported",
1037 } catch (WebException ex) {
1038 // An error occurred performing a WebClient request
1039 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1040 Assert.IsNotNull (ex.InnerException, "#3");
1041 Assert.IsNotNull (ex.Message, "#4");
1042 Assert.IsNull (ex.Response, "#5");
1043 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1045 // The URI prefix is not recognized
1046 Exception inner = ex.InnerException;
1047 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1048 Assert.IsNull (inner.InnerException, "#8");
1049 Assert.IsNotNull (inner.Message, "#9");
1053 [Test] // UploadFile (string, string, string)
1054 public void UploadFile3_FileName_NotFound ()
1056 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1058 WebClient wc = new WebClient ();
1060 wc.UploadFile ("tp://scheme.notsupported",
1063 } catch (WebException ex) {
1064 // An error occurred performing a WebClient request
1065 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1066 Assert.IsNotNull (ex.Message, "#3");
1067 Assert.IsNull (ex.Response, "#4");
1068 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1070 // Could not find file "..."
1071 FileNotFoundException inner = ex.InnerException
1072 as FileNotFoundException;
1073 Assert.IsNotNull (inner, "#6");
1074 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1075 Assert.IsNotNull (inner.FileName, "#8");
1076 Assert.AreEqual (tempFile, inner.FileName, "#9");
1077 Assert.IsNull (inner.InnerException, "#10");
1078 Assert.IsNotNull (inner.Message, "#11");
1082 [Test] // UploadFile (string, string, string)
1083 public void UploadFile3_FileName_Null ()
1085 WebClient wc = new WebClient ();
1087 wc.UploadFile ("tp://scheme.notsupported",
1088 "POST", (string) null);
1090 } catch (ArgumentNullException ex) {
1091 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1092 Assert.IsNull (ex.InnerException, "#3");
1093 Assert.IsNotNull (ex.Message, "#4");
1094 Assert.IsNotNull (ex.ParamName, "#5");
1095 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1099 [Test] // UploadFile (Uri, string, string)
1100 public void UploadFile4_Address_Null ()
1102 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1104 WebClient wc = new WebClient ();
1106 wc.UploadFile ((Uri) null, "POST", tempFile);
1108 } catch (ArgumentNullException ex) {
1109 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1110 Assert.IsNull (ex.InnerException, "#3");
1111 Assert.IsNotNull (ex.Message, "#4");
1112 Assert.IsNotNull (ex.ParamName, "#5");
1113 Assert.AreEqual ("address", ex.ParamName, "#6");
1117 [Test] // UploadFile (Uri, string, string)
1118 public void UploadFile4_Address_SchemeNotSupported ()
1120 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1121 File.Create (tempFile).Close ();
1123 WebClient wc = new WebClient ();
1125 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1128 } catch (WebException ex) {
1129 // An error occurred performing a WebClient request
1130 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1131 Assert.IsNotNull (ex.InnerException, "#3");
1132 Assert.IsNotNull (ex.Message, "#4");
1133 Assert.IsNull (ex.Response, "#5");
1134 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1136 // The URI prefix is not recognized
1137 Exception inner = ex.InnerException;
1138 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1139 Assert.IsNull (inner.InnerException, "#8");
1140 Assert.IsNotNull (inner.Message, "#9");
1144 [Test] // UploadFile (Uri, string, string)
1145 public void UploadFile4_FileName_NotFound ()
1147 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1149 WebClient wc = new WebClient ();
1151 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1154 } catch (WebException ex) {
1155 // An error occurred performing a WebClient request
1156 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1157 Assert.IsNotNull (ex.Message, "#3");
1158 Assert.IsNull (ex.Response, "#4");
1159 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1161 // Could not find file "..."
1162 FileNotFoundException inner = ex.InnerException
1163 as FileNotFoundException;
1164 Assert.IsNotNull (inner, "#6");
1165 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1166 Assert.IsNotNull (inner.FileName, "#8");
1167 Assert.AreEqual (tempFile, inner.FileName, "#9");
1168 Assert.IsNull (inner.InnerException, "#10");
1169 Assert.IsNotNull (inner.Message, "#11");
1173 [Test] // UploadFile (Uri, string, string)
1174 public void UploadFile4_FileName_Null ()
1176 WebClient wc = new WebClient ();
1178 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1179 "POST", (string) null);
1181 } catch (ArgumentNullException ex) {
1182 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1183 Assert.IsNull (ex.InnerException, "#3");
1184 Assert.IsNotNull (ex.Message, "#4");
1185 Assert.IsNotNull (ex.ParamName, "#5");
1186 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1190 [Test] // UploadString (string, string)
1191 public void UploadString1_Address_Null ()
1193 WebClient wc = new WebClient ();
1195 wc.UploadString ((string) null, (string) null);
1197 } catch (ArgumentNullException ex) {
1198 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1199 Assert.IsNull (ex.InnerException, "#3");
1200 Assert.IsNotNull (ex.Message, "#4");
1201 Assert.IsNotNull (ex.ParamName, "#5");
1202 Assert.AreEqual ("address", ex.ParamName, "#6");
1206 [Test] // UploadString (string, string)
1207 public void UploadString1_Address_SchemeNotSupported ()
1209 WebClient wc = new WebClient ();
1211 wc.UploadString ("tp://scheme.notsupported", "abc");
1213 } catch (WebException ex) {
1214 // An error occurred performing a WebClient request
1215 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1216 Assert.IsNotNull (ex.InnerException, "#3");
1217 Assert.IsNotNull (ex.Message, "#4");
1218 Assert.IsNull (ex.Response, "#5");
1219 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1221 // The URI prefix is not recognized
1222 Exception inner = ex.InnerException;
1223 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1224 Assert.IsNull (inner.InnerException, "#8");
1225 Assert.IsNotNull (inner.Message, "#9");
1229 [Test] // UploadString (string, string)
1230 public void UploadString1_Data_Null ()
1232 WebClient wc = new WebClient ();
1234 wc.UploadString ("tp://scheme.notsupported", (string) null);
1236 } catch (ArgumentNullException ex) {
1237 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1238 Assert.IsNull (ex.InnerException, "#3");
1239 Assert.IsNotNull (ex.Message, "#4");
1240 Assert.IsNotNull (ex.ParamName, "#5");
1241 Assert.AreEqual ("data", ex.ParamName, "#6");
1245 [Test] // UploadString (Uri, string)
1246 public void UploadString2_Address_Null ()
1248 WebClient wc = new WebClient ();
1250 wc.UploadString ((Uri) null, (string) null);
1252 } catch (ArgumentNullException ex) {
1253 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1254 Assert.IsNull (ex.InnerException, "#3");
1255 Assert.IsNotNull (ex.Message, "#4");
1256 Assert.IsNotNull (ex.ParamName, "#5");
1257 Assert.AreEqual ("address", ex.ParamName, "#6");
1261 [Test] // UploadString (Uri, string)
1262 public void UploadString2_Address_SchemeNotSupported ()
1264 WebClient wc = new WebClient ();
1266 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1268 } catch (WebException ex) {
1269 // An error occurred performing a WebClient request
1270 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1271 Assert.IsNotNull (ex.InnerException, "#3");
1272 Assert.IsNotNull (ex.Message, "#4");
1273 Assert.IsNull (ex.Response, "#5");
1274 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1276 // The URI prefix is not recognized
1277 Exception inner = ex.InnerException;
1278 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1279 Assert.IsNull (inner.InnerException, "#8");
1280 Assert.IsNotNull (inner.Message, "#9");
1284 [Test] // UploadString (Uri, string)
1285 public void UploadString2_Data_Null ()
1287 WebClient wc = new WebClient ();
1289 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1292 } catch (ArgumentNullException ex) {
1293 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1294 Assert.IsNull (ex.InnerException, "#3");
1295 Assert.IsNotNull (ex.Message, "#4");
1296 Assert.IsNotNull (ex.ParamName, "#5");
1297 Assert.AreEqual ("data", ex.ParamName, "#6");
1301 [Test] // UploadString (string, string, string)
1302 public void UploadString3_Address_Null ()
1304 WebClient wc = new WebClient ();
1306 wc.UploadString ((string) null, (string) null,
1309 } catch (ArgumentNullException ex) {
1310 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1311 Assert.IsNull (ex.InnerException, "#3");
1312 Assert.IsNotNull (ex.Message, "#4");
1313 Assert.IsNotNull (ex.ParamName, "#5");
1314 Assert.AreEqual ("address", ex.ParamName, "#6");
1318 [Test] // UploadString (string, string, string)
1319 public void UploadString3_Address_SchemeNotSupported ()
1321 WebClient wc = new WebClient ();
1323 wc.UploadString ("tp://scheme.notsupported",
1326 } catch (WebException ex) {
1327 // An error occurred performing a WebClient request
1328 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1329 Assert.IsNotNull (ex.InnerException, "#3");
1330 Assert.IsNotNull (ex.Message, "#4");
1331 Assert.IsNull (ex.Response, "#5");
1332 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1334 // The URI prefix is not recognized
1335 Exception inner = ex.InnerException;
1336 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1337 Assert.IsNull (inner.InnerException, "#8");
1338 Assert.IsNotNull (inner.Message, "#9");
1342 [Test] // UploadString (string, string, string)
1343 public void UploadString3_Data_Null ()
1345 WebClient wc = new WebClient ();
1347 wc.UploadString ("tp://scheme.notsupported",
1348 "POST", (string) null);
1350 } catch (ArgumentNullException ex) {
1351 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1352 Assert.IsNull (ex.InnerException, "#3");
1353 Assert.IsNotNull (ex.Message, "#4");
1354 Assert.IsNotNull (ex.ParamName, "#5");
1355 Assert.AreEqual ("data", ex.ParamName, "#6");
1359 [Test] // UploadString (Uri, string, string)
1360 public void UploadString4_Address_Null ()
1362 WebClient wc = new WebClient ();
1364 wc.UploadString ((Uri) null, (string) null,
1367 } catch (ArgumentNullException ex) {
1368 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1369 Assert.IsNull (ex.InnerException, "#3");
1370 Assert.IsNotNull (ex.Message, "#4");
1371 Assert.IsNotNull (ex.ParamName, "#5");
1372 Assert.AreEqual ("address", ex.ParamName, "#6");
1376 [Test] // UploadString (Uri, string, string)
1377 public void UploadString4_Address_SchemeNotSupported ()
1379 WebClient wc = new WebClient ();
1381 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1384 } catch (WebException ex) {
1385 // An error occurred performing a WebClient request
1386 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1387 Assert.IsNotNull (ex.InnerException, "#3");
1388 Assert.IsNotNull (ex.Message, "#4");
1389 Assert.IsNull (ex.Response, "#5");
1390 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1392 // The URI prefix is not recognized
1393 Exception inner = ex.InnerException;
1394 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1395 Assert.IsNull (inner.InnerException, "#8");
1396 Assert.IsNotNull (inner.Message, "#9");
1400 [Test] // UploadString (Uri, string, string)
1401 public void UploadString4_Data_Null ()
1403 WebClient wc = new WebClient ();
1405 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1406 "POST", (string) null);
1408 } catch (ArgumentNullException ex) {
1409 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1410 Assert.IsNull (ex.InnerException, "#3");
1411 Assert.IsNotNull (ex.Message, "#4");
1412 Assert.IsNotNull (ex.ParamName, "#5");
1413 Assert.AreEqual ("data", ex.ParamName, "#6");
1418 public void UploadValues1 ()
1420 IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
1421 string url = "http://" + IPAddress.Loopback.ToString () + ":8000/test/";
1423 using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) {
1426 WebClient wc = new WebClient ();
1427 wc.Encoding = Encoding.ASCII;
1429 NameValueCollection nvc = new NameValueCollection ();
1430 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1431 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1433 byte [] buffer = wc.UploadValues (url, nvc);
1434 string response = Encoding.UTF8.GetString (buffer);
1435 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1439 [Test] // UploadValues (string, NameValueCollection)
1440 public void UploadValues1_Address_Null ()
1442 WebClient wc = new WebClient ();
1444 wc.UploadValues ((string) null, new NameValueCollection ());
1446 } catch (ArgumentNullException ex) {
1447 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1448 Assert.IsNull (ex.InnerException, "#3");
1449 Assert.IsNotNull (ex.Message, "#4");
1450 Assert.IsNotNull (ex.ParamName, "#5");
1451 Assert.AreEqual ("address", ex.ParamName, "#6");
1455 [Test] // UploadValues (string, NameValueCollection)
1456 public void UploadValues1_Address_SchemeNotSupported ()
1458 WebClient wc = new WebClient ();
1460 wc.UploadValues ("tp://scheme.notsupported",
1461 new NameValueCollection ());
1463 } catch (WebException ex) {
1464 // An error occurred performing a WebClient request
1465 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1466 Assert.IsNotNull (ex.InnerException, "#3");
1467 Assert.IsNotNull (ex.Message, "#4");
1468 Assert.IsNull (ex.Response, "#5");
1469 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1471 // The URI prefix is not recognized
1472 Exception inner = ex.InnerException;
1473 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1474 Assert.IsNull (inner.InnerException, "#8");
1475 Assert.IsNotNull (inner.Message, "#9");
1479 [Test] // UploadValues (string, NameValueCollection)
1480 public void UploadValues1_Data_Null ()
1482 WebClient wc = new WebClient ();
1484 wc.UploadValues ("http://www.mono-project.com",
1485 (NameValueCollection) null);
1487 } catch (ArgumentNullException ex) {
1488 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1489 Assert.IsNull (ex.InnerException, "#3");
1490 Assert.IsNotNull (ex.Message, "#4");
1491 Assert.IsNotNull (ex.ParamName, "#5");
1492 Assert.AreEqual ("data", ex.ParamName, "#6");
1496 [Test] // UploadValues (Uri, NameValueCollection)
1497 public void UploadValues2_Address_Null ()
1499 WebClient wc = new WebClient ();
1501 wc.UploadValues ((Uri) null, new NameValueCollection ());
1503 } catch (ArgumentNullException ex) {
1504 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1505 Assert.IsNull (ex.InnerException, "#3");
1506 Assert.IsNotNull (ex.Message, "#4");
1507 Assert.IsNotNull (ex.ParamName, "#5");
1508 Assert.AreEqual ("address", ex.ParamName, "#6");
1512 [Test] // UploadValues (Uri, NameValueCollection)
1513 public void UploadValues2_Address_SchemeNotSupported ()
1515 WebClient wc = new WebClient ();
1517 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1518 new NameValueCollection ());
1520 } catch (WebException ex) {
1521 // An error occurred performing a WebClient request
1522 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1523 Assert.IsNotNull (ex.InnerException, "#3");
1524 Assert.IsNotNull (ex.Message, "#4");
1525 Assert.IsNull (ex.Response, "#5");
1526 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1528 // The URI prefix is not recognized
1529 Exception inner = ex.InnerException;
1530 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1531 Assert.IsNull (inner.InnerException, "#8");
1532 Assert.IsNotNull (inner.Message, "#9");
1536 [Test] // UploadValues (Uri, NameValueCollection)
1537 public void UploadValues2_Data_Null ()
1539 WebClient wc = new WebClient ();
1541 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1542 (NameValueCollection) null);
1544 } catch (ArgumentNullException ex) {
1545 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1546 Assert.IsNull (ex.InnerException, "#3");
1547 Assert.IsNotNull (ex.Message, "#4");
1548 Assert.IsNotNull (ex.ParamName, "#5");
1549 Assert.AreEqual ("data", ex.ParamName, "#6");
1553 [Test] // UploadValues (string, string, NameValueCollection)
1554 public void UploadValues3_Address_Null ()
1556 WebClient wc = new WebClient ();
1558 wc.UploadValues ((string) null, "POST",
1559 new NameValueCollection ());
1561 } catch (ArgumentNullException ex) {
1562 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1563 Assert.IsNull (ex.InnerException, "#3");
1564 Assert.IsNotNull (ex.Message, "#4");
1565 Assert.IsNotNull (ex.ParamName, "#5");
1566 Assert.AreEqual ("address", ex.ParamName, "#6");
1570 [Test] // UploadValues (string, string, NameValueCollection)
1571 public void UploadValues3_Address_SchemeNotSupported ()
1573 WebClient wc = new WebClient ();
1575 wc.UploadValues ("tp://scheme.notsupported",
1576 "POST", new NameValueCollection ());
1578 } catch (WebException ex) {
1579 // An error occurred performing a WebClient request
1580 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1581 Assert.IsNotNull (ex.InnerException, "#3");
1582 Assert.IsNotNull (ex.Message, "#4");
1583 Assert.IsNull (ex.Response, "#5");
1584 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1586 // The URI prefix is not recognized
1587 Exception inner = ex.InnerException;
1588 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1589 Assert.IsNull (inner.InnerException, "#8");
1590 Assert.IsNotNull (inner.Message, "#9");
1594 [Test] // UploadValues (string, string, NameValueCollection)
1595 public void UploadValues3_Data_Null ()
1597 WebClient wc = new WebClient ();
1599 wc.UploadValues ("http://www.mono-project.com",
1600 "POST", (NameValueCollection) null);
1602 } catch (ArgumentNullException ex) {
1603 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1604 Assert.IsNull (ex.InnerException, "#3");
1605 Assert.IsNotNull (ex.Message, "#4");
1606 Assert.IsNotNull (ex.ParamName, "#5");
1607 Assert.AreEqual ("data", ex.ParamName, "#6");
1611 [Test] // UploadValues (Uri, string, NameValueCollection)
1612 public void UploadValues4_Address_Null ()
1614 WebClient wc = new WebClient ();
1616 wc.UploadValues ((Uri) null, "POST",
1617 new NameValueCollection ());
1619 } catch (ArgumentNullException ex) {
1620 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1621 Assert.IsNull (ex.InnerException, "#3");
1622 Assert.IsNotNull (ex.Message, "#4");
1623 Assert.IsNotNull (ex.ParamName, "#5");
1624 Assert.AreEqual ("address", ex.ParamName, "#6");
1628 [Test] // UploadValues (Uri, string, NameValueCollection)
1629 public void UploadValues4_Address_SchemeNotSupported ()
1631 WebClient wc = new WebClient ();
1633 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1634 "POST", new NameValueCollection ());
1636 } catch (WebException ex) {
1637 // An error occurred performing a WebClient request
1638 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1639 Assert.IsNotNull (ex.InnerException, "#3");
1640 Assert.IsNotNull (ex.Message, "#4");
1641 Assert.IsNull (ex.Response, "#5");
1642 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1644 // The URI prefix is not recognized
1645 Exception inner = ex.InnerException;
1646 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1647 Assert.IsNull (inner.InnerException, "#8");
1648 Assert.IsNotNull (inner.Message, "#9");
1652 [Test] // UploadValues (Uri, string, NameValueCollection)
1653 public void UploadValues4_Data_Null ()
1655 WebClient wc = new WebClient ();
1657 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1658 "POST", (NameValueCollection) null);
1660 } catch (ArgumentNullException ex) {
1661 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1662 Assert.IsNull (ex.InnerException, "#3");
1663 Assert.IsNotNull (ex.Message, "#4");
1664 Assert.IsNotNull (ex.ParamName, "#5");
1665 Assert.AreEqual ("data", ex.ParamName, "#6");
1670 public void GetWebRequestOverriding ()
1672 GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1673 testObject.DownloadData ("http://www.mono-project.com");
1675 Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1678 class GetWebRequestOverridingTestClass : WebClient
1680 internal bool overridedCodeRan = false;
1681 protected override WebRequest GetWebRequest(Uri address)
1683 overridedCodeRan = true;
1684 return base.GetWebRequest (address);
1688 static byte [] EchoRequestHandler (Socket socket)
1690 MemoryStream ms = new MemoryStream ();
1691 byte [] buffer = new byte [4096];
1692 int bytesReceived = socket.Receive (buffer);
1693 while (bytesReceived > 0) {
1694 ms.Write (buffer, 0, bytesReceived);
1695 // We don't check for Content-Length or anything else here, so we give the client a little time to write
1696 // after sending the headers
1698 if (socket.Available > 0) {
1699 bytesReceived = socket.Receive (buffer);
1707 StringBuilder sb = new StringBuilder ();
1709 string expect = null;
1711 StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1714 while ((line = sr.ReadLine ()) != null) {
1719 } if (line.Length == 0) {
1721 } else if (line.StartsWith ("Expect:")) {
1722 expect = line.Substring (8);
1726 StringWriter sw = new StringWriter ();
1728 if (expect == "100-continue" && state != 2) {
1729 sw.WriteLine ("HTTP/1.1 100 Continue");
1733 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1736 ms = new MemoryStream ();
1737 buffer = new byte [4096];
1738 bytesReceived = socket.Receive (buffer);
1739 while (bytesReceived > 0) {
1740 ms.Write (buffer, 0, bytesReceived);
1742 if (socket.Available > 0) {
1743 bytesReceived = socket.Receive (buffer);
1751 sb = new StringBuilder ();
1752 sr = new StreamReader (ms, Encoding.UTF8);
1753 line = sr.ReadLine ();
1754 while (line != null) {
1757 line = sr.ReadLine ();
1761 sw = new StringWriter ();
1762 sw.WriteLine ("HTTP/1.1 200 OK");
1763 sw.WriteLine ("Content-Type: text/xml");
1764 sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1766 sw.Write (sb.ToString ());
1769 return Encoding.UTF8.GetBytes (sw.ToString ());
1773 public void DefaultProxy ()
1775 WebClient wc = new WebClient ();
1776 // this is never null on .net
1777 Assert.IsNotNull (wc.Proxy);
1778 // and return the same instance as WebRequest.DefaultWebProxy
1779 Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1784 public void UploadStringAsyncCancelEvent ()
1786 UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
1789 webClient.UploadStringCompleted += (sender, args) =>
1795 webClient.UploadStringAsync (uri, "PUT", "text");
1800 public void UploadDataAsyncCancelEvent ()
1802 UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
1804 webClient.UploadDataCompleted += (sender, args) =>
1810 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1815 public void UploadValuesAsyncCancelEvent ()
1817 UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
1819 webClient.UploadValuesCompleted += (sender, args) =>
1825 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1830 public void UploadFileAsyncCancelEvent ()
1832 UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
1834 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1835 File.Create (tempFile).Close ();
1837 webClient.UploadFileCompleted += (sender, args) =>
1843 webClient.UploadFileAsync (uri, "PUT", tempFile);
1848 public void UploadFileAsyncContentType ()
1850 var serverUri = "http://localhost:13370/";
1851 var filename = Path.GetTempFileName ();
1853 HttpListener listener = new HttpListener ();
1854 listener.Prefixes.Add (serverUri);
1857 using (var client = new WebClient ())
1859 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1860 var request = listener.GetContext ().Request;
1862 var expected = "multipart/form-data; boundary=---------------------";
1863 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1864 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1871 public void UploadAsyncCancelEventTest (Action<WebClient, Uri, EventWaitHandle> uploadAction)
1873 var ep = new IPEndPoint (IPAddress.Loopback, 8000);
1874 string url = "http://" + IPAddress.Loopback + ":8000/test/";
1876 using (var responder = new SocketResponder (ep, EchoRequestHandler))
1880 var webClient = new WebClient ();
1882 var cancellationTokenSource = new CancellationTokenSource ();
1883 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1885 var cancelEvent = new ManualResetEvent (false);
1887 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1889 cancellationTokenSource.Cancel ();
1891 Assert.IsTrue (cancelEvent.WaitOne (1000));