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