2 // UriParserTest.cs - Unit tests for System.UriParser
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
35 namespace MonoTests.System {
37 public class UnitTestUriParser: UriParser {
39 private string scheme_name;
40 private int default_port;
41 private bool throw_on_register;
42 private bool on_new_uri_called;
44 public UnitTestUriParser ()
48 public UnitTestUriParser (bool throwOnRegister)
50 throw_on_register = throwOnRegister;
53 public string SchemeName
61 public int DefaultPort
69 public bool OnNewUriCalled
73 return on_new_uri_called;
77 public string _GetComponents (Uri uri, UriComponents components, UriFormat format)
79 return base.GetComponents (uri, components, format);
82 public void _InitializeAndValidate (Uri uri, out UriFormatException parserError)
84 base.InitializeAndValidate (uri, out parserError);
87 public bool _IsBaseOf (Uri baseUri, Uri relativeUri)
89 return base.IsBaseOf (baseUri, relativeUri);
92 public bool _IsWellFormedOriginalString (Uri uri)
94 return base.IsWellFormedOriginalString (uri);
97 public UriParser _OnNewUri ()
99 return base.OnNewUri ();
102 public void _OnRegister (string schemeName, int defaultPort)
104 base.OnRegister (schemeName, defaultPort);
107 public string _Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parserError)
109 return base.Resolve (baseUri, relativeUri, out parserError);
112 protected override UriParser OnNewUri ()
114 on_new_uri_called = true;
115 return base.OnNewUri ();
118 protected override void OnRegister (string schemeName, int defaultPort)
120 if (throw_on_register)
121 throw new NotSupportedException ();
122 scheme_name = schemeName;
123 default_port = defaultPort;
124 base.OnRegister (schemeName, defaultPort);
129 public class UriParserTest {
131 private const string full_http = "http://www.mono-project.com/Main_Page#FAQ?Edit";
133 private string prefix;
135 private Uri ftp, ftp2;
138 public void FixtureSetUp ()
140 prefix = "unit.test.";
141 http = new Uri (full_http);
142 ftp = new Uri ("ftp://username:password@ftp.go-mono.com:21/with some spaces/mono.tgz");
144 // Uses percent encoding on the username and password
145 ftp2 = new Uri ("ftp://%75sername%3a%70assword@ftp.go-mono.com:21/with some spaces/mono.tgz");
161 public void GetComponents ()
163 UnitTestUriParser p = new UnitTestUriParser ();
164 Assert.AreEqual ("http", p._GetComponents (http, UriComponents.Scheme, UriFormat.SafeUnescaped), "http.Scheme");
165 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.UserInfo, UriFormat.SafeUnescaped), "http.UserInfo");
166 Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http.Host");
167 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Port, UriFormat.SafeUnescaped), "http.Port");
168 Assert.AreEqual ("Main_Page", p._GetComponents (http, UriComponents.Path, UriFormat.SafeUnescaped), "http.Path");
169 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Query, UriFormat.SafeUnescaped), "http.Query");
170 Assert.AreEqual ("FAQ?Edit", p._GetComponents (http, UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Fragment");
171 Assert.AreEqual ("80", p._GetComponents (http, UriComponents.StrongPort, UriFormat.SafeUnescaped), "http.StrongPort");
172 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped), "http.KeepDelimiter");
173 Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.HostAndPort, UriFormat.SafeUnescaped), "http.HostAndPort");
174 Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped), "http.StrongAuthority");
175 Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped), "http.AbsoluteUri");
176 Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped), "http.PathAndQuery");
177 Assert.AreEqual ("http://www.mono-project.com/Main_Page", p._GetComponents (http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), "http.HttpRequestUrl");
178 Assert.AreEqual ("http://www.mono-project.com", p._GetComponents (http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped), "http.SchemeAndServer");
179 Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), "http.SerializationInfoString");
181 Assert.AreEqual ("http://", p._GetComponents (http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped), "http.Scheme+Port");
182 Assert.AreEqual ("www.mono-project.com#FAQ?Edit", p._GetComponents (http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Scheme+Port");
183 Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped), "http.Scheme+Port");
184 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
188 public void GetComponents_Ftp ()
190 UnitTestUriParser p = new UnitTestUriParser ();
191 Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
192 Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
193 Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
194 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
195 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
196 Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
197 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
198 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
199 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
200 Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
201 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
202 Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
203 Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
204 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
205 Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
206 Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
207 Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
208 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
209 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
211 Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
212 Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
216 public void GetComponents_Ftp2 ()
218 UnitTestUriParser p = new UnitTestUriParser ();
219 Assert.AreEqual ("ftp", p._GetComponents (ftp2, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
220 Assert.AreEqual ("username:password", p._GetComponents (ftp2, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
221 Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp2, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
222 Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
223 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
224 Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
225 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
226 Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
227 Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
228 Assert.AreEqual ("21", p._GetComponents (ftp2, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
229 Assert.AreEqual (String.Empty, p._GetComponents (ftp2, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
230 Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp2, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
231 Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp2, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
232 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
233 Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
234 Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
235 Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp2, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
236 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
237 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
239 Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp2, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
240 Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp2, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
243 // Test case for Xamarin#17665
245 public void TestParseUserPath ()
247 var u = new Uri("https://a.net/1@1.msg");
248 var result = u.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
249 Assert.AreEqual (result, "https://a.net/1@1.msg", "parse@InUrl");
254 [ExpectedException (typeof (NullReferenceException))]
255 public void GetComponents_Null ()
257 UnitTestUriParser p = new UnitTestUriParser ();
258 p._GetComponents (null, UriComponents.Host, UriFormat.SafeUnescaped);
262 public void GetComponents_BadUriComponents ()
264 UnitTestUriParser p = new UnitTestUriParser ();
265 Assert.AreEqual (full_http, p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
269 [ExpectedException (typeof (ArgumentOutOfRangeException))]
270 public void GetComponents_BadUriFormat ()
272 UnitTestUriParser p = new UnitTestUriParser ();
273 p._GetComponents (http, UriComponents.Host, (UriFormat) Int32.MinValue);
277 public void InitializeAndValidate ()
279 UriFormatException error = null;
280 UnitTestUriParser p = new UnitTestUriParser ();
281 p._InitializeAndValidate (http, out error);
282 Assert.IsNotNull (error, "out"); // authority/host couldn't be parsed ?!?!
286 [ExpectedException (typeof (NullReferenceException))]
287 // oh man, this is a bad boy.It should be ArgumentNullException.
288 public void InitializeAndValidate_Null ()
290 UriFormatException error = null;
291 UnitTestUriParser p = new UnitTestUriParser ();
292 p._InitializeAndValidate (null, out error);
296 public void IsBaseOf ()
298 UnitTestUriParser p = new UnitTestUriParser ();
299 Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
301 Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
302 Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
303 Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
305 u = new Uri ("http://www.mono-project.com/Main_Page");
306 Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
307 Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
309 u = new Uri ("http://www.mono-project.com/");
310 Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
311 Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
313 u = new Uri ("http://www.mono-project.com/Main_Page/");
314 Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
315 Assert.IsTrue (p._IsBaseOf (http, u), "http-4b");
317 // docs says the UserInfo isn't evaluated, but...
318 u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
319 Assert.IsFalse (p._IsBaseOf (u, http), "http-5a");
320 Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
322 // scheme case sensitive ? no
323 u = new Uri ("HTTP://www.mono-project.com/Main_Page");
324 Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
325 Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
327 // host case sensitive ? no
328 u = new Uri ("http://www.Mono-Project.com/Main_Page");
329 Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
330 Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
332 // path case sensitive ? no
333 u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
334 Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
335 Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
338 u = new Uri ("ftp://www.mono-project.com/Main_Page");
339 Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
340 Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
343 u = new Uri ("http://www.go-mono.com/Main_Page");
344 Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
345 Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
348 u = new Uri ("http://www.mono-project.com:8080/");
349 Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
350 Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
352 // specify default port
353 u = new Uri ("http://www.mono-project.com:80/");
354 Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
355 Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
359 [ExpectedException (typeof (NullReferenceException))]
360 public void IsBaseOf_UriNull ()
362 UnitTestUriParser p = new UnitTestUriParser ();
363 p._IsBaseOf (http, null);
367 [ExpectedException (typeof (NullReferenceException))]
368 public void IsBaseOf_NullUri ()
370 UnitTestUriParser p = new UnitTestUriParser ();
371 p._IsBaseOf (null, http);
375 public void IsWellFormedOriginalString ()
377 UnitTestUriParser p = new UnitTestUriParser ();
378 Assert.IsTrue (p._IsWellFormedOriginalString (http), "http");
382 [ExpectedException (typeof (NullReferenceException))]
383 public void IsWellFormedOriginalString_Null ()
385 UnitTestUriParser p = new UnitTestUriParser ();
386 p._IsWellFormedOriginalString (null);
390 public void OnNewUri ()
392 string scheme = prefix + "on.new.uri";
393 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
395 UnitTestUriParser p = new UnitTestUriParser ();
396 UriParser.Register (p, scheme, 1999);
398 Assert.IsFalse (p.OnNewUriCalled, "!Called");
399 Uri uri = new Uri (scheme + "://www.mono-project.com");
400 Assert.IsTrue (p.OnNewUriCalled, "Called");
404 public void OnRegister ()
406 string scheme = prefix + "onregister";
407 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
408 UnitTestUriParser p = new UnitTestUriParser ();
410 UriParser.Register (p, scheme, 2005);
412 catch (NotSupportedException) {
413 // special case / ordering
415 // if true then the registration is done before calling OnRegister
416 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
420 public void OnRegister2 ()
422 string scheme = prefix + "onregister2";
423 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
424 UnitTestUriParser p = new UnitTestUriParser ();
426 UriParser.Register (p, scheme, 2005);
427 Uri uri = new Uri (scheme + "://foobar:2005");
428 Assert.AreEqual (scheme, uri.Scheme, "uri-prefix");
429 Assert.AreEqual (2005, uri.Port, "uri-port");
431 Assert.AreEqual ("//foobar:2005", uri.LocalPath, "uri-localpath");
433 catch (NotSupportedException) {
434 // special case / ordering
436 // if true then the registration is done before calling OnRegister
437 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
441 public void Resolve ()
443 UriFormatException error = null;
444 UnitTestUriParser p = new UnitTestUriParser ();
445 Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
449 public void Resolve_UriNull ()
451 UriFormatException error = null;
452 UnitTestUriParser p = new UnitTestUriParser ();
453 Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
457 [ExpectedException (typeof (NullReferenceException))]
458 public void Resolve_NullUri ()
460 UriFormatException error = null;
461 UnitTestUriParser p = new UnitTestUriParser ();
462 p._Resolve (null, http, out error);
463 p._Resolve (http, null, out error);
467 public void IsKnownScheme_WellKnown ()
469 // from Uri.UriScheme* fields
470 Assert.IsTrue (UriParser.IsKnownScheme ("file"), "file");
471 Assert.IsTrue (UriParser.IsKnownScheme ("ftp"), "ftp");
472 Assert.IsTrue (UriParser.IsKnownScheme ("gopher"), "gopher");
473 Assert.IsTrue (UriParser.IsKnownScheme ("http"), "http");
474 Assert.IsTrue (UriParser.IsKnownScheme ("https"), "https");
475 Assert.IsTrue (UriParser.IsKnownScheme ("mailto"), "mailto");
476 Assert.IsTrue (UriParser.IsKnownScheme ("net.pipe"), "net.pipe");
477 Assert.IsTrue (UriParser.IsKnownScheme ("net.tcp"), "net.tcp");
478 Assert.IsTrue (UriParser.IsKnownScheme ("news"), "news");
479 Assert.IsTrue (UriParser.IsKnownScheme ("nntp"), "nntp");
480 // inferred from class library
481 Assert.IsTrue (UriParser.IsKnownScheme ("ldap"), "ldap");
482 Assert.IsFalse (UriParser.IsKnownScheme ("ldaps"), "ldaps");
483 // well known for not existing
484 Assert.IsFalse (UriParser.IsKnownScheme ("unknown"), "unknown");
486 // variations - mixed and upper case
487 Assert.IsTrue (UriParser.IsKnownScheme ("FiLe"), "FiLe");
488 Assert.IsTrue (UriParser.IsKnownScheme ("FTP"), "ftp");
491 Assert.IsFalse (UriParser.IsKnownScheme ("tcp"), "tcp");
495 [ExpectedException (typeof (ArgumentOutOfRangeException))]
496 public void IsKnownScheme_ExtraSpace ()
498 // same result for space before, inside or after the scheme
499 UriParser.IsKnownScheme ("ht tp");
500 // this is undocumented (and I hate exceptions in a boolean method)
504 [ExpectedException (typeof (ArgumentNullException))]
505 public void IsKnownScheme_Null ()
507 UriParser.IsKnownScheme (null);
511 [ExpectedException (typeof (ArgumentOutOfRangeException))]
512 public void IsKnownScheme_Empty ()
514 UriParser.IsKnownScheme (String.Empty);
518 public void Register ()
520 string scheme = prefix + "register.mono";
521 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
523 UnitTestUriParser p = new UnitTestUriParser ();
524 UriParser.Register (p, scheme, 2005);
525 Assert.AreEqual (scheme, p.SchemeName, "SchemeName");
526 Assert.AreEqual (2005, p.DefaultPort, "DefaultPort");
528 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
532 [ExpectedException (typeof (ArgumentNullException))]
533 public void Register_NullParser ()
535 UriParser.Register (null, prefix + "null.parser", 2006);
539 [ExpectedException (typeof (ArgumentNullException))]
540 public void Register_NullScheme ()
542 UnitTestUriParser p = new UnitTestUriParser ();
543 UriParser.Register (p, null, 2006);
547 [ExpectedException (typeof (ArgumentOutOfRangeException))]
548 public void Register_NegativePort ()
550 UnitTestUriParser p = new UnitTestUriParser ();
551 UriParser.Register (p, prefix + "negative.port", -2);
555 public void Register_Minus1Port ()
557 UnitTestUriParser p = new UnitTestUriParser ();
558 UriParser.Register (p, prefix + "minus1.port", -1);
562 public void Register_UInt16PortMinus1 ()
564 UnitTestUriParser p = new UnitTestUriParser ();
565 UriParser.Register (p, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1);
569 [ExpectedException (typeof (ArgumentOutOfRangeException))]
570 public void Register_TooBigPort ()
572 UnitTestUriParser p = new UnitTestUriParser ();
573 UriParser.Register (p, prefix + "too.big.port", UInt16.MaxValue);
577 [ExpectedException (typeof (InvalidOperationException))]
578 public void ReRegister ()
580 string scheme = prefix + "re.register.mono";
581 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
582 UnitTestUriParser p = new UnitTestUriParser ();
583 UriParser.Register (p, scheme, 2005);
584 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
585 UriParser.Register (p, scheme, 2006);