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