copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[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                 public void InitializeAndValidate ()
238                 {
239                         UriFormatException error = null;
240                         UnitTestUriParser p = new UnitTestUriParser ();
241                         p._InitializeAndValidate (http, out error);
242                         Assert.IsNotNull (error, "out"); // authority/host couldn't be parsed ?!?!
243                 }
244
245                 [Test]
246                 [ExpectedException (typeof (NullReferenceException))]
247                 // oh man, this is a bad boy.It should be ArgumentNullException.
248                 public void InitializeAndValidate_Null ()
249                 {
250                         UriFormatException error = null;
251                         UnitTestUriParser p = new UnitTestUriParser ();
252                         p._InitializeAndValidate (null, out error);
253                 }
254
255                 [Test]
256                 public void IsBaseOf ()
257                 {
258                         UnitTestUriParser p = new UnitTestUriParser ();
259                         Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
260
261                         Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
262                         Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
263                         Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
264
265                         u = new Uri ("http://www.mono-project.com/Main_Page");
266                         Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
267                         Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
268
269                         u = new Uri ("http://www.mono-project.com/");
270                         Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
271                         Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
272
273                         u = new Uri ("http://www.mono-project.com/Main_Page/");
274                         Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
275                         Assert.IsTrue (p._IsBaseOf (http, u), "http-4b");
276
277                         // docs says the UserInfo isn't evaluated, but...
278                         u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
279                         Assert.IsFalse (p._IsBaseOf (u, http), "http-5a");
280                         Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
281
282                         // scheme case sensitive ? no
283                         u = new Uri ("HTTP://www.mono-project.com/Main_Page");
284                         Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
285                         Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
286
287                         // host case sensitive ? no
288                         u = new Uri ("http://www.Mono-Project.com/Main_Page");
289                         Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
290                         Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
291
292                         // path case sensitive ? no
293                         u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
294                         Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
295                         Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
296
297                         // different scheme
298                         u = new Uri ("ftp://www.mono-project.com/Main_Page");
299                         Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
300                         Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
301
302                         // different host
303                         u = new Uri ("http://www.go-mono.com/Main_Page");
304                         Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
305                         Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
306
307                         // different port
308                         u = new Uri ("http://www.mono-project.com:8080/");
309                         Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
310                         Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
311
312                         // specify default port
313                         u = new Uri ("http://www.mono-project.com:80/");
314                         Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
315                         Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
316                 }
317
318                 [Test]
319                 [ExpectedException (typeof (NullReferenceException))]
320                 public void IsBaseOf_UriNull ()
321                 {
322                         UnitTestUriParser p = new UnitTestUriParser ();
323                         p._IsBaseOf (http, null);
324                 }
325
326                 [Test]
327                 [ExpectedException (typeof (NullReferenceException))]
328                 public void IsBaseOf_NullUri ()
329                 {
330                         UnitTestUriParser p = new UnitTestUriParser ();
331                         p._IsBaseOf (null, http);
332                 }
333
334                 [Test]
335                 [Category ("NotWorking")]
336                 public void IsWellFormedOriginalString ()
337                 {
338                         UnitTestUriParser p = new UnitTestUriParser ();
339                         Assert.IsTrue (p._IsWellFormedOriginalString (http), "http");
340                 }
341
342                 [Test]
343                 [ExpectedException (typeof (NullReferenceException))]
344                 [Category ("NotWorking")]
345                 public void IsWellFormedOriginalString_Null ()
346                 {
347                         UnitTestUriParser p = new UnitTestUriParser ();
348                         p._IsWellFormedOriginalString (null);
349                 }
350
351                 [Test]
352                 [Category ("NotWorking")]
353                 public void OnNewUri ()
354                 {
355                         string scheme = prefix + "on.new.uri";
356                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
357
358                         UnitTestUriParser p = new UnitTestUriParser ();
359                         UriParser.Register (p, scheme, 1999);
360
361                         Assert.IsFalse (p.OnNewUriCalled, "!Called");
362                         Uri uri = new Uri (scheme + "://www.mono-project.com");
363                         Assert.IsTrue (p.OnNewUriCalled, "Called");
364                 }
365
366                 [Test]
367                 public void OnRegister ()
368                 {
369                         string scheme = prefix + "onregister";
370                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
371                         UnitTestUriParser p = new UnitTestUriParser ();
372                         try {
373                                 UriParser.Register (p, scheme, 2005);
374                         }
375                         catch (NotSupportedException) {
376                                 // special case / ordering
377                         }
378                         // if true then the registration is done before calling OnRegister
379                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
380                 }
381
382                 [Test]
383                 [Category ("NotWorking")]
384                 public void OnRegister2 ()
385                 {
386                         string scheme = prefix + "onregister2";
387                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
388                         UnitTestUriParser p = new UnitTestUriParser ();
389                         try {
390                                 UriParser.Register (p, scheme, 2005);
391                                 Uri uri = new Uri (scheme + "://foobar:2005");
392                                 Assert.AreEqual (scheme, uri.Scheme, "uri-prefix");
393                                 Assert.AreEqual (2005, uri.Port, "uri-port");
394                                 
395                                 Assert.AreEqual ("//foobar:2005", uri.LocalPath, "uri-localpath");
396                         }
397                         catch (NotSupportedException) {
398                                 // special case / ordering
399                         }
400                         // if true then the registration is done before calling OnRegister
401                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
402                 }
403
404                 [Test]
405                 [Category ("NotWorking")]
406                 public void Resolve ()
407                 {
408                         UriFormatException error = null;
409                         UnitTestUriParser p = new UnitTestUriParser ();
410                         Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
411                 }
412
413                 [Test]
414                 [Category ("NotWorking")]
415                 public void Resolve_UriNull ()
416                 {
417                         UriFormatException error = null;
418                         UnitTestUriParser p = new UnitTestUriParser ();
419                         Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
420                 }
421
422                 [Test]
423                 [ExpectedException (typeof (NullReferenceException))]
424                 [Category ("NotWorking")]
425                 public void Resolve_NullUri ()
426                 {
427                         UriFormatException error = null;
428                         UnitTestUriParser p = new UnitTestUriParser ();
429                         p._Resolve (null, http, out error);
430                         p._Resolve (http, null, out error);
431                 }
432
433                 [Test]
434                 public void IsKnownScheme_WellKnown ()
435                 {
436                         // from Uri.UriScheme* fields
437                         Assert.IsTrue (UriParser.IsKnownScheme ("file"), "file");
438                         Assert.IsTrue (UriParser.IsKnownScheme ("ftp"), "ftp");
439                         Assert.IsTrue (UriParser.IsKnownScheme ("gopher"), "gopher");
440                         Assert.IsTrue (UriParser.IsKnownScheme ("http"), "http");
441                         Assert.IsTrue (UriParser.IsKnownScheme ("https"), "https");
442                         Assert.IsTrue (UriParser.IsKnownScheme ("mailto"), "mailto");
443                         Assert.IsTrue (UriParser.IsKnownScheme ("net.pipe"), "net.pipe");
444                         Assert.IsTrue (UriParser.IsKnownScheme ("net.tcp"), "net.tcp");
445                         Assert.IsTrue (UriParser.IsKnownScheme ("news"), "news");
446                         Assert.IsTrue (UriParser.IsKnownScheme ("nntp"), "nntp");
447                         // inferred from class library
448                         Assert.IsTrue (UriParser.IsKnownScheme ("ldap"), "ldap");
449                         Assert.IsFalse (UriParser.IsKnownScheme ("ldaps"), "ldaps");
450                         // well known for not existing
451                         Assert.IsFalse (UriParser.IsKnownScheme ("unknown"), "unknown");
452
453                         // variations - mixed and upper case
454                         Assert.IsTrue (UriParser.IsKnownScheme ("FiLe"), "FiLe");
455                         Assert.IsTrue (UriParser.IsKnownScheme ("FTP"), "ftp");
456
457                         // see 496783
458                         Assert.IsFalse (UriParser.IsKnownScheme ("tcp"), "tcp");
459                 }
460
461                 [Test]
462                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
463                 [Category ("NotWorking")]
464                 public void IsKnownScheme_ExtraSpace ()
465                 {
466                         // same result for space before, inside or after the scheme
467                         UriParser.IsKnownScheme ("ht tp");
468                         // this is undocumented (and I hate exceptions in a boolean method)
469                 }
470
471                 [Test]
472                 [ExpectedException (typeof (ArgumentNullException))]
473                 public void IsKnownScheme_Null ()
474                 {
475                         UriParser.IsKnownScheme (null);
476                 }
477
478                 [Test]
479                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
480                 public void IsKnownScheme_Empty ()
481                 {
482                         UriParser.IsKnownScheme (String.Empty);
483                 }
484
485                 [Test]
486                 public void Register ()
487                 {
488                         string scheme = prefix + "register.mono";
489                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
490
491                         UnitTestUriParser p = new UnitTestUriParser ();
492                         UriParser.Register (p, scheme, 2005);
493                         Assert.AreEqual (scheme, p.SchemeName, "SchemeName");
494                         Assert.AreEqual (2005, p.DefaultPort, "DefaultPort");
495
496                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
497                 }
498
499                 [Test]
500                 [ExpectedException (typeof (ArgumentNullException))]
501                 public void Register_NullParser ()
502                 {
503                         UriParser.Register (null, prefix + "null.parser", 2006);
504                 }
505
506                 [Test]
507                 [ExpectedException (typeof (ArgumentNullException))]
508                 public void Register_NullScheme ()
509                 {
510                         UnitTestUriParser p = new UnitTestUriParser ();
511                         UriParser.Register (p, null, 2006);
512                 }
513
514                 [Test]
515                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
516                 public void Register_NegativePort ()
517                 {
518                         UnitTestUriParser p = new UnitTestUriParser ();
519                         UriParser.Register (p, prefix + "negative.port", -2);
520                 }
521
522                 [Test]
523                 public void Register_Minus1Port ()
524                 {
525                         UnitTestUriParser p = new UnitTestUriParser ();
526                         UriParser.Register (p, prefix + "minus1.port", -1);
527                 }
528
529                 [Test]
530                 public void Register_UInt16PortMinus1 ()
531                 {
532                         UnitTestUriParser p = new UnitTestUriParser ();
533                         UriParser.Register (p, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1);
534                 }
535
536                 [Test]
537                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
538                 public void Register_TooBigPort ()
539                 {
540                         UnitTestUriParser p = new UnitTestUriParser ();
541                         UriParser.Register (p, prefix + "too.big.port", UInt16.MaxValue);
542                 }
543
544                 [Test]
545                 [ExpectedException (typeof (InvalidOperationException))]
546                 public void ReRegister ()
547                 {
548                         string scheme = prefix + "re.register.mono";
549                         Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
550                         UnitTestUriParser p = new UnitTestUriParser ();
551                         UriParser.Register (p, scheme, 2005);
552                         Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
553                         UriParser.Register (p, scheme, 2006);
554                 }
555         }
556 }
557
558 #endif