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