In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / System / Test / System / UriParserTest.cs
1 //
2 // UriParserTest.cs - Unit tests for System.UriParser
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.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 #if NET_2_0
30
31 using NUnit.Framework;
32
33 using System;
34 using System.Text;
35
36 namespace MonoTests.System {
37
38         public class UnitTestUriParser: UriParser {
39
40                 private string scheme_name;
41                 private int default_port;
42                 private bool throw_on_register;
43                 private bool on_new_uri_called;
44
45                 public UnitTestUriParser ()
46                 {
47                 }
48
49                 public UnitTestUriParser (bool throwOnRegister)
50                 {
51                         throw_on_register = throwOnRegister;
52                 }
53
54                 public string SchemeName
55                 {
56                         get
57                         {
58                                 return scheme_name;
59                         }
60                 }
61
62                 public int DefaultPort
63                 {
64                         get
65                         {
66                                 return default_port;
67                         }
68                 }
69
70                 public bool OnNewUriCalled
71                 {
72                         get
73                         {
74                                 return on_new_uri_called;
75                         }
76                 }
77
78                 public string _GetComponents (Uri uri, UriComponents components, UriFormat format)
79                 {
80                         return base.GetComponents (uri, components, format);
81                 }
82
83                 public void _InitializeAndValidate (Uri uri, out UriFormatException parserError)
84                 {
85                         base.InitializeAndValidate (uri, out parserError);
86                 }
87
88                 public bool _IsBaseOf (Uri baseUri, Uri relativeUri)
89                 {
90                         return base.IsBaseOf (baseUri, relativeUri);
91                 }
92
93                 public bool _IsWellFormedOriginalString (Uri uri)
94                 {
95                         return base.IsWellFormedOriginalString (uri);
96                 }
97
98                 public UriParser _OnNewUri ()
99                 {
100                         return base.OnNewUri ();
101                 }
102
103                 public void _OnRegister (string schemeName, int defaultPort)
104                 {
105                         base.OnRegister (schemeName, defaultPort);
106                 }
107
108                 public string _Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parserError)
109                 {
110                         return base.Resolve (baseUri, relativeUri, out parserError);
111                 }
112
113                 protected override UriParser OnNewUri ()
114                 {
115                         on_new_uri_called = true;
116                         return base.OnNewUri ();
117                 }
118
119                 protected override void OnRegister (string schemeName, int defaultPort)
120                 {
121                         if (throw_on_register)
122                                 throw new NotSupportedException ();
123                         scheme_name = schemeName;
124                         default_port = defaultPort;
125                         base.OnRegister (schemeName, defaultPort);
126                 }
127         }
128
129         [TestFixture]
130         public class UriParserTest {
131
132                 private const string full_http = "http://www.mono-project.com/Main_Page#FAQ?Edit";
133
134                 private string prefix;
135                 private Uri http;
136                 private Uri ftp;
137
138                 [TestFixtureSetUp]
139                 public void FixtureSetUp ()
140                 {
141                         prefix = "unit.test.";
142                         http = new Uri (full_http);
143                         ftp = new Uri ("ftp://username:password@ftp.go-mono.com:21/with some spaces/mono.tgz");
144                 }
145
146                 public string Prefix
147                 {
148                         get
149                         {
150                                 return prefix;
151                         }
152                         set
153                         {
154                                 prefix = value;
155                         }
156                 }
157
158                 [Test]
159                 public void GetComponents ()
160                 {
161                         UnitTestUriParser p = new UnitTestUriParser ();
162                         Assert.AreEqual ("http", p._GetComponents (http, UriComponents.Scheme, UriFormat.SafeUnescaped), "http.Scheme");
163                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.UserInfo, UriFormat.SafeUnescaped), "http.UserInfo");
164                         Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http.Host");
165                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Port, UriFormat.SafeUnescaped), "http.Port");
166                         Assert.AreEqual ("Main_Page", p._GetComponents (http, UriComponents.Path, UriFormat.SafeUnescaped), "http.Path");
167                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Query, UriFormat.SafeUnescaped), "http.Query");
168                         Assert.AreEqual ("FAQ?Edit", p._GetComponents (http, UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Fragment");
169                         Assert.AreEqual ("80", p._GetComponents (http, UriComponents.StrongPort, UriFormat.SafeUnescaped), "http.StrongPort");
170                         Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped), "http.KeepDelimiter");
171                         Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.HostAndPort, UriFormat.SafeUnescaped), "http.HostAndPort");
172                         Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped), "http.StrongAuthority");
173                         Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped), "http.AbsoluteUri");
174                         Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped), "http.PathAndQuery");
175                         Assert.AreEqual ("http://www.mono-project.com/Main_Page", p._GetComponents (http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), "http.HttpRequestUrl");
176                         Assert.AreEqual ("http://www.mono-project.com", p._GetComponents (http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped), "http.SchemeAndServer");
177                         Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), "http.SerializationInfoString");
178                         // strange mixup
179                         Assert.AreEqual ("http://", p._GetComponents (http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped), "http.Scheme+Port");
180                         Assert.AreEqual ("www.mono-project.com#FAQ?Edit", p._GetComponents (http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Scheme+Port");
181                         Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped), "http.Scheme+Port");
182                         Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
183                 }
184
185                 [Test]
186                 public void GetComponents_Ftp ()
187                 {
188                         UnitTestUriParser p = new UnitTestUriParser ();
189                         Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
190                         Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
191                         Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
192                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
193                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
194                         Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
195                         Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
196                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
197                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
198                         Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
199                         Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
200                         Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
201                         Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
202                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
203                         Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
204                         Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
205                         Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
206                         Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
207                         Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
208                         // strange mixup
209                         Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
210                         Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
211                 }
212
213                 [Test]
214                 [ExpectedException (typeof (NullReferenceException))]
215                 public void GetComponents_Null ()
216                 {
217                         UnitTestUriParser p = new UnitTestUriParser ();
218                         p._GetComponents (null, UriComponents.Host, UriFormat.SafeUnescaped);
219                 }
220
221                 [Test]
222                 public void GetComponents_BadUriComponents ()
223                 {
224                         UnitTestUriParser p = new UnitTestUriParser ();
225                         Assert.AreEqual (full_http, p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
226                 }
227
228                 [Test]
229                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
230                 public void GetComponents_BadUriFormat ()
231                 {
232                         UnitTestUriParser p = new UnitTestUriParser ();
233                         p._GetComponents (http, UriComponents.Host, (UriFormat) Int32.MinValue);
234                 }
235
236                 [Test]
237                 [Category ("NotWorking")]
238                 public void InitializeAndValidate ()
239                 {
240                         UriFormatException error = null;
241                         UnitTestUriParser p = new UnitTestUriParser ();
242                         p._InitializeAndValidate (http, out error);
243                         Assert.IsNotNull (error, "out"); // authority/host couldn't be parsed ?!?!
244                 }
245
246                 [Test]
247                 [ExpectedException (typeof (NullReferenceException))]
248                 [Category ("NotWorking")]
249                 public void InitializeAndValidate_Null ()
250                 {
251                         UriFormatException error = null;
252                         UnitTestUriParser p = new UnitTestUriParser ();
253                         p._InitializeAndValidate (null, out error);
254                 }
255
256                 [Test]
257                 public void IsBaseOf ()
258                 {
259                         UnitTestUriParser p = new UnitTestUriParser ();
260                         Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
261
262                         Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
263                         Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
264                         Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
265
266                         u = new Uri ("http://www.mono-project.com/Main_Page");
267                         Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
268                         Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
269
270                         u = new Uri ("http://www.mono-project.com/");
271                         Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
272                         Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
273
274                         u = new Uri ("http://www.mono-project.com/Main_Page/");
275                         Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
276                         Assert.IsTrue (p._IsBaseOf (http, u), "http-4b");
277
278                         // docs says the UserInfo isn't evaluated, but...
279                         u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
280                         Assert.IsFalse (p._IsBaseOf (u, http), "http-5a");
281                         Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
282
283                         // scheme case sensitive ? no
284                         u = new Uri ("HTTP://www.mono-project.com/Main_Page");
285                         Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
286                         Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
287
288                         // host case sensitive ? no
289                         u = new Uri ("http://www.Mono-Project.com/Main_Page");
290                         Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
291                         Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
292
293                         // path case sensitive ? no
294                         u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
295                         Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
296                         Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
297
298                         // different scheme
299                         u = new Uri ("ftp://www.mono-project.com/Main_Page");
300                         Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
301                         Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
302
303                         // different host
304                         u = new Uri ("http://www.go-mono.com/Main_Page");
305                         Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
306                         Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
307
308                         // different port
309                         u = new Uri ("http://www.mono-project.com:8080/");
310                         Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
311                         Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
312
313                         // specify default port
314                         u = new Uri ("http://www.mono-project.com:80/");
315                         Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
316                         Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
317                 }
318
319                 [Test]
320                 [ExpectedException (typeof (NullReferenceException))]
321                 public void IsBaseOf_UriNull ()
322                 {
323                         UnitTestUriParser p = new UnitTestUriParser ();
324                         p._IsBaseOf (http, null);
325                 }
326
327                 [Test]
328                 [ExpectedException (typeof (NullReferenceException))]
329                 public void IsBaseOf_NullUri ()
330                 {
331                         UnitTestUriParser p = new UnitTestUriParser ();
332                         p._IsBaseOf (null, http);
333                 }
334
335                 [Test]
336                 [Category ("NotWorking")]
337                 public void IsWellFormedOriginalString ()
338                 {
339                         UnitTestUriParser p = new UnitTestUriParser ();
340                         Assert.IsTrue (p._IsWellFormedOriginalString (http), "http");
341                 }
342
343                 [Test]
344                 [ExpectedException (typeof (NullReferenceException))]
345                 [Category ("NotWorking")]
346                 public void IsWellFormedOriginalString_Null ()
347                 {
348                         UnitTestUriParser p = new UnitTestUriParser ();
349                         p._IsWellFormedOriginalString (null);
350                 }
351
352                 [Test]
353                 [Category ("NotWorking")]
354                 public void OnNewUri ()
355                 {
356                         string scheme = prefix + "on.new.uri";
357                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
358
359                         UnitTestUriParser p = new UnitTestUriParser ();
360                         UriParser.Register (p, scheme, 1999);
361
362                         Assert.IsFalse (p.OnNewUriCalled, "!Called");
363                         Uri uri = new Uri (scheme + "://www.mono-project.com");
364                         Assert.IsTrue (p.OnNewUriCalled, "Called");
365                 }
366
367                 [Test]
368                 public void OnRegister ()
369                 {
370                         string scheme = prefix + "onregister";
371                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
372                         UnitTestUriParser p = new UnitTestUriParser ();
373                         try {
374                                 UriParser.Register (p, scheme, 2005);
375                         }
376                         catch (NotSupportedException) {
377                                 // special case / ordering
378                         }
379                         // if true then the registration is done before calling OnRegister
380                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
381                 }
382
383                 [Test]
384                 [Category ("NotWorking")]
385                 public void Resolve ()
386                 {
387                         UriFormatException error = null;
388                         UnitTestUriParser p = new UnitTestUriParser ();
389                         Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
390                 }
391
392                 [Test]
393                 [Category ("NotWorking")]
394                 public void Resolve_UriNull ()
395                 {
396                         UriFormatException error = null;
397                         UnitTestUriParser p = new UnitTestUriParser ();
398                         Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
399                 }
400
401                 [Test]
402                 [ExpectedException (typeof (NullReferenceException))]
403                 [Category ("NotWorking")]
404                 public void Resolve_NullUri ()
405                 {
406                         UriFormatException error = null;
407                         UnitTestUriParser p = new UnitTestUriParser ();
408                         p._Resolve (null, http, out error);
409                         p._Resolve (http, null, out error);
410                 }
411
412                 [Test]
413                 public void IsKnownScheme_WellKnown ()
414                 {
415                         // from Uri.UriScheme* fields
416                         Assert.IsTrue (UriParser.IsKnownScheme ("file"), "file");
417                         Assert.IsTrue (UriParser.IsKnownScheme ("ftp"), "ftp");
418                         Assert.IsTrue (UriParser.IsKnownScheme ("gopher"), "gopher");
419                         Assert.IsTrue (UriParser.IsKnownScheme ("http"), "http");
420                         Assert.IsTrue (UriParser.IsKnownScheme ("https"), "https");
421                         Assert.IsTrue (UriParser.IsKnownScheme ("mailto"), "mailto");
422                         Assert.IsTrue (UriParser.IsKnownScheme ("net.pipe"), "net.pipe");
423                         Assert.IsTrue (UriParser.IsKnownScheme ("net.tcp"), "net.tcp");
424                         Assert.IsTrue (UriParser.IsKnownScheme ("news"), "news");
425                         Assert.IsTrue (UriParser.IsKnownScheme ("nntp"), "nntp");
426                         // inferred from class library
427                         Assert.IsTrue (UriParser.IsKnownScheme ("ldap"), "ldap");
428                         Assert.IsFalse (UriParser.IsKnownScheme ("ldaps"), "ldaps");
429                         // well known for not existing
430                         Assert.IsFalse (UriParser.IsKnownScheme ("unknown"), "unknown");
431
432                         // variations - mixed and upper case
433                         Assert.IsTrue (UriParser.IsKnownScheme ("FiLe"), "FiLe");
434                         Assert.IsTrue (UriParser.IsKnownScheme ("FTP"), "ftp");
435                 }
436
437                 [Test]
438                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
439                 [Category ("NotWorking")]
440                 public void IsKnownScheme_ExtraSpace ()
441                 {
442                         // same result for space before, inside or after the scheme
443                         UriParser.IsKnownScheme ("ht tp");
444                         // this is undocumented (and I hate exceptions in a boolean method)
445                 }
446
447                 [Test]
448                 [ExpectedException (typeof (ArgumentNullException))]
449                 public void IsKnownScheme_Null ()
450                 {
451                         UriParser.IsKnownScheme (null);
452                 }
453
454                 [Test]
455                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
456                 public void IsKnownScheme_Empty ()
457                 {
458                         UriParser.IsKnownScheme (String.Empty);
459                 }
460
461                 [Test]
462                 public void Register ()
463                 {
464                         string scheme = prefix + "register.mono";
465                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
466
467                         UnitTestUriParser p = new UnitTestUriParser ();
468                         UriParser.Register (p, scheme, 2005);
469                         Assert.AreEqual (scheme, p.SchemeName, "SchemeName");
470                         Assert.AreEqual (2005, p.DefaultPort, "DefaultPort");
471
472                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
473                 }
474
475                 [Test]
476                 [ExpectedException (typeof (ArgumentNullException))]
477                 public void Register_NullParser ()
478                 {
479                         UriParser.Register (null, prefix + "null.parser", 2006);
480                 }
481
482                 [Test]
483                 [ExpectedException (typeof (ArgumentNullException))]
484                 public void Register_NullScheme ()
485                 {
486                         UnitTestUriParser p = new UnitTestUriParser ();
487                         UriParser.Register (p, null, 2006);
488                 }
489
490                 [Test]
491                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
492                 public void Register_NegativePort ()
493                 {
494                         UnitTestUriParser p = new UnitTestUriParser ();
495                         UriParser.Register (p, prefix + "negative.port", -2);
496                 }
497
498                 [Test]
499                 public void Register_Minus1Port ()
500                 {
501                         UnitTestUriParser p = new UnitTestUriParser ();
502                         UriParser.Register (p, prefix + "minus1.port", -1);
503                 }
504
505                 [Test]
506                 public void Register_UInt16PortMinus1 ()
507                 {
508                         UnitTestUriParser p = new UnitTestUriParser ();
509                         UriParser.Register (p, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1);
510                 }
511
512                 [Test]
513                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
514                 public void Register_TooBigPort ()
515                 {
516                         UnitTestUriParser p = new UnitTestUriParser ();
517                         UriParser.Register (p, prefix + "too.big.port", UInt16.MaxValue);
518                 }
519
520                 [Test]
521                 [ExpectedException (typeof (InvalidOperationException))]
522                 public void ReRegister ()
523                 {
524                         string scheme = prefix + "re.register.mono";
525                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
526                         UnitTestUriParser p = new UnitTestUriParser ();
527                         UriParser.Register (p, scheme, 2005);
528                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
529                         UriParser.Register (p, scheme, 2006);
530                 }
531         }
532 }
533
534 #endif