Added tests for Task.WhenAll w/ empty list
[mono.git] / mcs / class / System.Net.Http / Test / System.Net.Http / HttpRequestMessageTest.cs
1 //
2 // HttpRequestMessageTest.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
6 //
7 // Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Text.RegularExpressions;
33 using NUnit.Framework;
34 using System.Net.Http;
35 using System.Net;
36 using System.Net.Http.Headers;
37 using System.Linq;
38
39 namespace MonoTests.System.Net.Http
40 {
41         [TestFixture]
42         public class HttpRequestMessageTest
43         {
44                 [Test]
45                 public void Ctor_Invalid ()
46                 {
47                         try {
48                                 new HttpRequestMessage (null, "");
49                                 Assert.Fail ("#1");
50                         } catch (ArgumentNullException) {
51                         }
52                 }
53
54                 [Test]
55                 public void Ctor_Default ()
56                 {
57                         var m = new HttpRequestMessage ();
58                         Assert.IsNull (m.Content, "#1");
59                         Assert.IsNotNull (m.Headers, "#2");
60                         Assert.AreEqual (HttpMethod.Get, m.Method, "#3");
61                         Assert.IsNotNull (m.Properties, "#4");
62                         Assert.IsNull (m.RequestUri, "#5");
63                         Assert.AreEqual (new Version (1, 1), m.Version, "#6");
64
65                         Assert.AreEqual ("Method: GET, RequestUri: '<null>', Version: 1.1, Content: <null>, Headers:\r\n{\r\n}", m.ToString (), "#7");
66                 }
67
68                 [Test]
69                 public void Ctor_Uri ()
70                 {
71                         var c = new HttpRequestMessage (HttpMethod.Get, new Uri ("http://xamarin.com"));
72                         Assert.AreEqual ("http://xamarin.com/", c.RequestUri.AbsoluteUri, "#1");
73
74                         c = new HttpRequestMessage (HttpMethod.Get, new Uri ("https://xamarin.com"));
75                         Assert.AreEqual ("https://xamarin.com/", c.RequestUri.AbsoluteUri, "#2");
76
77                         c = new HttpRequestMessage (HttpMethod.Get, new Uri ("HTTP://xamarin.com:8080"));
78                         Assert.AreEqual ("http://xamarin.com:8080/", c.RequestUri.AbsoluteUri, "#3");
79
80                         var a = Uri.UriSchemeHttps;
81                         var b = new Uri ("http://xamarin.com");
82
83                         try {
84                                 new HttpRequestMessage (HttpMethod.Get, new Uri ("ftp://xamarin.com"));
85                                 Assert.Fail ("#4");
86                         } catch (ArgumentException) {
87                         }
88                 }
89
90                 [Test]
91                 public void Ctor_RelativeUri ()
92                 {
93                         var client = new HttpClient ();
94                         client.BaseAddress = new Uri ("http://en.wikipedia.org/wiki/");
95                         var uri = new Uri ("Computer", UriKind.Relative);
96                         var req = new HttpRequestMessage (HttpMethod.Get, uri);
97                         // HttpRequestMessage does not rewrite it here.
98                         Assert.AreEqual (req.RequestUri, uri);
99                 }
100
101                 [Test]
102                 public void Ctor_RelativeUriString ()
103                 {
104                         var client = new HttpClient ();
105                         client.BaseAddress = new Uri ("http://en.wikipedia.org/wiki/");
106                         var req = new HttpRequestMessage (HttpMethod.Get, "Computer");
107                         // HttpRequestMessage does not rewrite it here.
108                         Assert.IsFalse (req.RequestUri.IsAbsoluteUri);
109                 }
110
111                 [Test]
112                 public void Headers ()
113                 {
114                         HttpRequestMessage message = new HttpRequestMessage ();
115                         HttpRequestHeaders headers = message.Headers;
116
117                         headers.Accept.Add (new MediaTypeWithQualityHeaderValue ("audio/x"));
118                         headers.AcceptCharset.Add (new StringWithQualityHeaderValue ("str-v", 0.002));
119                         headers.AcceptEncoding.Add (new StringWithQualityHeaderValue ("str-enc", 0.44));
120                         headers.AcceptLanguage.Add (new StringWithQualityHeaderValue ("str-lang", 0.41));
121                         headers.Authorization = new AuthenticationHeaderValue ("sh-aut", "par");
122                         headers.CacheControl = new CacheControlHeaderValue () {
123                                 MaxAge = TimeSpan.MaxValue
124                         };
125                         headers.Connection.Add ("test-value");
126                         headers.ConnectionClose = true;
127                         headers.Date = new DateTimeOffset (DateTime.Today);
128                         headers.Expect.Add (new NameValueWithParametersHeaderValue ("en", "ev"));
129                         headers.ExpectContinue = true;
130                         headers.From = "webmaster@w3.org";
131                         headers.Host = "host";
132                         headers.IfMatch.Add (new EntityTagHeaderValue ("\"tag\"", true));
133                         headers.IfModifiedSince = new DateTimeOffset (DateTime.Today);
134                         headers.IfNoneMatch.Add (new EntityTagHeaderValue ("\"tag2\"", true));
135                         headers.IfRange = new RangeConditionHeaderValue (new DateTimeOffset (DateTime.Today));
136                         headers.IfUnmodifiedSince = new DateTimeOffset? (DateTimeOffset.Now);
137                         headers.MaxForwards = 0x15b3;
138                         headers.Pragma.Add (new NameValueHeaderValue ("name", "value"));
139                         headers.ProxyAuthorization = new AuthenticationHeaderValue ("s", "p");
140                         headers.Range = new RangeHeaderValue (5L, 30L);
141                         headers.Referrer = new Uri ("http://xamarin.com");
142                         headers.TE.Add (new TransferCodingWithQualityHeaderValue ("TE", 0.3));
143                         headers.Trailer.Add ("value");
144                         headers.TransferEncoding.Add (new TransferCodingHeaderValue ("tchv"));
145                         headers.TransferEncodingChunked = true;
146                         headers.Upgrade.Add (new ProductHeaderValue ("prod", "ver"));
147                         headers.UserAgent.Add (new ProductInfoHeaderValue ("(comment)"));
148                         headers.Via.Add (new ViaHeaderValue ("protocol", "rec-by"));
149                         headers.Warning.Add (new WarningHeaderValue (5, "agent", "\"txt\""));
150
151                         try {
152                                 headers.Add ("authorization", "");
153                                 Assert.Fail ("Authorization");
154                         } catch (FormatException) {
155                         }
156
157                         try {
158                                 headers.Add ("connection", "extra ÃŸ ");
159                                 Assert.Fail ("Date");
160                         } catch (FormatException) {
161                         }
162
163                         try {
164                                 headers.Add ("date", "");
165                                 Assert.Fail ("Date");
166                         } catch (FormatException) {
167                         }
168
169                         try {
170                                 headers.Add ("from", "a@w3.org");
171                                 Assert.Fail ("From");
172                         } catch (FormatException) {
173                         }
174
175                         try {
176                                 headers.Add ("hOst", "host");
177                                 Assert.Fail ("Host");
178                         } catch (FormatException) {
179                         }
180
181                         try {
182                                 headers.Add ("if-modified-since", "");
183                                 Assert.Fail ("if-modified-since");
184                         } catch (FormatException) {
185                         }
186
187                         try {
188                                 headers.Add ("if-range", "");
189                                 Assert.Fail ("if-range");
190                         } catch (FormatException) {
191                         }
192
193                         try {
194                                 headers.Add ("if-unmodified-since", "");
195                                 Assert.Fail ("if-unmodified-since");
196                         } catch (FormatException) {
197                         }
198
199                         try {
200                                 headers.Add ("max-forwards", "");
201                                 Assert.Fail ("max-forwards");
202                         } catch (FormatException) {
203                         }
204
205                         try {
206                                 headers.Add ("proxy-authorization", "");
207                                 Assert.Fail ("proxy-authorization");
208                         } catch (FormatException) {
209                         }
210
211                         try {
212                                 headers.Add ("range", "");
213                         } catch (FormatException) {
214                         }
215
216                         try {
217                                 headers.Add ("referer", "");
218                                 Assert.Fail ("referer");
219                         } catch (FormatException) {
220                         }
221
222                         headers.Add ("accept", "audio/y");
223                         headers.Add ("accept-charset", "achs");
224                         headers.Add ("accept-encoding", "aenc");
225                         headers.Add ("accept-language", "alan");
226                         headers.Add ("expect", "exp");
227                         headers.Add ("if-match", "\"v\"");
228                         headers.Add ("if-none-match", "\"v2\"");
229                         headers.Add ("pragma", "p");
230                         headers.Add ("TE", "0.8");
231                         headers.Add ("trailer", "value2");
232                         headers.Add ("transfer-encoding", "ttt");
233                         headers.Add ("upgrade", "uuu");
234                         headers.Add ("user-agent", "uaua");
235                         headers.Add ("via", "prot v");
236                         headers.Add ("warning", "4 ww \"t\"");
237
238                         Assert.IsTrue (headers.Accept.SequenceEqual (
239                                 new[] {
240                                         new MediaTypeWithQualityHeaderValue ("audio/x"),
241                                         new MediaTypeWithQualityHeaderValue ("audio/y")
242                                 }
243                         ));
244
245                         Assert.IsTrue (headers.AcceptCharset.SequenceEqual (
246                                 new[] {
247                                         new StringWithQualityHeaderValue ("str-v", 0.002),
248                                         new StringWithQualityHeaderValue ("achs")
249                                 }
250                         ));
251
252                         Assert.IsTrue (headers.AcceptEncoding.SequenceEqual (
253                                 new[] {
254                                         new StringWithQualityHeaderValue ("str-enc", 0.44),
255                                         new StringWithQualityHeaderValue ("aenc")
256                                 }
257                         ));
258
259                         Assert.IsTrue (headers.AcceptLanguage.SequenceEqual (
260                                 new[] {
261                                         new StringWithQualityHeaderValue ("str-lang", 0.41),
262                                         new StringWithQualityHeaderValue ("alan")
263                                 }
264                         ));
265
266                         Assert.AreEqual (new AuthenticationHeaderValue ("sh-aut", "par"), headers.Authorization);
267
268                         var cch = new CacheControlHeaderValue () {
269                                         MaxAge = TimeSpan.MaxValue,
270                                 };
271
272                         Assert.AreEqual (cch, headers.CacheControl);
273
274                         Assert.IsTrue (headers.Connection.SequenceEqual (
275                                 new string[] { "test-value", "close" }));
276
277                         Assert.AreEqual (headers.Date, new DateTimeOffset (DateTime.Today));
278
279                         Assert.IsTrue (headers.Expect.SequenceEqual (
280                                 new [] {
281                                         new NameValueWithParametersHeaderValue ("en", "ev"),
282                                         new NameValueWithParametersHeaderValue ("100-continue"),
283                                         new NameValueWithParametersHeaderValue ("exp")
284                                 }));
285
286                         Assert.AreEqual (headers.From, "webmaster@w3.org");
287
288                         Assert.IsTrue (headers.IfMatch.SequenceEqual (
289                                 new EntityTagHeaderValue[] {
290                                         new EntityTagHeaderValue ("\"tag\"", true),
291                                         new EntityTagHeaderValue ("\"v\"", false)
292                                 }
293                         ));
294
295                         Assert.AreEqual (headers.IfModifiedSince, new DateTimeOffset (DateTime.Today));
296                         Assert.IsTrue (headers.IfNoneMatch.SequenceEqual (new EntityTagHeaderValue[] { new EntityTagHeaderValue ("\"tag2\"", true), new EntityTagHeaderValue ("\"v2\"", false) }));
297                         Assert.AreEqual (new DateTimeOffset (DateTime.Today), headers.IfRange.Date);
298                         Assert.AreEqual (headers.MaxForwards, 0x15b3);
299                         Assert.IsTrue (headers.Pragma.SequenceEqual (new NameValueHeaderValue[] { new NameValueHeaderValue ("name", "value"), new NameValueHeaderValue ("p", null) }));
300                         Assert.AreEqual ("p", headers.ProxyAuthorization.Parameter);
301                         Assert.AreEqual ("s", headers.ProxyAuthorization.Scheme);
302                         Assert.AreEqual (5, headers.Range.Ranges.First ().From);
303                         Assert.AreEqual (30, headers.Range.Ranges.First ().To);
304                         Assert.AreEqual ("bytes", headers.Range.Unit);
305                         Assert.AreEqual (headers.Referrer, new Uri ("http://xamarin.com"));
306                         Assert.IsTrue (headers.TE.SequenceEqual (new TransferCodingWithQualityHeaderValue[] { new TransferCodingWithQualityHeaderValue ("TE", 0.3), new TransferCodingWithQualityHeaderValue ("0.8") }), "29");
307                         Assert.IsTrue (headers.Trailer.SequenceEqual (
308                                 new string[] {
309                                         "value", "value2"
310                                 }), "30");
311
312                         Assert.IsTrue (headers.TransferEncoding.SequenceEqual (
313                                 new[] {
314                                         new TransferCodingHeaderValue ("tchv"),
315                                         new TransferCodingHeaderValue ("chunked"),
316                                         new TransferCodingHeaderValue ("ttt")
317                                 }
318                         ));
319
320                         Assert.IsTrue (headers.Upgrade.SequenceEqual (
321                                 new[] {
322                                         new ProductHeaderValue ("prod", "ver"),
323                                         new ProductHeaderValue ("uuu")
324                                 }
325                         ));
326
327                         Assert.IsTrue (headers.UserAgent.SequenceEqual (
328                                 new[] {
329                                         new ProductInfoHeaderValue ("(comment)"),
330                                         new ProductInfoHeaderValue ("uaua", null)
331                                 }
332                         ));
333
334                         Assert.IsTrue (headers.Via.SequenceEqual (
335                                 new[] {
336                                         new ViaHeaderValue ("protocol", "rec-by"),
337                                         new ViaHeaderValue ("prot", "v")
338                                 }
339                         ));
340
341                         Assert.IsTrue (headers.Warning.SequenceEqual (
342                                 new[] {
343                                         new WarningHeaderValue (5, "agent", "\"txt\""),
344                                         new WarningHeaderValue (4, "ww", "\"t\"")
345                                 }
346                         ));
347
348                 }
349
350                 [Test]
351                 public void Header_BaseImplementation ()
352                 {
353                         HttpRequestMessage message = new HttpRequestMessage ();
354                         HttpRequestHeaders headers = message.Headers;
355
356                         headers.Add ("a", "a-value");
357                         headers.Add ("b", new List<string> { "v1", "v2" });
358                         headers.Add ("c", null as string);
359                         headers.Add ("d", new string[0]);
360
361                         Assert.IsTrue (headers.TryAddWithoutValidation ("accept", "audio"), "#0");
362
363                         Assert.IsFalse (headers.Contains ("nn"), "#1a");
364                         Assert.IsTrue (headers.Contains ("b"), "#1b");
365
366                         var values = headers.GetValues ("b").ToList ();
367                         Assert.AreEqual ("v1", values[0], "#2a");
368                         Assert.AreEqual ("v2", values[1], "#2b");
369
370                         Assert.IsFalse (headers.Remove ("p"), "#3a");
371                         Assert.IsTrue (headers.Remove ("b"), "#3b");
372                         Assert.IsFalse (headers.Contains ("b"), "#3b-c");
373
374                         IEnumerable<string> values2;
375                         Assert.IsTrue (headers.TryGetValues ("c", out values2));
376                         values = values2.ToList ();
377                         Assert.AreEqual ("", values[0], "#4a");
378
379                         int counter = 0;
380                         foreach (var i in headers) {
381                                 ++counter;
382                         }
383
384                         Assert.AreEqual (3, counter, "#5");
385
386                         headers.Clear ();
387
388                         headers.Accept.Add (new MediaTypeWithQualityHeaderValue ("audio/x"));
389                         Assert.IsTrue (headers.TryAddWithoutValidation ("accept", "audio"), "#55");
390
391                         values = headers.GetValues ("accept").ToList ();
392                         Assert.AreEqual (2, values.Count, "#6");
393                         Assert.AreEqual ("audio/x", values[0], "#6a");
394                         Assert.AreEqual ("audio", values[1], "#6b");
395                         Assert.AreEqual (1, headers.Accept.Count, "#6c");
396
397                         headers.Clear ();
398
399                         Assert.IsTrue (headers.TryAddWithoutValidation ("from", new[] { "a@a.com", "ssss@oo.com" }), "#70");
400                         values = headers.GetValues ("from").ToList ();
401
402                         Assert.AreEqual (2, values.Count, "#7");
403                         Assert.AreEqual ("a@a.com", values[0], "#7a");
404                         Assert.AreEqual ("ssss@oo.com", values[1], "#7b");
405                         Assert.AreEqual ("a@a.com", headers.From, "#7c");
406
407                         headers.Clear ();
408
409                         Assert.IsTrue (headers.TryAddWithoutValidation ("Date", "wrong date"), "#8-0");
410                         var value = headers.Date;
411                         Assert.IsNull (headers.Date, "#8");
412                 }
413
414                 [Test]
415                 public void Headers_Invalid ()
416                 {
417                         HttpRequestMessage message = new HttpRequestMessage ();
418                         HttpRequestHeaders headers = message.Headers;
419
420                         try {
421                                 headers.Add ("Allow", "");
422                                 Assert.Fail ("#1");
423                         } catch (InvalidOperationException) {
424                         }
425
426                         try {
427                                 headers.Add (null, "");
428                                 Assert.Fail ("#2");
429                         } catch (ArgumentException) {
430                         }
431
432                         try {
433                                 headers.Add ("mm", null as IEnumerable<string>);
434                                 Assert.Fail ("#2b");
435                         } catch (ArgumentNullException) {
436                         }
437
438                         try {
439                                 headers.Add ("accept", "audio");
440                                 Assert.Fail ("#2c");
441                         } catch (FormatException) {
442                         }
443
444                         Assert.IsFalse (headers.TryAddWithoutValidation ("Allow", ""), "#3"); ;
445
446                         Assert.IsFalse (headers.TryAddWithoutValidation (null, ""), "#4");
447
448                         try {
449                                 headers.Contains (null);
450                                 Assert.Fail ("#5");
451                         } catch (ArgumentException) {
452                         }
453
454                         try {
455                                 headers.GetValues (null);
456                                 Assert.Fail ("#6a");
457                         } catch (ArgumentException) {
458                         }
459
460                         try {
461                                 headers.GetValues ("bbbb");
462                                 Assert.Fail ("#6b");
463                         } catch (InvalidOperationException) {
464                         }
465
466                         try {
467                                 headers.Add ("from", new[] { "a@a.com", "ssss@oo.com" });
468                                 Assert.Fail ("#7a");
469                         } catch (FormatException) {
470                         }
471
472                         Assert.IsTrue (headers.TryAddWithoutValidation ("from", "a@a.com"), "#7-0");
473                         try {
474                                 headers.Add ("from", "valid@w3.org");
475                                 Assert.Fail ("#7b");
476                         } catch (FormatException) {
477                         }
478                 }
479
480                 [Test]
481                 public void Headers_Response ()
482                 {
483                         HttpRequestMessage message = new HttpRequestMessage ();
484                         HttpRequestHeaders headers = message.Headers;
485
486                         headers.Add ("Age", "vv");
487                         Assert.AreEqual ("vv", headers.GetValues ("Age").First (), "#1");
488
489                         headers.Clear ();
490                         headers.TryAddWithoutValidation ("Age", "vv");
491                         Assert.AreEqual ("vv", headers.GetValues ("Age").First (), "#2");
492
493                         // .NET encloses the "Age: vv" with two whitespaces.
494                         var normalized = Regex.Replace (message.ToString (), @"\s", "");
495                         Assert.AreEqual ("Method:GET,RequestUri:'<null>',Version:1.1,Content:<null>,Headers:{Age:vv}", normalized, "#3");
496                 }
497
498                 [Test]
499                 public void Headers_ExpectContinue ()
500                 {
501                         HttpRequestMessage message = new HttpRequestMessage ();
502                         HttpRequestHeaders headers = message.Headers;
503                         Assert.IsNull (headers.ExpectContinue, "#1");
504
505                         headers.ExpectContinue = false;
506                         Assert.IsFalse (headers.ExpectContinue.Value, "#2");
507
508                         headers.Clear ();
509
510                         headers.ExpectContinue = true;
511                         headers.ExpectContinue = true;
512                         headers.ExpectContinue = true;
513                         headers.ExpectContinue = true;
514                         Assert.IsTrue (headers.ExpectContinue.Value, "#3");
515                         Assert.AreEqual (1, headers.GetValues ("expect").ToList ().Count, "#4");
516
517                         headers.Clear ();
518                         headers.Expect.Add (new NameValueWithParametersHeaderValue ("100-conTinuE"));
519                         Assert.IsTrue (headers.ExpectContinue.Value, "#5");
520                 }
521
522                 [Test]
523                 public void Headers_ConnectionClose ()
524                 {
525                         HttpRequestMessage message = new HttpRequestMessage ();
526                         HttpRequestHeaders headers = message.Headers;
527                         Assert.IsNull (headers.ConnectionClose, "#1");
528
529                         headers.ConnectionClose = false;
530                         Assert.IsFalse (headers.ConnectionClose.Value, "#2");
531
532                         headers.Clear ();
533
534                         headers.ConnectionClose = true;
535                         Assert.IsTrue (headers.ConnectionClose.Value, "#3");
536
537                         headers.Clear ();
538                         headers.Connection.Add ("Close");
539                         Assert.IsTrue (headers.ConnectionClose.Value, "#4");
540                 }
541
542                 [Test]
543                 public void Headers_From_Invalid ()
544                 {
545                         HttpRequestMessage message = new HttpRequestMessage ();
546                         HttpRequestHeaders headers = message.Headers;
547                         headers.From = null;
548                         headers.From = "";
549                         try {
550                                 headers.From = " ";
551                                 Assert.Fail ("#1");
552                         } catch (FormatException) {
553                         }
554                         try {
555                                 headers.From = "test";
556                                 Assert.Fail ("#2");
557                         } catch (FormatException) {
558                         }
559                 }
560
561                 [Test]
562                 public void Headers_TransferEncodingChunked ()
563                 {
564                         HttpRequestMessage message = new HttpRequestMessage ();
565                         HttpRequestHeaders headers = message.Headers;
566                         Assert.IsNull (headers.TransferEncodingChunked, "#1");
567
568                         headers.TransferEncodingChunked = false;
569                         Assert.IsFalse (headers.TransferEncodingChunked.Value, "#2");
570
571                         headers.Clear ();
572
573                         headers.TransferEncodingChunked = true;
574                         Assert.IsTrue (headers.TransferEncodingChunked.Value, "#3");
575                         Assert.AreEqual (1, headers.TransferEncoding.Count, "#3b");
576                 }
577
578                 [Test]
579                 public void Properties ()
580                 {
581                         var c = new HttpRequestMessage ();
582                         c.Content = null;
583                         c.Method = HttpMethod.Post;
584                         c.Properties.Add ("a", "test");
585                         c.RequestUri = null;
586                         c.Version = HttpVersion.Version10;
587
588                         Assert.IsNull (c.Content, "#1");
589                         Assert.AreEqual (HttpMethod.Post, c.Method, "#2");
590                         Assert.AreEqual ("test", c.Properties["a"], "#3");
591                         Assert.IsNull (c.RequestUri, "#4");
592                         Assert.AreEqual (HttpVersion.Version10, c.Version, "#5");
593                 }
594
595                 [Test]
596                 public void Properties_Invalid ()
597                 {
598                         var c = new HttpRequestMessage ();
599                         try {
600                                 c.Method = null;
601                                 Assert.Fail ("#1");
602                         } catch (ArgumentNullException) {
603                         }
604
605                         try {
606                                 c.RequestUri = new Uri ("ftp://xamarin.com");
607                                 Assert.Fail ("#2");
608                         } catch (ArgumentException) {
609                         }
610
611                         try {
612                                 c.Version = null;
613                                 Assert.Fail ("#3");
614                         } catch (ArgumentNullException) {
615                         }
616                 }
617         }
618 }