[System] Tweak define to exclude System.Net.WebProxy.CreateDefaultProxy and update...
[mono.git] / mcs / class / System / Test / System.Net / WebClientTest.cs
1 //
2 // WebClientTest.cs - NUnit Test Cases for System.Net.WebClient
3 //
4 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
5 //
6
7 using System;
8 using System.Collections;
9 using System.Collections.Specialized;
10 using System.Globalization;
11 using System.IO;
12 using System.Net;
13 using System.Net.Sockets;
14 using System.Runtime.Serialization;
15 using System.Text;
16 using System.Threading;
17 using NUnit.Framework;
18
19 using MonoTests.Helpers;
20
21 namespace MonoTests.System.Net
22 {
23         [TestFixture]
24         public class WebClientTest
25         {
26                 private string _tempFolder;
27
28                 [SetUp]
29                 public void SetUp ()
30                 {
31                         _tempFolder = Path.Combine (Path.GetTempPath (),
32                                 GetType ().FullName);
33                         if (Directory.Exists (_tempFolder))
34                                 Directory.Delete (_tempFolder, true);
35                         Directory.CreateDirectory (_tempFolder);
36                 }
37
38                 [TearDown]
39                 public void TearDown ()
40                 {
41                         if (Directory.Exists (_tempFolder))
42                                 Directory.Delete (_tempFolder, true);
43                 }
44
45                 [Test]
46                 [Category ("InetAccess")]
47                 public void DownloadTwice ()
48                 {
49                         WebClient wc = new WebClient();
50                         string filename = Path.GetTempFileName();
51                         
52                         // A new, but empty file has been created. This is a test case
53                         // for bug 81005
54                         wc.DownloadFile("http://google.com/", filename);
55                         
56                         // Now, remove the file and attempt to download again.
57                         File.Delete(filename);
58                         wc.DownloadFile("http://google.com/", filename);
59                 }
60
61                 [Test]
62                 public void DownloadData1_Address_Null ()
63                 {
64                         WebClient wc = new WebClient ();
65                         try {
66                                 wc.DownloadData ((string) null);
67                                 Assert.Fail ("#1");
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");
74                         }
75                 }
76
77                 [Test] // DownloadData (string)
78                 public void DownloadData1_Address_SchemeNotSupported ()
79                 {
80                         WebClient wc = new WebClient ();
81                         try {
82                                 wc.DownloadData ("tp://scheme.notsupported");
83                                 Assert.Fail ("#1");
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");
91
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");
97                         }
98                 }
99
100                 [Test] // DownloadData (Uri)
101                 public void DownloadData2_Address_Null ()
102                 {
103                         WebClient wc = new WebClient ();
104                         try {
105                                 wc.DownloadData ((Uri) null);
106                                 Assert.Fail ("#1");
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");
113                         }
114                 }
115
116                 [Test] // DownloadData (Uri)
117                 public void DownloadData2_Address_SchemeNotSupported ()
118                 {
119                         WebClient wc = new WebClient ();
120                         try {
121                                 wc.DownloadData (new Uri ("tp://scheme.notsupported"));
122                                 Assert.Fail ("#1");
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");
130
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");
136                         }
137                 }
138
139                 [Test]
140                 public void DownloadFile1_Address_Null ()
141                 {
142                         WebClient wc = new WebClient ();
143                         try {
144                                 wc.DownloadFile ((string) null, "tmp.out");
145                                 Assert.Fail ("#1");
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");
152                         }
153                 }
154
155                 [Test] // DownloadFile (string, string)
156                 public void DownloadFile1_Address_SchemeNotSupported ()
157                 {
158                         string file = Path.Combine (Path.GetTempPath (), "tmp.out");
159                         WebClient wc = new WebClient ();
160                         try {
161                                 wc.DownloadFile ("tp://scheme.notsupported", file);
162                                 Assert.Fail ("#1");
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");
170
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");
176                         }
177                         finally {
178                                 if (File.Exists (file))
179                                         File.Delete (file);
180                         }
181                 }
182
183                 [Test] // DownloadFile (string, string)
184                 public void DownloadFile1_FileName_Null ()
185                 {
186                         WebClient wc = new WebClient ();
187                         try {
188                                 wc.DownloadFile ("tp://scheme.notsupported",
189                                         (string) null);
190                                 Assert.Fail ("#1");
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");
197                         }
198                 }
199
200                 [Test] // DownloadFile (Uri, string)
201                 public void DownloadFile2_Address_Null ()
202                 {
203                         WebClient wc = new WebClient ();
204                         try {
205                                 wc.DownloadFile ((Uri) null, "tmp.out");
206                                 Assert.Fail ("#1");
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");
213                         }
214                 }
215
216                 [Test] // DownloadFile (Uri, string)
217                 public void DownloadFile2_Address_SchemeNotSupported ()
218                 {
219                         string file = Path.Combine (Path.GetTempPath (), "tmp.out");
220                         WebClient wc = new WebClient ();
221                         try {
222                                 wc.DownloadFile (new Uri ("tp://scheme.notsupported"), file);
223                                 Assert.Fail ("#1");
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");
231
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");
237                         }
238                         finally {
239                                 if (File.Exists (file))
240                                         File.Delete (file);
241                         }
242                 }
243
244                 [Test] // DownloadFile (Uri, string)
245                 public void DownloadFile2_FileName_Null ()
246                 {
247                         WebClient wc = new WebClient ();
248                         try {
249                                 wc.DownloadFile (new Uri ("tp://scheme.notsupported"),
250                                         (string) null);
251                                 Assert.Fail ("#1");
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");
258                         }
259                 }
260
261                 [Test] // DownloadString (string)
262                 public void DownloadString1_Address_Null ()
263                 {
264                         WebClient wc = new WebClient ();
265                         try {
266                                 wc.DownloadString ((string) null);
267                                 Assert.Fail ("#1");
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");
274                         }
275                 }
276
277                 [Test] // DownloadString (string)
278                 public void DownloadString1_Address_SchemeNotSupported ()
279                 {
280                         WebClient wc = new WebClient ();
281                         try {
282                                 wc.DownloadString ("tp://scheme.notsupported");
283                                 Assert.Fail ("#1");
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");
291
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");
297                         }
298                 }
299
300                 [Test] // DownloadString (Uri)
301                 public void DownloadString2_Address_Null ()
302                 {
303                         WebClient wc = new WebClient ();
304                         try {
305                                 wc.DownloadString ((Uri) null);
306                                 Assert.Fail ("#1");
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");
313                         }
314                 }
315
316                 [Test] // DownloadString (Uri)
317                 public void DownloadString2_Address_SchemeNotSupported ()
318                 {
319                         WebClient wc = new WebClient ();
320                         try {
321                                 wc.DownloadString (new Uri ("tp://scheme.notsupported"));
322                                 Assert.Fail ("#1");
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");
330
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");
336                         }
337                 }
338
339                 [Test]
340                 public void EncodingTest ()
341                 {
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");
346                 }
347
348                 [Test]
349                 public void Encoding_Value_Null ()
350                 {
351                         WebClient wc = new WebClient ();
352                         try {
353                                 wc.Encoding = null;
354                                 Assert.Fail ("#1");
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");
360                         }
361                 }
362
363                 [Test] // OpenRead (string)
364                 public void OpenRead1_Address_Null ()
365                 {
366                         WebClient wc = new WebClient ();
367                         try {
368                                 wc.OpenRead ((string) null);
369                                 Assert.Fail ("#1");
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");
376                         }
377                 }
378
379                 [Test] // OpenRead (string)
380                 public void OpenRead1_Address_SchemeNotSupported ()
381                 {
382                         WebClient wc = new WebClient ();
383                         try {
384                                 wc.OpenRead ("tp://scheme.notsupported");
385                                 Assert.Fail ("#1");
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");
393
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");
399                         }
400                 }
401
402                 [Test] // OpenRead (Uri)
403                 public void OpenRead2_Address_Null ()
404                 {
405                         WebClient wc = new WebClient ();
406                         try {
407                                 wc.OpenRead ((Uri) null);
408                                 Assert.Fail ("#1");
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");
415                         }
416                 }
417
418                 [Test] // OpenRead (Uri)
419                 public void OpenRead2_Address_SchemeNotSupported ()
420                 {
421                         WebClient wc = new WebClient ();
422                         try {
423                                 wc.OpenRead (new Uri ("tp://scheme.notsupported"));
424                                 Assert.Fail ("#1");
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");
432
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");
438                         }
439                 }
440
441                 [Test] // OpenWrite (string)
442                 public void OpenWrite1_Address_Null ()
443                 {
444                         WebClient wc = new WebClient ();
445                         try {
446                                 wc.OpenWrite ((string) null);
447                                 Assert.Fail ("#1");
448                         } catch (ArgumentNullException ex) {
449                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
450                                 Assert.IsNull (ex.InnerException, "#3");
451                                 Assert.IsNotNull (ex.Message, "#4");
452                                 Assert.IsNotNull (ex.ParamName, "#5");
453                                 Assert.AreEqual ("address", ex.ParamName, "#6");
454                         }
455                 }
456
457                 [Test] // OpenWrite (string)
458                 public void OpenWrite1_Address_SchemeNotSupported ()
459                 {
460                         WebClient wc = new WebClient ();
461                         try {
462                                 wc.OpenWrite ("tp://scheme.notsupported");
463                                 Assert.Fail ("#1");
464                         } catch (WebException ex) {
465                                 // An error occurred performing a WebClient request
466                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
467                                 Assert.IsNotNull (ex.InnerException, "#3");
468                                 Assert.IsNotNull (ex.Message, "#4");
469                                 Assert.IsNull (ex.Response, "#5");
470                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
471
472                                 // The URI prefix is not recognized
473                                 Exception inner = ex.InnerException;
474                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
475                                 Assert.IsNull (inner.InnerException, "#8");
476                                 Assert.IsNotNull (inner.Message, "#9");
477                         }
478                 }
479
480                 [Test] // OpenWrite (string, string)
481                 public void OpenWrite2_Address_Null ()
482                 {
483                         WebClient wc = new WebClient ();
484                         try {
485                                 wc.OpenWrite ((string) null, "PUT");
486                                 Assert.Fail ("#1");
487                         } catch (ArgumentNullException ex) {
488                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
489                                 Assert.IsNull (ex.InnerException, "#3");
490                                 Assert.IsNotNull (ex.Message, "#4");
491                                 Assert.IsNotNull (ex.ParamName, "#5");
492                                 Assert.AreEqual ("address", ex.ParamName, "#6");
493                         }
494                 }
495
496                 [Test] // OpenWrite (string, string)
497                 public void OpenWrite2_Address_SchemeNotSupported ()
498                 {
499                         WebClient wc = new WebClient ();
500                         try {
501                                 wc.OpenWrite ("tp://scheme.notsupported", "PUT");
502                                 Assert.Fail ("#1");
503                         } catch (WebException ex) {
504                                 // An error occurred performing a WebClient request
505                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
506                                 Assert.IsNotNull (ex.InnerException, "#3");
507                                 Assert.IsNotNull (ex.Message, "#4");
508                                 Assert.IsNull (ex.Response, "#5");
509                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
510
511                                 // The URI prefix is not recognized
512                                 Exception inner = ex.InnerException;
513                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
514                                 Assert.IsNull (inner.InnerException, "#8");
515                                 Assert.IsNotNull (inner.Message, "#9");
516                         }
517                 }
518
519                 [Test] // OpenWrite (Uri)
520                 public void OpenWrite3_Address_Null ()
521                 {
522                         WebClient wc = new WebClient ();
523                         try {
524                                 wc.OpenWrite ((Uri) null);
525                                 Assert.Fail ("#1");
526                         } catch (ArgumentNullException ex) {
527                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
528                                 Assert.IsNull (ex.InnerException, "#3");
529                                 Assert.IsNotNull (ex.Message, "#4");
530                                 Assert.IsNotNull (ex.ParamName, "#5");
531                                 Assert.AreEqual ("address", ex.ParamName, "#6");
532                         }
533                 }
534
535                 [Test] // OpenWrite (Uri)
536                 public void OpenWrite3_Address_SchemeNotSupported ()
537                 {
538                         WebClient wc = new WebClient ();
539                         try {
540                                 wc.OpenWrite (new Uri ("tp://scheme.notsupported"));
541                                 Assert.Fail ("#1");
542                         } catch (WebException ex) {
543                                 // An error occurred performing a WebClient request
544                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
545                                 Assert.IsNotNull (ex.InnerException, "#3");
546                                 Assert.IsNotNull (ex.Message, "#4");
547                                 Assert.IsNull (ex.Response, "#5");
548                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
549
550                                 // The URI prefix is not recognized
551                                 Exception inner = ex.InnerException;
552                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
553                                 Assert.IsNull (inner.InnerException, "#8");
554                                 Assert.IsNotNull (inner.Message, "#9");
555                         }
556                 }
557
558                 [Test] // OpenWrite (Uri, string)
559                 public void OpenWrite4_Address_Null ()
560                 {
561                         WebClient wc = new WebClient ();
562                         try {
563                                 wc.OpenWrite ((Uri) null, "POST");
564                                 Assert.Fail ("#1");
565                         } catch (ArgumentNullException ex) {
566                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
567                                 Assert.IsNull (ex.InnerException, "#3");
568                                 Assert.IsNotNull (ex.Message, "#4");
569                                 Assert.IsNotNull (ex.ParamName, "#5");
570                                 Assert.AreEqual ("address", ex.ParamName, "#6");
571                         }
572                 }
573
574                 [Test] // OpenWrite (Uri, string)
575                 public void OpenWrite4_Address_SchemeNotSupported ()
576                 {
577                         WebClient wc = new WebClient ();
578                         try {
579                                 wc.OpenWrite (new Uri ("tp://scheme.notsupported"),
580                                         "POST");
581                                 Assert.Fail ("#1");
582                         } catch (WebException ex) {
583                                 // An error occurred performing a WebClient request
584                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
585                                 Assert.IsNotNull (ex.InnerException, "#3");
586                                 Assert.IsNotNull (ex.Message, "#4");
587                                 Assert.IsNull (ex.Response, "#5");
588                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
589
590                                 // The URI prefix is not recognized
591                                 Exception inner = ex.InnerException;
592                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
593                                 Assert.IsNull (inner.InnerException, "#8");
594                                 Assert.IsNotNull (inner.Message, "#9");
595                         }
596                 }
597
598                 [Test] // UploadData (string, byte [])
599                 public void UploadData1_Address_Null ()
600                 {
601                         WebClient wc = new WebClient ();
602                         try {
603                                 wc.UploadData ((string) null, new byte [] { 0x1a });
604                                 Assert.Fail ("#1");
605                         } catch (ArgumentNullException ex) {
606                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
607                                 Assert.IsNull (ex.InnerException, "#3");
608                                 Assert.IsNotNull (ex.Message, "#4");
609                                 Assert.IsNotNull (ex.ParamName, "#5");
610                                 Assert.AreEqual ("address", ex.ParamName, "#6");
611                         }
612                 }
613
614                 [Test] // UploadData (string, byte [])
615                 public void UploadData1_Address_SchemeNotSupported ()
616                 {
617                         WebClient wc = new WebClient ();
618                         try {
619                                 wc.UploadData ("tp://scheme.notsupported", new byte [] { 0x1a });
620                                 Assert.Fail ("#1");
621                         } catch (WebException ex) {
622                                 // An error occurred performing a WebClient request
623                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
624                                 Assert.IsNotNull (ex.InnerException, "#3");
625                                 Assert.IsNotNull (ex.Message, "#4");
626                                 Assert.IsNull (ex.Response, "#5");
627                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
628
629                                 // The URI prefix is not recognized
630                                 Exception inner = ex.InnerException;
631                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
632                                 Assert.IsNull (inner.InnerException, "#8");
633                                 Assert.IsNotNull (inner.Message, "#9");
634                         }
635                 }
636
637                 [Test] // UploadData (string, byte [])
638                 public void UploadData1_Data_Null ()
639                 {
640                         WebClient wc = new WebClient ();
641                         try {
642                                 wc.UploadData ("http://www.mono-project.com",
643                                         (byte []) null);
644                                 Assert.Fail ("#1");
645                         } catch (ArgumentNullException ex) {
646                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
647                                 Assert.IsNull (ex.InnerException, "#3");
648                                 Assert.IsNotNull (ex.Message, "#4");
649                                 Assert.IsNotNull (ex.ParamName, "#5");
650                                 Assert.AreEqual ("data", ex.ParamName, "#6");
651                         }
652                 }
653
654                 [Test] // UploadData (Uri, byte [])
655                 public void UploadData2_Address_Null ()
656                 {
657                         WebClient wc = new WebClient ();
658                         try {
659                                 wc.UploadData ((Uri) null, new byte [] { 0x1a });
660                                 Assert.Fail ("#1");
661                         } catch (ArgumentNullException ex) {
662                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
663                                 Assert.IsNull (ex.InnerException, "#3");
664                                 Assert.IsNotNull (ex.Message, "#4");
665                                 Assert.IsNotNull (ex.ParamName, "#5");
666                                 Assert.AreEqual ("address", ex.ParamName, "#6");
667                         }
668                 }
669
670                 [Test] // UploadData (Uri, byte [])
671                 public void UploadData2_Address_SchemeNotSupported ()
672                 {
673                         WebClient wc = new WebClient ();
674                         try {
675                                 wc.UploadData (new Uri ("tp://scheme.notsupported"),
676                                         new byte [] { 0x1a });
677                                 Assert.Fail ("#1");
678                         } catch (WebException ex) {
679                                 // An error occurred performing a WebClient request
680                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
681                                 Assert.IsNotNull (ex.InnerException, "#3");
682                                 Assert.IsNotNull (ex.Message, "#4");
683                                 Assert.IsNull (ex.Response, "#5");
684                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
685
686                                 // The URI prefix is not recognized
687                                 Exception inner = ex.InnerException;
688                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
689                                 Assert.IsNull (inner.InnerException, "#8");
690                                 Assert.IsNotNull (inner.Message, "#9");
691                         }
692                 }
693
694                 [Test] // UploadData (Uri, byte [])
695                 public void UploadData2_Data_Null ()
696                 {
697                         WebClient wc = new WebClient ();
698                         try {
699                                 wc.UploadData (new Uri ("http://www.mono-project.com"),
700                                         (byte []) null);
701                                 Assert.Fail ("#1");
702                         } catch (ArgumentNullException ex) {
703                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
704                                 Assert.IsNull (ex.InnerException, "#3");
705                                 Assert.IsNotNull (ex.Message, "#4");
706                                 Assert.IsNotNull (ex.ParamName, "#5");
707                                 Assert.AreEqual ("data", ex.ParamName, "#6");
708                         }
709                 }
710
711                 [Test] // UploadData (string, string, byte [])
712                 public void UploadData3_Address_Null ()
713                 {
714                         WebClient wc = new WebClient ();
715                         try {
716                                 wc.UploadData ((string) null, "POST",
717                                         new byte [] { 0x1a });
718                                 Assert.Fail ("#1");
719                         } catch (ArgumentNullException ex) {
720                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
721                                 Assert.IsNull (ex.InnerException, "#3");
722                                 Assert.IsNotNull (ex.Message, "#4");
723                                 Assert.IsNotNull (ex.ParamName, "#5");
724                                 Assert.AreEqual ("address", ex.ParamName, "#6");
725                         }
726                 }
727
728                 [Test] // UploadData (string, string, byte [])
729                 public void UploadData3_Address_SchemeNotSupported ()
730                 {
731                         WebClient wc = new WebClient ();
732                         try {
733                                 wc.UploadData ("tp://scheme.notsupported",
734                                         "POST", new byte [] { 0x1a });
735                                 Assert.Fail ("#1");
736                         } catch (WebException ex) {
737                                 // An error occurred performing a WebClient request
738                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
739                                 Assert.IsNotNull (ex.InnerException, "#3");
740                                 Assert.IsNotNull (ex.Message, "#4");
741                                 Assert.IsNull (ex.Response, "#5");
742                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
743
744                                 // The URI prefix is not recognized
745                                 Exception inner = ex.InnerException;
746                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
747                                 Assert.IsNull (inner.InnerException, "#8");
748                                 Assert.IsNotNull (inner.Message, "#9");
749                         }
750                 }
751
752                 [Test] // UploadData (string, string, byte [])
753                 public void UploadData3_Data_Null ()
754                 {
755                         WebClient wc = new WebClient ();
756                         try {
757                                 wc.UploadData ("http://www.mono-project.com",
758                                         "POST", (byte []) null);
759                                 Assert.Fail ("#1");
760                         } catch (ArgumentNullException ex) {
761                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
762                                 Assert.IsNull (ex.InnerException, "#3");
763                                 Assert.IsNotNull (ex.Message, "#4");
764                                 Assert.IsNotNull (ex.ParamName, "#5");
765                                 Assert.AreEqual ("data", ex.ParamName, "#6");
766                         }
767                 }
768
769                 [Test] // UploadData (Uri, string, byte [])
770                 public void UploadData4_Address_Null ()
771                 {
772                         WebClient wc = new WebClient ();
773                         try {
774                                 wc.UploadData ((Uri) null, "POST", new byte [] { 0x1a });
775                                 Assert.Fail ("#1");
776                         } catch (ArgumentNullException ex) {
777                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
778                                 Assert.IsNull (ex.InnerException, "#3");
779                                 Assert.IsNotNull (ex.Message, "#4");
780                                 Assert.IsNotNull (ex.ParamName, "#5");
781                                 Assert.AreEqual ("address", ex.ParamName, "#6");
782                         }
783                 }
784
785                 [Test] // UploadData (Uri, string, byte [])
786                 public void UploadData4_Address_SchemeNotSupported ()
787                 {
788                         WebClient wc = new WebClient ();
789                         try {
790                                 wc.UploadData (new Uri ("tp://scheme.notsupported"),
791                                         "POST", new byte [] { 0x1a });
792                                 Assert.Fail ("#1");
793                         } catch (WebException ex) {
794                                 // An error occurred performing a WebClient request
795                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
796                                 Assert.IsNotNull (ex.InnerException, "#3");
797                                 Assert.IsNotNull (ex.Message, "#4");
798                                 Assert.IsNull (ex.Response, "#5");
799                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
800
801                                 // The URI prefix is not recognized
802                                 Exception inner = ex.InnerException;
803                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
804                                 Assert.IsNull (inner.InnerException, "#8");
805                                 Assert.IsNotNull (inner.Message, "#9");
806                         }
807                 }
808
809                 [Test] // UploadData (Uri, string, byte [])
810                 public void UploadData4_Data_Null ()
811                 {
812                         WebClient wc = new WebClient ();
813                         try {
814                                 wc.UploadData (new Uri ("http://www.mono-project.com"),
815                                         "POST", (byte []) null);
816                                 Assert.Fail ("#1");
817                         } catch (ArgumentNullException ex) {
818                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
819                                 Assert.IsNull (ex.InnerException, "#3");
820                                 Assert.IsNotNull (ex.Message, "#4");
821                                 Assert.IsNotNull (ex.ParamName, "#5");
822                                 Assert.AreEqual ("data", ex.ParamName, "#6");
823                         }
824                 }
825
826                 [Test] // UploadFile (string, string)
827                 public void UploadFile1_Address_Null ()
828                 {
829                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
830                         File.Create (tempFile).Close ();
831
832                         WebClient wc = new WebClient ();
833                         try {
834                                 wc.UploadFile ((string) null, tempFile);
835                                 Assert.Fail ("#1");
836                         } catch (ArgumentNullException ex) {
837                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
838                                 Assert.IsNull (ex.InnerException, "#3");
839                                 Assert.IsNotNull (ex.Message, "#4");
840                                 Assert.IsNotNull (ex.ParamName, "#5");
841                                 Assert.AreEqual ("address", ex.ParamName, "#6");
842                         }
843                 }
844
845                 [Test] // UploadFile (string, string)
846                 public void UploadFile1_Address_SchemeNotSupported ()
847                 {
848                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
849                         File.Create (tempFile).Close ();
850
851                         WebClient wc = new WebClient ();
852                         try {
853                                 wc.UploadFile ("tp://scheme.notsupported",
854                                         tempFile);
855                                 Assert.Fail ("#1");
856                         } catch (WebException ex) {
857                                 // An error occurred performing a WebClient request
858                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
859                                 Assert.IsNotNull (ex.InnerException, "#3");
860                                 Assert.IsNotNull (ex.Message, "#4");
861                                 Assert.IsNull (ex.Response, "#5");
862                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
863
864                                 // The URI prefix is not recognized
865                                 Exception inner = ex.InnerException;
866                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
867                                 Assert.IsNull (inner.InnerException, "#8");
868                                 Assert.IsNotNull (inner.Message, "#9");
869                         }
870                 }
871
872                 [Test] // UploadFile (string, string)
873                 public void UploadFile1_FileName_NotFound ()
874                 {
875                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
876
877                         WebClient wc = new WebClient ();
878                         try {
879                                 wc.UploadFile ("tp://scheme.notsupported",
880                                         tempFile);
881                                 Assert.Fail ("#1");
882                         } catch (WebException ex) {
883                                 // An error occurred performing a WebClient request
884                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
885                                 Assert.IsNotNull (ex.Message, "#3");
886                                 Assert.IsNull (ex.Response, "#4");
887                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
888
889                                 // Could not find file "..."
890                                 FileNotFoundException inner = ex.InnerException
891                                         as FileNotFoundException;
892                                 Assert.IsNotNull (inner, "#6");
893                                 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
894                                 Assert.IsNotNull (inner.FileName, "#8");
895                                 Assert.AreEqual (tempFile, inner.FileName, "#9");
896                                 Assert.IsNull (inner.InnerException, "#10");
897                                 Assert.IsNotNull (inner.Message, "#11");
898                         }
899                 }
900
901                 [Test] // UploadFile (string, string)
902                 public void UploadFile1_FileName_Null ()
903                 {
904                         WebClient wc = new WebClient ();
905                         try {
906                                 wc.UploadFile ("tp://scheme.notsupported",
907                                         (string) null);
908                                 Assert.Fail ("#1");
909                         } catch (ArgumentNullException ex) {
910                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
911                                 Assert.IsNull (ex.InnerException, "#3");
912                                 Assert.IsNotNull (ex.Message, "#4");
913                                 Assert.IsNotNull (ex.ParamName, "#5");
914                                 Assert.AreEqual ("fileName", ex.ParamName, "#6");
915                         }
916                 }
917
918                 [Test] // UploadFile (Uri, string)
919                 public void UploadFile2_Address_Null ()
920                 {
921                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
922
923                         WebClient wc = new WebClient ();
924                         try {
925                                 wc.UploadFile ((Uri) null, tempFile);
926                                 Assert.Fail ("#1");
927                         } catch (ArgumentNullException ex) {
928                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
929                                 Assert.IsNull (ex.InnerException, "#3");
930                                 Assert.IsNotNull (ex.Message, "#4");
931                                 Assert.IsNotNull (ex.ParamName, "#5");
932                                 Assert.AreEqual ("address", ex.ParamName, "#6");
933                         }
934                 }
935
936                 [Test] // UploadFile (Uri, string)
937                 public void UploadFile2_Address_SchemeNotSupported ()
938                 {
939                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
940                         File.Create (tempFile).Close ();
941
942                         WebClient wc = new WebClient ();
943                         try {
944                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
945                                         tempFile);
946                                 Assert.Fail ("#1");
947                         } catch (WebException ex) {
948                                 // An error occurred performing a WebClient request
949                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
950                                 Assert.IsNotNull (ex.InnerException, "#3");
951                                 Assert.IsNotNull (ex.Message, "#4");
952                                 Assert.IsNull (ex.Response, "#5");
953                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
954
955                                 // The URI prefix is not recognized
956                                 Exception inner = ex.InnerException;
957                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
958                                 Assert.IsNull (inner.InnerException, "#8");
959                                 Assert.IsNotNull (inner.Message, "#9");
960                         }
961                 }
962
963                 [Test] // UploadFile (Uri, string)
964                 public void UploadFile2_FileName_NotFound ()
965                 {
966                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
967
968                         WebClient wc = new WebClient ();
969                         try {
970                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
971                                         tempFile);
972                                 Assert.Fail ("#1");
973                         } catch (WebException ex) {
974                                 // An error occurred performing a WebClient request
975                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
976                                 Assert.IsNotNull (ex.Message, "#3");
977                                 Assert.IsNull (ex.Response, "#4");
978                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
979
980                                 // Could not find file "..."
981                                 FileNotFoundException inner = ex.InnerException
982                                         as FileNotFoundException;
983                                 Assert.IsNotNull (inner, "#6");
984                                 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
985                                 Assert.IsNotNull (inner.FileName, "#8");
986                                 Assert.AreEqual (tempFile, inner.FileName, "#9");
987                                 Assert.IsNull (inner.InnerException, "#10");
988                                 Assert.IsNotNull (inner.Message, "#11");
989                         }
990                 }
991
992                 [Test] // UploadFile (Uri, string)
993                 public void UploadFile2_FileName_Null ()
994                 {
995                         WebClient wc = new WebClient ();
996                         try {
997                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
998                                         null);
999                                 Assert.Fail ("#1");
1000                         } catch (ArgumentNullException ex) {
1001                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1002                                 Assert.IsNull (ex.InnerException, "#3");
1003                                 Assert.IsNotNull (ex.Message, "#4");
1004                                 Assert.IsNotNull (ex.ParamName, "#5");
1005                                 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1006                         }
1007                 }
1008
1009                 [Test] // UploadFile (string, string, string)
1010                 public void UploadFile3_Address_Null ()
1011                 {
1012                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1013                         File.Create (tempFile).Close ();
1014
1015                         WebClient wc = new WebClient ();
1016                         try {
1017                                 wc.UploadFile ((string) null, "POST", tempFile);
1018                                 Assert.Fail ("#1");
1019                         } catch (ArgumentNullException ex) {
1020                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1021                                 Assert.IsNull (ex.InnerException, "#3");
1022                                 Assert.IsNotNull (ex.Message, "#4");
1023                                 Assert.IsNotNull (ex.ParamName, "#5");
1024                                 Assert.AreEqual ("path", ex.ParamName, "#6");
1025                         }
1026                 }
1027
1028                 [Test] // UploadFile (string, string, string)
1029                 public void UploadFile3_Address_SchemeNotSupported ()
1030                 {
1031                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1032                         File.Create (tempFile).Close ();
1033
1034                         WebClient wc = new WebClient ();
1035                         try {
1036                                 wc.UploadFile ("tp://scheme.notsupported",
1037                                         "POST", tempFile);
1038                                 Assert.Fail ("#1");
1039                         } catch (WebException ex) {
1040                                 // An error occurred performing a WebClient request
1041                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1042                                 Assert.IsNotNull (ex.InnerException, "#3");
1043                                 Assert.IsNotNull (ex.Message, "#4");
1044                                 Assert.IsNull (ex.Response, "#5");
1045                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1046
1047                                 // The URI prefix is not recognized
1048                                 Exception inner = ex.InnerException;
1049                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1050                                 Assert.IsNull (inner.InnerException, "#8");
1051                                 Assert.IsNotNull (inner.Message, "#9");
1052                         }
1053                 }
1054
1055                 [Test] // UploadFile (string, string, string)
1056                 public void UploadFile3_FileName_NotFound ()
1057                 {
1058                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1059
1060                         WebClient wc = new WebClient ();
1061                         try {
1062                                 wc.UploadFile ("tp://scheme.notsupported",
1063                                         "POST", tempFile);
1064                                 Assert.Fail ("#1");
1065                         } catch (WebException ex) {
1066                                 // An error occurred performing a WebClient request
1067                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1068                                 Assert.IsNotNull (ex.Message, "#3");
1069                                 Assert.IsNull (ex.Response, "#4");
1070                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1071
1072                                 // Could not find file "..."
1073                                 FileNotFoundException inner = ex.InnerException
1074                                         as FileNotFoundException;
1075                                 Assert.IsNotNull (inner, "#6");
1076                                 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1077                                 Assert.IsNotNull (inner.FileName, "#8");
1078                                 Assert.AreEqual (tempFile, inner.FileName, "#9");
1079                                 Assert.IsNull (inner.InnerException, "#10");
1080                                 Assert.IsNotNull (inner.Message, "#11");
1081                         }
1082                 }
1083
1084                 [Test] // UploadFile (string, string, string)
1085                 public void UploadFile3_FileName_Null ()
1086                 {
1087                         WebClient wc = new WebClient ();
1088                         try {
1089                                 wc.UploadFile ("tp://scheme.notsupported",
1090                                         "POST", (string) null);
1091                                 Assert.Fail ("#1");
1092                         } catch (ArgumentNullException ex) {
1093                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1094                                 Assert.IsNull (ex.InnerException, "#3");
1095                                 Assert.IsNotNull (ex.Message, "#4");
1096                                 Assert.IsNotNull (ex.ParamName, "#5");
1097                                 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1098                         }
1099                 }
1100
1101                 [Test] // UploadFile (Uri, string, string)
1102                 public void UploadFile4_Address_Null ()
1103                 {
1104                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1105
1106                         WebClient wc = new WebClient ();
1107                         try {
1108                                 wc.UploadFile ((Uri) null, "POST", tempFile);
1109                                 Assert.Fail ("#1");
1110                         } catch (ArgumentNullException ex) {
1111                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1112                                 Assert.IsNull (ex.InnerException, "#3");
1113                                 Assert.IsNotNull (ex.Message, "#4");
1114                                 Assert.IsNotNull (ex.ParamName, "#5");
1115                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1116                         }
1117                 }
1118
1119                 [Test] // UploadFile (Uri, string, string)
1120                 public void UploadFile4_Address_SchemeNotSupported ()
1121                 {
1122                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1123                         File.Create (tempFile).Close ();
1124
1125                         WebClient wc = new WebClient ();
1126                         try {
1127                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1128                                         "POST", tempFile);
1129                                 Assert.Fail ("#1");
1130                         } catch (WebException ex) {
1131                                 // An error occurred performing a WebClient request
1132                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1133                                 Assert.IsNotNull (ex.InnerException, "#3");
1134                                 Assert.IsNotNull (ex.Message, "#4");
1135                                 Assert.IsNull (ex.Response, "#5");
1136                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1137
1138                                 // The URI prefix is not recognized
1139                                 Exception inner = ex.InnerException;
1140                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1141                                 Assert.IsNull (inner.InnerException, "#8");
1142                                 Assert.IsNotNull (inner.Message, "#9");
1143                         }
1144                 }
1145
1146                 [Test] // UploadFile (Uri, string, string)
1147                 public void UploadFile4_FileName_NotFound ()
1148                 {
1149                         string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1150
1151                         WebClient wc = new WebClient ();
1152                         try {
1153                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1154                                         "POST", tempFile);
1155                                 Assert.Fail ("#1");
1156                         } catch (WebException ex) {
1157                                 // An error occurred performing a WebClient request
1158                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1159                                 Assert.IsNotNull (ex.Message, "#3");
1160                                 Assert.IsNull (ex.Response, "#4");
1161                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#5");
1162
1163                                 // Could not find file "..."
1164                                 FileNotFoundException inner = ex.InnerException
1165                                         as FileNotFoundException;
1166                                 Assert.IsNotNull (inner, "#6");
1167                                 Assert.AreEqual (typeof (FileNotFoundException), inner.GetType (), "#7");
1168                                 Assert.IsNotNull (inner.FileName, "#8");
1169                                 Assert.AreEqual (tempFile, inner.FileName, "#9");
1170                                 Assert.IsNull (inner.InnerException, "#10");
1171                                 Assert.IsNotNull (inner.Message, "#11");
1172                         }
1173                 }
1174
1175                 [Test] // UploadFile (Uri, string, string)
1176                 public void UploadFile4_FileName_Null ()
1177                 {
1178                         WebClient wc = new WebClient ();
1179                         try {
1180                                 wc.UploadFile (new Uri ("tp://scheme.notsupported"),
1181                                         "POST", (string) null);
1182                                 Assert.Fail ("#1");
1183                         } catch (ArgumentNullException ex) {
1184                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1185                                 Assert.IsNull (ex.InnerException, "#3");
1186                                 Assert.IsNotNull (ex.Message, "#4");
1187                                 Assert.IsNotNull (ex.ParamName, "#5");
1188                                 Assert.AreEqual ("fileName", ex.ParamName, "#6");
1189                         }
1190                 }
1191
1192                 [Test] // UploadString (string, string)
1193                 public void UploadString1_Address_Null ()
1194                 {
1195                         WebClient wc = new WebClient ();
1196                         try {
1197                                 wc.UploadString ((string) null, (string) null);
1198                                 Assert.Fail ("#1");
1199                         } catch (ArgumentNullException ex) {
1200                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1201                                 Assert.IsNull (ex.InnerException, "#3");
1202                                 Assert.IsNotNull (ex.Message, "#4");
1203                                 Assert.IsNotNull (ex.ParamName, "#5");
1204                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1205                         }
1206                 }
1207
1208                 [Test] // UploadString (string, string)
1209                 public void UploadString1_Address_SchemeNotSupported ()
1210                 {
1211                         WebClient wc = new WebClient ();
1212                         try {
1213                                 wc.UploadString ("tp://scheme.notsupported", "abc");
1214                                 Assert.Fail ("#1");
1215                         } catch (WebException ex) {
1216                                 // An error occurred performing a WebClient request
1217                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1218                                 Assert.IsNotNull (ex.InnerException, "#3");
1219                                 Assert.IsNotNull (ex.Message, "#4");
1220                                 Assert.IsNull (ex.Response, "#5");
1221                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1222
1223                                 // The URI prefix is not recognized
1224                                 Exception inner = ex.InnerException;
1225                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1226                                 Assert.IsNull (inner.InnerException, "#8");
1227                                 Assert.IsNotNull (inner.Message, "#9");
1228                         }
1229                 }
1230
1231                 [Test] // UploadString (string, string)
1232                 public void UploadString1_Data_Null ()
1233                 {
1234                         WebClient wc = new WebClient ();
1235                         try {
1236                                 wc.UploadString ("tp://scheme.notsupported", (string) null);
1237                                 Assert.Fail ("#1");
1238                         } catch (ArgumentNullException ex) {
1239                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1240                                 Assert.IsNull (ex.InnerException, "#3");
1241                                 Assert.IsNotNull (ex.Message, "#4");
1242                                 Assert.IsNotNull (ex.ParamName, "#5");
1243                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1244                         }
1245                 }
1246
1247                 [Test] // UploadString (Uri, string)
1248                 public void UploadString2_Address_Null ()
1249                 {
1250                         WebClient wc = new WebClient ();
1251                         try {
1252                                 wc.UploadString ((Uri) null, (string) null);
1253                                 Assert.Fail ("#1");
1254                         } catch (ArgumentNullException ex) {
1255                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1256                                 Assert.IsNull (ex.InnerException, "#3");
1257                                 Assert.IsNotNull (ex.Message, "#4");
1258                                 Assert.IsNotNull (ex.ParamName, "#5");
1259                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1260                         }
1261                 }
1262
1263                 [Test] // UploadString (Uri, string)
1264                 public void UploadString2_Address_SchemeNotSupported ()
1265                 {
1266                         WebClient wc = new WebClient ();
1267                         try {
1268                                 wc.UploadString (new Uri ("tp://scheme.notsupported"), "abc");
1269                                 Assert.Fail ("#1");
1270                         } catch (WebException ex) {
1271                                 // An error occurred performing a WebClient request
1272                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1273                                 Assert.IsNotNull (ex.InnerException, "#3");
1274                                 Assert.IsNotNull (ex.Message, "#4");
1275                                 Assert.IsNull (ex.Response, "#5");
1276                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1277
1278                                 // The URI prefix is not recognized
1279                                 Exception inner = ex.InnerException;
1280                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1281                                 Assert.IsNull (inner.InnerException, "#8");
1282                                 Assert.IsNotNull (inner.Message, "#9");
1283                         }
1284                 }
1285
1286                 [Test] // UploadString (Uri, string)
1287                 public void UploadString2_Data_Null ()
1288                 {
1289                         WebClient wc = new WebClient ();
1290                         try {
1291                                 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1292                                         (string) null);
1293                                 Assert.Fail ("#1");
1294                         } catch (ArgumentNullException ex) {
1295                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1296                                 Assert.IsNull (ex.InnerException, "#3");
1297                                 Assert.IsNotNull (ex.Message, "#4");
1298                                 Assert.IsNotNull (ex.ParamName, "#5");
1299                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1300                         }
1301                 }
1302
1303                 [Test] // UploadString (string, string, string)
1304                 public void UploadString3_Address_Null ()
1305                 {
1306                         WebClient wc = new WebClient ();
1307                         try {
1308                                 wc.UploadString ((string) null, (string) null,
1309                                         (string) null);
1310                                 Assert.Fail ("#1");
1311                         } catch (ArgumentNullException ex) {
1312                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1313                                 Assert.IsNull (ex.InnerException, "#3");
1314                                 Assert.IsNotNull (ex.Message, "#4");
1315                                 Assert.IsNotNull (ex.ParamName, "#5");
1316                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1317                         }
1318                 }
1319
1320                 [Test] // UploadString (string, string, string)
1321                 public void UploadString3_Address_SchemeNotSupported ()
1322                 {
1323                         WebClient wc = new WebClient ();
1324                         try {
1325                                 wc.UploadString ("tp://scheme.notsupported",
1326                                         "POST", "abc");
1327                                 Assert.Fail ("#1");
1328                         } catch (WebException ex) {
1329                                 // An error occurred performing a WebClient request
1330                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1331                                 Assert.IsNotNull (ex.InnerException, "#3");
1332                                 Assert.IsNotNull (ex.Message, "#4");
1333                                 Assert.IsNull (ex.Response, "#5");
1334                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1335
1336                                 // The URI prefix is not recognized
1337                                 Exception inner = ex.InnerException;
1338                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1339                                 Assert.IsNull (inner.InnerException, "#8");
1340                                 Assert.IsNotNull (inner.Message, "#9");
1341                         }
1342                 }
1343
1344                 [Test] // UploadString (string, string, string)
1345                 public void UploadString3_Data_Null ()
1346                 {
1347                         WebClient wc = new WebClient ();
1348                         try {
1349                                 wc.UploadString ("tp://scheme.notsupported",
1350                                         "POST", (string) null);
1351                                 Assert.Fail ("#1");
1352                         } catch (ArgumentNullException ex) {
1353                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1354                                 Assert.IsNull (ex.InnerException, "#3");
1355                                 Assert.IsNotNull (ex.Message, "#4");
1356                                 Assert.IsNotNull (ex.ParamName, "#5");
1357                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1358                         }
1359                 }
1360
1361                 [Test] // UploadString (Uri, string, string)
1362                 public void UploadString4_Address_Null ()
1363                 {
1364                         WebClient wc = new WebClient ();
1365                         try {
1366                                 wc.UploadString ((Uri) null, (string) null,
1367                                         (string) null);
1368                                 Assert.Fail ("#1");
1369                         } catch (ArgumentNullException ex) {
1370                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1371                                 Assert.IsNull (ex.InnerException, "#3");
1372                                 Assert.IsNotNull (ex.Message, "#4");
1373                                 Assert.IsNotNull (ex.ParamName, "#5");
1374                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1375                         }
1376                 }
1377
1378                 [Test] // UploadString (Uri, string, string)
1379                 public void UploadString4_Address_SchemeNotSupported ()
1380                 {
1381                         WebClient wc = new WebClient ();
1382                         try {
1383                                 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1384                                         "POST", "abc");
1385                                 Assert.Fail ("#1");
1386                         } catch (WebException ex) {
1387                                 // An error occurred performing a WebClient request
1388                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1389                                 Assert.IsNotNull (ex.InnerException, "#3");
1390                                 Assert.IsNotNull (ex.Message, "#4");
1391                                 Assert.IsNull (ex.Response, "#5");
1392                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1393
1394                                 // The URI prefix is not recognized
1395                                 Exception inner = ex.InnerException;
1396                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1397                                 Assert.IsNull (inner.InnerException, "#8");
1398                                 Assert.IsNotNull (inner.Message, "#9");
1399                         }
1400                 }
1401
1402                 [Test] // UploadString (Uri, string, string)
1403                 public void UploadString4_Data_Null ()
1404                 {
1405                         WebClient wc = new WebClient ();
1406                         try {
1407                                 wc.UploadString (new Uri ("tp://scheme.notsupported"),
1408                                         "POST", (string) null);
1409                                 Assert.Fail ("#1");
1410                         } catch (ArgumentNullException ex) {
1411                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1412                                 Assert.IsNull (ex.InnerException, "#3");
1413                                 Assert.IsNotNull (ex.Message, "#4");
1414                                 Assert.IsNotNull (ex.ParamName, "#5");
1415                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1416                         }
1417                 }
1418
1419                 [Test]
1420                 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1421 #if FEATURE_NO_BSD_SOCKETS
1422                 [ExpectedException (typeof (PlatformNotSupportedException))]
1423 #endif
1424                 public void UploadValues1 ()
1425                 {
1426                         IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
1427                         string url = "http://" + ep.ToString () + "/test/";
1428
1429                         using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) {
1430                                 WebClient wc = new WebClient ();
1431                                 wc.Encoding = Encoding.ASCII;
1432
1433                                 NameValueCollection nvc = new NameValueCollection ();
1434                                 nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
1435                                 nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
1436
1437                                 byte [] buffer = wc.UploadValues (url, nvc);
1438                                 string response = Encoding.UTF8.GetString (buffer);
1439                                 Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
1440                         }
1441                 }
1442
1443                 [Test] // UploadValues (string, NameValueCollection)
1444                 public void UploadValues1_Address_Null ()
1445                 {
1446                         WebClient wc = new WebClient ();
1447                         try {
1448                                 wc.UploadValues ((string) null, new NameValueCollection ());
1449                                 Assert.Fail ("#1");
1450                         } catch (ArgumentNullException ex) {
1451                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1452                                 Assert.IsNull (ex.InnerException, "#3");
1453                                 Assert.IsNotNull (ex.Message, "#4");
1454                                 Assert.IsNotNull (ex.ParamName, "#5");
1455                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1456                         }
1457                 }
1458
1459                 [Test] // UploadValues (string, NameValueCollection)
1460                 public void UploadValues1_Address_SchemeNotSupported ()
1461                 {
1462                         WebClient wc = new WebClient ();
1463                         try {
1464                                 wc.UploadValues ("tp://scheme.notsupported",
1465                                         new NameValueCollection ());
1466                                 Assert.Fail ("#1");
1467                         } catch (WebException ex) {
1468                                 // An error occurred performing a WebClient request
1469                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1470                                 Assert.IsNotNull (ex.InnerException, "#3");
1471                                 Assert.IsNotNull (ex.Message, "#4");
1472                                 Assert.IsNull (ex.Response, "#5");
1473                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1474
1475                                 // The URI prefix is not recognized
1476                                 Exception inner = ex.InnerException;
1477                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1478                                 Assert.IsNull (inner.InnerException, "#8");
1479                                 Assert.IsNotNull (inner.Message, "#9");
1480                         }
1481                 }
1482
1483                 [Test] // UploadValues (string, NameValueCollection)
1484                 public void UploadValues1_Data_Null ()
1485                 {
1486                         WebClient wc = new WebClient ();
1487                         try {
1488                                 wc.UploadValues ("http://www.mono-project.com",
1489                                         (NameValueCollection) null);
1490                                 Assert.Fail ("#1");
1491                         } catch (ArgumentNullException ex) {
1492                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1493                                 Assert.IsNull (ex.InnerException, "#3");
1494                                 Assert.IsNotNull (ex.Message, "#4");
1495                                 Assert.IsNotNull (ex.ParamName, "#5");
1496                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1497                         }
1498                 }
1499
1500                 [Test] // UploadValues (Uri, NameValueCollection)
1501                 public void UploadValues2_Address_Null ()
1502                 {
1503                         WebClient wc = new WebClient ();
1504                         try {
1505                                 wc.UploadValues ((Uri) null, new NameValueCollection ());
1506                                 Assert.Fail ("#1");
1507                         } catch (ArgumentNullException ex) {
1508                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1509                                 Assert.IsNull (ex.InnerException, "#3");
1510                                 Assert.IsNotNull (ex.Message, "#4");
1511                                 Assert.IsNotNull (ex.ParamName, "#5");
1512                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1513                         }
1514                 }
1515
1516                 [Test] // UploadValues (Uri, NameValueCollection)
1517                 public void UploadValues2_Address_SchemeNotSupported ()
1518                 {
1519                         WebClient wc = new WebClient ();
1520                         try {
1521                                 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1522                                         new NameValueCollection ());
1523                                 Assert.Fail ("#1");
1524                         } catch (WebException ex) {
1525                                 // An error occurred performing a WebClient request
1526                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1527                                 Assert.IsNotNull (ex.InnerException, "#3");
1528                                 Assert.IsNotNull (ex.Message, "#4");
1529                                 Assert.IsNull (ex.Response, "#5");
1530                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1531
1532                                 // The URI prefix is not recognized
1533                                 Exception inner = ex.InnerException;
1534                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1535                                 Assert.IsNull (inner.InnerException, "#8");
1536                                 Assert.IsNotNull (inner.Message, "#9");
1537                         }
1538                 }
1539
1540                 [Test] // UploadValues (Uri, NameValueCollection)
1541                 public void UploadValues2_Data_Null ()
1542                 {
1543                         WebClient wc = new WebClient ();
1544                         try {
1545                                 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1546                                         (NameValueCollection) null);
1547                                 Assert.Fail ("#1");
1548                         } catch (ArgumentNullException ex) {
1549                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1550                                 Assert.IsNull (ex.InnerException, "#3");
1551                                 Assert.IsNotNull (ex.Message, "#4");
1552                                 Assert.IsNotNull (ex.ParamName, "#5");
1553                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1554                         }
1555                 }
1556
1557                 [Test] // UploadValues (string, string, NameValueCollection)
1558                 public void UploadValues3_Address_Null ()
1559                 {
1560                         WebClient wc = new WebClient ();
1561                         try {
1562                                 wc.UploadValues ((string) null, "POST",
1563                                         new NameValueCollection ());
1564                                 Assert.Fail ("#1");
1565                         } catch (ArgumentNullException ex) {
1566                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1567                                 Assert.IsNull (ex.InnerException, "#3");
1568                                 Assert.IsNotNull (ex.Message, "#4");
1569                                 Assert.IsNotNull (ex.ParamName, "#5");
1570                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1571                         }
1572                 }
1573
1574                 [Test] // UploadValues (string, string, NameValueCollection)
1575                 public void UploadValues3_Address_SchemeNotSupported ()
1576                 {
1577                         WebClient wc = new WebClient ();
1578                         try {
1579                                 wc.UploadValues ("tp://scheme.notsupported",
1580                                         "POST", new NameValueCollection ());
1581                                 Assert.Fail ("#1");
1582                         } catch (WebException ex) {
1583                                 // An error occurred performing a WebClient request
1584                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1585                                 Assert.IsNotNull (ex.InnerException, "#3");
1586                                 Assert.IsNotNull (ex.Message, "#4");
1587                                 Assert.IsNull (ex.Response, "#5");
1588                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1589
1590                                 // The URI prefix is not recognized
1591                                 Exception inner = ex.InnerException;
1592                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1593                                 Assert.IsNull (inner.InnerException, "#8");
1594                                 Assert.IsNotNull (inner.Message, "#9");
1595                         }
1596                 }
1597
1598                 [Test] // UploadValues (string, string, NameValueCollection)
1599                 public void UploadValues3_Data_Null ()
1600                 {
1601                         WebClient wc = new WebClient ();
1602                         try {
1603                                 wc.UploadValues ("http://www.mono-project.com",
1604                                         "POST", (NameValueCollection) null);
1605                                 Assert.Fail ("#1");
1606                         } catch (ArgumentNullException ex) {
1607                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1608                                 Assert.IsNull (ex.InnerException, "#3");
1609                                 Assert.IsNotNull (ex.Message, "#4");
1610                                 Assert.IsNotNull (ex.ParamName, "#5");
1611                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1612                         }
1613                 }
1614
1615                 [Test] // UploadValues (Uri, string, NameValueCollection)
1616                 public void UploadValues4_Address_Null ()
1617                 {
1618                         WebClient wc = new WebClient ();
1619                         try {
1620                                 wc.UploadValues ((Uri) null, "POST",
1621                                         new NameValueCollection ());
1622                                 Assert.Fail ("#1");
1623                         } catch (ArgumentNullException ex) {
1624                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1625                                 Assert.IsNull (ex.InnerException, "#3");
1626                                 Assert.IsNotNull (ex.Message, "#4");
1627                                 Assert.IsNotNull (ex.ParamName, "#5");
1628                                 Assert.AreEqual ("address", ex.ParamName, "#6");
1629                         }
1630                 }
1631
1632                 [Test] // UploadValues (Uri, string, NameValueCollection)
1633                 public void UploadValues4_Address_SchemeNotSupported ()
1634                 {
1635                         WebClient wc = new WebClient ();
1636                         try {
1637                                 wc.UploadValues (new Uri ("tp://scheme.notsupported"),
1638                                         "POST", new NameValueCollection ());
1639                                 Assert.Fail ("#1");
1640                         } catch (WebException ex) {
1641                                 // An error occurred performing a WebClient request
1642                                 Assert.AreEqual (typeof (WebException), ex.GetType (), "#2");
1643                                 Assert.IsNotNull (ex.InnerException, "#3");
1644                                 Assert.IsNotNull (ex.Message, "#4");
1645                                 Assert.IsNull (ex.Response, "#5");
1646                                 Assert.AreEqual (WebExceptionStatus.UnknownError, ex.Status, "#6");
1647
1648                                 // The URI prefix is not recognized
1649                                 Exception inner = ex.InnerException;
1650                                 Assert.AreEqual (typeof (NotSupportedException), inner.GetType (), "#7");
1651                                 Assert.IsNull (inner.InnerException, "#8");
1652                                 Assert.IsNotNull (inner.Message, "#9");
1653                         }
1654                 }
1655
1656                 [Test] // UploadValues (Uri, string, NameValueCollection)
1657                 public void UploadValues4_Data_Null ()
1658                 {
1659                         WebClient wc = new WebClient ();
1660                         try {
1661                                 wc.UploadValues (new Uri ("http://www.mono-project.com"),
1662                                         "POST", (NameValueCollection) null);
1663                                 Assert.Fail ("#1");
1664                         } catch (ArgumentNullException ex) {
1665                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1666                                 Assert.IsNull (ex.InnerException, "#3");
1667                                 Assert.IsNotNull (ex.Message, "#4");
1668                                 Assert.IsNotNull (ex.ParamName, "#5");
1669                                 Assert.AreEqual ("data", ex.ParamName, "#6");
1670                         }
1671                 }
1672
1673                 [Test]
1674 #if FEATURE_NO_BSD_SOCKETS
1675                 // We throw a PlatformNotSupportedException deeper, which is caught and re-thrown as WebException
1676                 [ExpectedException (typeof (WebException))]
1677 #endif
1678                 public void GetWebRequestOverriding ()
1679                 {
1680                         GetWebRequestOverridingTestClass testObject = new GetWebRequestOverridingTestClass ();
1681                         testObject.DownloadData ("http://www.mono-project.com");
1682
1683                         Assert.IsTrue (testObject.overridedCodeRan, "Overrided code wasn't called");
1684                 }
1685                 
1686                 class GetWebRequestOverridingTestClass : WebClient
1687                 {
1688                         internal bool overridedCodeRan = false;
1689                         protected override WebRequest GetWebRequest(Uri address)
1690                         {
1691                                 overridedCodeRan = true;
1692                                 return base.GetWebRequest (address);
1693                         }
1694                 }
1695
1696                 static byte [] EchoRequestHandler (Socket socket)
1697                 {
1698                         MemoryStream ms = new MemoryStream ();
1699                         byte [] buffer = new byte [4096];
1700                         int bytesReceived = socket.Receive (buffer);
1701                         while (bytesReceived > 0) {
1702                                 ms.Write (buffer, 0, bytesReceived);
1703                                  // We don't check for Content-Length or anything else here, so we give the client a little time to write
1704                                  // after sending the headers
1705                                 Thread.Sleep (200);
1706                                 if (socket.Available > 0) {
1707                                         bytesReceived = socket.Receive (buffer);
1708                                 } else {
1709                                         bytesReceived = 0;
1710                                 }
1711                         }
1712                         ms.Flush ();
1713                         ms.Position = 0;
1714
1715                         StringBuilder sb = new StringBuilder ();
1716
1717                         string expect = null;
1718
1719                         StreamReader sr = new StreamReader (ms, Encoding.UTF8);
1720                         string line = null;
1721                         byte state = 0;
1722                         while ((line = sr.ReadLine ()) != null) {
1723                                 if (state > 0) {
1724                                         state = 2;
1725                                         sb.Append (line);
1726                                         sb.Append ("\r\n");
1727                                 } if (line.Length == 0) {
1728                                         state = 1;
1729                                 } else if (line.StartsWith ("Expect:")) {
1730                                         expect = line.Substring (8);
1731                                 }
1732                         }
1733
1734                         StringWriter sw = new StringWriter ();
1735
1736                         if (expect == "100-continue" && state != 2) {
1737                                 sw.WriteLine ("HTTP/1.1 100 Continue");
1738                                 sw.WriteLine ();
1739                                 sw.Flush ();
1740
1741                                 socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
1742
1743                                 // receive body
1744                                 ms = new MemoryStream ();
1745                                 buffer = new byte [4096];
1746                                 bytesReceived = socket.Receive (buffer);
1747                                 while (bytesReceived > 0) {
1748                                         ms.Write (buffer, 0, bytesReceived);
1749                                         Thread.Sleep (200);
1750                                         if (socket.Available > 0) {
1751                                                 bytesReceived = socket.Receive (buffer);
1752                                         } else {
1753                                                 bytesReceived = 0;
1754                                         }
1755                                 }
1756                                 ms.Flush ();
1757                                 ms.Position = 0;
1758
1759                                 sb = new StringBuilder ();
1760                                 sr = new StreamReader (ms, Encoding.UTF8);
1761                                 line = sr.ReadLine ();
1762                                 while (line != null) {
1763                                         sb.Append (line);
1764                                         sb.Append ("\r\n");
1765                                         line = sr.ReadLine ();
1766                                 }
1767                         }
1768
1769                         sw = new StringWriter ();
1770                         sw.WriteLine ("HTTP/1.1 200 OK");
1771                         sw.WriteLine ("Content-Type: text/xml");
1772                         sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
1773                         sw.WriteLine ();
1774                         sw.Write (sb.ToString ());
1775                         sw.Flush ();
1776
1777                         return Encoding.UTF8.GetBytes (sw.ToString ());
1778                 }
1779
1780                 [Test]
1781 #if FEATURE_NO_BSD_SOCKETS
1782                 [ExpectedException (typeof (PlatformNotSupportedException))]
1783 #endif
1784                 public void DefaultProxy ()
1785                 {
1786                         WebClient wc = new WebClient ();
1787                         // this is never null on .net
1788                         Assert.IsNotNull (wc.Proxy);
1789                         // and return the same instance as WebRequest.DefaultWebProxy
1790                         Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
1791                 }
1792                  
1793                 [Test]
1794                 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1795 #if FEATURE_NO_BSD_SOCKETS
1796                 [ExpectedException (typeof (PlatformNotSupportedException))]
1797 #endif
1798                 public void UploadStringAsyncCancelEvent ()
1799                 {
1800                         UploadAsyncCancelEventTest (9301, (webClient, uri, cancelEvent) =>
1801                         {
1802
1803                                 webClient.UploadStringCompleted += (sender, args) =>
1804                                 {
1805                                         if (args.Cancelled)
1806                                                 cancelEvent.Set ();
1807                                 };
1808
1809                                 webClient.UploadStringAsync (uri, "PUT", "text");
1810                         });
1811                 }
1812
1813                 [Test]
1814                 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1815 #if FEATURE_NO_BSD_SOCKETS
1816                 [ExpectedException (typeof (PlatformNotSupportedException))]
1817 #endif
1818                 public void UploadDataAsyncCancelEvent ()
1819                 {
1820                         UploadAsyncCancelEventTest (9302, (webClient, uri, cancelEvent) =>
1821                         {
1822                                 webClient.UploadDataCompleted += (sender, args) =>
1823                                 {
1824                                         if (args.Cancelled)
1825                                                 cancelEvent.Set ();
1826                                 };
1827
1828                                 webClient.UploadDataAsync (uri, "PUT", new byte[] { });
1829                         });
1830                 }
1831                 
1832                 [Test]
1833                 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1834 #if FEATURE_NO_BSD_SOCKETS
1835                 [ExpectedException (typeof (PlatformNotSupportedException))]
1836 #endif
1837                 public void UploadValuesAsyncCancelEvent ()
1838                 {
1839                         UploadAsyncCancelEventTest (9303, (webClient, uri, cancelEvent) =>
1840                         {
1841                                 webClient.UploadValuesCompleted += (sender, args) =>
1842                                 {
1843                                         if (args.Cancelled)
1844                                                 cancelEvent.Set ();
1845                                 };
1846
1847                                 webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
1848                         });
1849                 }
1850
1851                 [Test]
1852                 [Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
1853 #if FEATURE_NO_BSD_SOCKETS
1854                 [ExpectedException (typeof (PlatformNotSupportedException))]
1855 #endif
1856                 public void UploadFileAsyncCancelEvent ()
1857                 {
1858                         UploadAsyncCancelEventTest (9304,(webClient, uri, cancelEvent) =>
1859                         {
1860                                 string tempFile = Path.Combine (_tempFolder, "upload.tmp");
1861                                 File.Create (tempFile).Close ();
1862
1863                                 webClient.UploadFileCompleted += (sender, args) =>
1864                                 {
1865                                         if (args.Cancelled)
1866                                                 cancelEvent.Set ();
1867                                 };
1868
1869                                 webClient.UploadFileAsync (uri, "PUT", tempFile);
1870                         });
1871                 }
1872
1873                 [Test]
1874                 [Category ("AndroidNotWorking")] // Test suite hangs if the tests runs as part of the entire BCL suite. Works when only this fixture is ran
1875 #if FEATURE_NO_BSD_SOCKETS
1876                 [ExpectedException (typeof (PlatformNotSupportedException))]
1877 #endif
1878                 public void UploadFileAsyncContentType ()
1879                 {
1880                         var port = NetworkHelpers.FindFreePort ();
1881                         var serverUri = "http://localhost:" + port + "/";
1882                         var filename = Path.GetTempFileName ();
1883
1884                         HttpListener listener = new HttpListener ();
1885                         listener.Prefixes.Add (serverUri);
1886                         listener.Start ();
1887
1888                         using (var client = new WebClient ())
1889                         {
1890                                 client.UploadFileTaskAsync (new Uri (serverUri), filename);
1891                                 var request = listener.GetContext ().Request;
1892
1893                                 var expected = "multipart/form-data; boundary=---------------------";
1894                                 Assert.AreEqual (expected.Length + 15, request.ContentType.Length);
1895                                 Assert.AreEqual (expected, request.ContentType.Substring (0, expected.Length));
1896                         }
1897                         listener.Close ();
1898                 }
1899
1900                 public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
1901                 {
1902                         var ep = NetworkHelpers.LocalEphemeralEndPoint ();
1903                         string url = "http://" + ep.ToString() + "/test/";
1904
1905                         using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s)))
1906                         {
1907                                 var webClient = new WebClient ();
1908
1909                                 var cancellationTokenSource = new CancellationTokenSource ();
1910                                 cancellationTokenSource.Token.Register (webClient.CancelAsync);
1911
1912                                 var cancelEvent = new ManualResetEvent (false);
1913
1914                                 uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
1915
1916                                 cancellationTokenSource.Cancel ();
1917
1918                                 Assert.IsTrue (cancelEvent.WaitOne (1000));
1919                         }
1920                 }
1921         }
1922 }