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.
31 using NUnit.Framework;
36 namespace MonoTests.System {
38 public class UnitTestUriParser: UriParser {
40 private string scheme_name;
41 private int default_port;
42 private bool throw_on_register;
43 private bool on_new_uri_called;
45 public UnitTestUriParser ()
49 public UnitTestUriParser (bool throwOnRegister)
51 throw_on_register = throwOnRegister;
54 public string SchemeName
62 public int DefaultPort
70 public bool OnNewUriCalled
74 return on_new_uri_called;
78 public string _GetComponents (Uri uri, UriComponents components, UriFormat format)
80 return base.GetComponents (uri, components, format);
83 public void _InitializeAndValidate (Uri uri, out UriFormatException parserError)
85 base.InitializeAndValidate (uri, out parserError);
88 public bool _IsBaseOf (Uri baseUri, Uri relativeUri)
90 return base.IsBaseOf (baseUri, relativeUri);
93 public bool _IsWellFormedOriginalString (Uri uri)
95 return base.IsWellFormedOriginalString (uri);
98 public UriParser _OnNewUri ()
100 return base.OnNewUri ();
103 public void _OnRegister (string schemeName, int defaultPort)
105 base.OnRegister (schemeName, defaultPort);
108 public string _Resolve (Uri baseUri, Uri relativeUri, out UriFormatException parserError)
110 return base.Resolve (baseUri, relativeUri, out parserError);
113 protected override UriParser OnNewUri ()
115 on_new_uri_called = true;
116 return base.OnNewUri ();
119 protected override void OnRegister (string schemeName, int defaultPort)
121 if (throw_on_register)
122 throw new NotSupportedException ();
123 scheme_name = schemeName;
124 default_port = defaultPort;
125 base.OnRegister (schemeName, defaultPort);
130 public class UriParserTest {
132 private const string full_http = "http://www.mono-project.com/Main_Page#FAQ?Edit";
134 private string prefix;
136 private Uri ftp, ftp2;
139 public void FixtureSetUp ()
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");
145 // Uses percent encoding on the username and password
146 ftp2 = new Uri ("ftp://%75sername%3a%70assword@ftp.go-mono.com:21/with some spaces/mono.tgz");
162 public void GetComponents ()
164 UnitTestUriParser p = new UnitTestUriParser ();
165 Assert.AreEqual ("http", p._GetComponents (http, UriComponents.Scheme, UriFormat.SafeUnescaped), "http.Scheme");
166 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.UserInfo, UriFormat.SafeUnescaped), "http.UserInfo");
167 Assert.AreEqual ("www.mono-project.com", p._GetComponents (http, UriComponents.Host, UriFormat.SafeUnescaped), "http.Host");
168 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Port, UriFormat.SafeUnescaped), "http.Port");
169 Assert.AreEqual ("Main_Page", p._GetComponents (http, UriComponents.Path, UriFormat.SafeUnescaped), "http.Path");
170 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.Query, UriFormat.SafeUnescaped), "http.Query");
171 Assert.AreEqual ("FAQ?Edit", p._GetComponents (http, UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Fragment");
172 Assert.AreEqual ("80", p._GetComponents (http, UriComponents.StrongPort, UriFormat.SafeUnescaped), "http.StrongPort");
173 Assert.AreEqual (String.Empty, p._GetComponents (http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped), "http.KeepDelimiter");
174 Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.HostAndPort, UriFormat.SafeUnescaped), "http.HostAndPort");
175 Assert.AreEqual ("www.mono-project.com:80", p._GetComponents (http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped), "http.StrongAuthority");
176 Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped), "http.AbsoluteUri");
177 Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped), "http.PathAndQuery");
178 Assert.AreEqual ("http://www.mono-project.com/Main_Page", p._GetComponents (http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped), "http.HttpRequestUrl");
179 Assert.AreEqual ("http://www.mono-project.com", p._GetComponents (http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped), "http.SchemeAndServer");
180 Assert.AreEqual (full_http, p._GetComponents (http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), "http.SerializationInfoString");
182 Assert.AreEqual ("http://", p._GetComponents (http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped), "http.Scheme+Port");
183 Assert.AreEqual ("www.mono-project.com#FAQ?Edit", p._GetComponents (http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped), "http.Scheme+Port");
184 Assert.AreEqual ("/Main_Page", p._GetComponents (http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped), "http.Scheme+Port");
185 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
189 public void GetComponents_Ftp ()
191 UnitTestUriParser p = new UnitTestUriParser ();
192 Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
193 Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
194 Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
195 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
196 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
197 Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
198 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
199 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
200 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
201 Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
202 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
203 Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
204 Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
205 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
206 Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
207 Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
208 Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
209 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
210 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
212 Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
213 Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
217 public void GetComponents_Ftp2 ()
219 UnitTestUriParser p = new UnitTestUriParser ();
220 Assert.AreEqual ("ftp", p._GetComponents (ftp, UriComponents.Scheme, UriFormat.Unescaped), "ftp.Scheme");
221 Assert.AreEqual ("username:password", p._GetComponents (ftp, UriComponents.UserInfo, UriFormat.Unescaped), "ftp.UserInfo");
222 Assert.AreEqual ("ftp.go-mono.com", p._GetComponents (ftp, UriComponents.Host, UriFormat.Unescaped), "ftp.Host");
223 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Port, UriFormat.Unescaped), "ftp.Port");
224 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.Unescaped), "ftp.Path");
225 Assert.AreEqual ("with%20some%20spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.UriEscaped), "ftp.Path-UriEscaped");
226 Assert.AreEqual ("with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path, UriFormat.SafeUnescaped), "ftp.Path-SafeUnescaped");
227 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Query, UriFormat.Unescaped), "ftp.Query");
228 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.Fragment, UriFormat.Unescaped), "ftp.Fragment");
229 Assert.AreEqual ("21", p._GetComponents (ftp, UriComponents.StrongPort, UriFormat.Unescaped), "ftp.StrongPort");
230 Assert.AreEqual (String.Empty, p._GetComponents (ftp, UriComponents.KeepDelimiter, UriFormat.Unescaped), "http.KeepDelimiter");
231 Assert.AreEqual ("ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.HostAndPort, UriFormat.Unescaped), "http.HostAndPort");
232 Assert.AreEqual ("username:password@ftp.go-mono.com:21", p._GetComponents (ftp, UriComponents.StrongAuthority, UriFormat.Unescaped), "http.StrongAuthority");
233 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.AbsoluteUri, UriFormat.Unescaped), "http.AbsoluteUri");
234 Assert.AreEqual ("/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.PathAndQuery, UriFormat.Unescaped), "http.PathAndQuery");
235 Assert.AreEqual ("ftp://ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.HttpRequestUrl, UriFormat.Unescaped), "http.HttpRequestUrl");
236 Assert.AreEqual ("ftp://ftp.go-mono.com", p._GetComponents (ftp, UriComponents.SchemeAndServer, UriFormat.Unescaped), "http.SchemeAndServer");
237 Assert.AreEqual ("ftp://username:password@ftp.go-mono.com/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.SerializationInfoString, UriFormat.Unescaped), "http.SerializationInfoString");
238 Assert.AreSame (p, p._OnNewUri (), "OnNewUri");
240 Assert.AreEqual ("ftp://username:password@", p._GetComponents (ftp, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped), "ftp.Scheme+UserInfo");
241 Assert.AreEqual (":21/with some spaces/mono.tgz", p._GetComponents (ftp, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped), "ftp.Path+StrongPort");
244 // Test case for Xamarin#17665
246 public void TestParseUserPath ()
248 var u = new Uri("https://a.net/1@1.msg");
249 var result = u.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
250 Assert.AreEqual (result, "https://a.net/1@1.msg", "parse@InUrl");
255 [ExpectedException (typeof (NullReferenceException))]
256 public void GetComponents_Null ()
258 UnitTestUriParser p = new UnitTestUriParser ();
259 p._GetComponents (null, UriComponents.Host, UriFormat.SafeUnescaped);
263 public void GetComponents_BadUriComponents ()
265 UnitTestUriParser p = new UnitTestUriParser ();
266 Assert.AreEqual (full_http, p._GetComponents (http, (UriComponents) Int32.MinValue, UriFormat.SafeUnescaped), "http");
270 [ExpectedException (typeof (ArgumentOutOfRangeException))]
271 public void GetComponents_BadUriFormat ()
273 UnitTestUriParser p = new UnitTestUriParser ();
274 p._GetComponents (http, UriComponents.Host, (UriFormat) Int32.MinValue);
278 public void InitializeAndValidate ()
280 UriFormatException error = null;
281 UnitTestUriParser p = new UnitTestUriParser ();
282 p._InitializeAndValidate (http, out error);
283 Assert.IsNotNull (error, "out"); // authority/host couldn't be parsed ?!?!
287 [ExpectedException (typeof (NullReferenceException))]
288 // oh man, this is a bad boy.It should be ArgumentNullException.
289 public void InitializeAndValidate_Null ()
291 UriFormatException error = null;
292 UnitTestUriParser p = new UnitTestUriParser ();
293 p._InitializeAndValidate (null, out error);
297 public void IsBaseOf ()
299 UnitTestUriParser p = new UnitTestUriParser ();
300 Assert.IsTrue (p._IsBaseOf (http, http), "http-http");
302 Uri u = new Uri ("http://www.mono-project.com/Main_Page#FAQ");
303 Assert.IsTrue (p._IsBaseOf (u, http), "http-1a");
304 Assert.IsTrue (p._IsBaseOf (http, u), "http-1b");
306 u = new Uri ("http://www.mono-project.com/Main_Page");
307 Assert.IsTrue (p._IsBaseOf (u, http), "http-2a");
308 Assert.IsTrue (p._IsBaseOf (http, u), "http-2b");
310 u = new Uri ("http://www.mono-project.com/");
311 Assert.IsTrue (p._IsBaseOf (u, http), "http-3a");
312 Assert.IsTrue (p._IsBaseOf (http, u), "http-3b");
314 u = new Uri ("http://www.mono-project.com/Main_Page/");
315 Assert.IsFalse (p._IsBaseOf (u, http), "http-4a");
316 Assert.IsTrue (p._IsBaseOf (http, u), "http-4b");
318 // docs says the UserInfo isn't evaluated, but...
319 u = new Uri ("http://username:password@www.mono-project.com/Main_Page");
320 Assert.IsFalse (p._IsBaseOf (u, http), "http-5a");
321 Assert.IsFalse (p._IsBaseOf (http, u), "http-5b");
323 // scheme case sensitive ? no
324 u = new Uri ("HTTP://www.mono-project.com/Main_Page");
325 Assert.IsTrue (p._IsBaseOf (u, http), "http-6a");
326 Assert.IsTrue (p._IsBaseOf (http, u), "http-6b");
328 // host case sensitive ? no
329 u = new Uri ("http://www.Mono-Project.com/Main_Page");
330 Assert.IsTrue (p._IsBaseOf (u, http), "http-7a");
331 Assert.IsTrue (p._IsBaseOf (http, u), "http-7b");
333 // path case sensitive ? no
334 u = new Uri ("http://www.Mono-Project.com/MAIN_Page");
335 Assert.IsTrue (p._IsBaseOf (u, http), "http-8a");
336 Assert.IsTrue (p._IsBaseOf (http, u), "http-8b");
339 u = new Uri ("ftp://www.mono-project.com/Main_Page");
340 Assert.IsFalse (p._IsBaseOf (u, http), "http-9a");
341 Assert.IsFalse (p._IsBaseOf (http, u), "http-9b");
344 u = new Uri ("http://www.go-mono.com/Main_Page");
345 Assert.IsFalse (p._IsBaseOf (u, http), "http-10a");
346 Assert.IsFalse (p._IsBaseOf (http, u), "http-10b");
349 u = new Uri ("http://www.mono-project.com:8080/");
350 Assert.IsFalse (p._IsBaseOf (u, http), "http-11a");
351 Assert.IsFalse (p._IsBaseOf (http, u), "http-11b");
353 // specify default port
354 u = new Uri ("http://www.mono-project.com:80/");
355 Assert.IsTrue (p._IsBaseOf (u, http), "http-12a");
356 Assert.IsTrue (p._IsBaseOf (http, u), "http-12b");
360 [ExpectedException (typeof (NullReferenceException))]
361 public void IsBaseOf_UriNull ()
363 UnitTestUriParser p = new UnitTestUriParser ();
364 p._IsBaseOf (http, null);
368 [ExpectedException (typeof (NullReferenceException))]
369 public void IsBaseOf_NullUri ()
371 UnitTestUriParser p = new UnitTestUriParser ();
372 p._IsBaseOf (null, http);
376 [Category ("NotWorking")]
377 public void IsWellFormedOriginalString ()
379 UnitTestUriParser p = new UnitTestUriParser ();
380 Assert.IsTrue (p._IsWellFormedOriginalString (http), "http");
384 [ExpectedException (typeof (NullReferenceException))]
385 [Category ("NotWorking")]
386 public void IsWellFormedOriginalString_Null ()
388 UnitTestUriParser p = new UnitTestUriParser ();
389 p._IsWellFormedOriginalString (null);
393 [Category ("NotWorking")]
394 public void OnNewUri ()
396 string scheme = prefix + "on.new.uri";
397 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
399 UnitTestUriParser p = new UnitTestUriParser ();
400 UriParser.Register (p, scheme, 1999);
402 Assert.IsFalse (p.OnNewUriCalled, "!Called");
403 Uri uri = new Uri (scheme + "://www.mono-project.com");
404 Assert.IsTrue (p.OnNewUriCalled, "Called");
408 public void OnRegister ()
410 string scheme = prefix + "onregister";
411 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
412 UnitTestUriParser p = new UnitTestUriParser ();
414 UriParser.Register (p, scheme, 2005);
416 catch (NotSupportedException) {
417 // special case / ordering
419 // if true then the registration is done before calling OnRegister
420 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
424 [Category ("NotWorking")]
425 public void OnRegister2 ()
427 string scheme = prefix + "onregister2";
428 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
429 UnitTestUriParser p = new UnitTestUriParser ();
431 UriParser.Register (p, scheme, 2005);
432 Uri uri = new Uri (scheme + "://foobar:2005");
433 Assert.AreEqual (scheme, uri.Scheme, "uri-prefix");
434 Assert.AreEqual (2005, uri.Port, "uri-port");
436 Assert.AreEqual ("//foobar:2005", uri.LocalPath, "uri-localpath");
438 catch (NotSupportedException) {
439 // special case / ordering
441 // if true then the registration is done before calling OnRegister
442 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
446 [Category ("NotWorking")]
447 public void Resolve ()
449 UriFormatException error = null;
450 UnitTestUriParser p = new UnitTestUriParser ();
451 Assert.AreEqual (full_http, p._Resolve (http, http, out error), "http-http");
455 [Category ("NotWorking")]
456 public void Resolve_UriNull ()
458 UriFormatException error = null;
459 UnitTestUriParser p = new UnitTestUriParser ();
460 Assert.AreEqual (full_http, p._Resolve (http, null, out error), "http-http");
464 [ExpectedException (typeof (NullReferenceException))]
465 [Category ("NotWorking")]
466 public void Resolve_NullUri ()
468 UriFormatException error = null;
469 UnitTestUriParser p = new UnitTestUriParser ();
470 p._Resolve (null, http, out error);
471 p._Resolve (http, null, out error);
475 public void IsKnownScheme_WellKnown ()
477 // from Uri.UriScheme* fields
478 Assert.IsTrue (UriParser.IsKnownScheme ("file"), "file");
479 Assert.IsTrue (UriParser.IsKnownScheme ("ftp"), "ftp");
480 Assert.IsTrue (UriParser.IsKnownScheme ("gopher"), "gopher");
481 Assert.IsTrue (UriParser.IsKnownScheme ("http"), "http");
482 Assert.IsTrue (UriParser.IsKnownScheme ("https"), "https");
483 Assert.IsTrue (UriParser.IsKnownScheme ("mailto"), "mailto");
484 Assert.IsTrue (UriParser.IsKnownScheme ("net.pipe"), "net.pipe");
485 Assert.IsTrue (UriParser.IsKnownScheme ("net.tcp"), "net.tcp");
486 Assert.IsTrue (UriParser.IsKnownScheme ("news"), "news");
487 Assert.IsTrue (UriParser.IsKnownScheme ("nntp"), "nntp");
488 // inferred from class library
489 Assert.IsTrue (UriParser.IsKnownScheme ("ldap"), "ldap");
490 Assert.IsFalse (UriParser.IsKnownScheme ("ldaps"), "ldaps");
491 // well known for not existing
492 Assert.IsFalse (UriParser.IsKnownScheme ("unknown"), "unknown");
494 // variations - mixed and upper case
495 Assert.IsTrue (UriParser.IsKnownScheme ("FiLe"), "FiLe");
496 Assert.IsTrue (UriParser.IsKnownScheme ("FTP"), "ftp");
499 Assert.IsFalse (UriParser.IsKnownScheme ("tcp"), "tcp");
503 [ExpectedException (typeof (ArgumentOutOfRangeException))]
504 [Category ("NotWorking")]
505 public void IsKnownScheme_ExtraSpace ()
507 // same result for space before, inside or after the scheme
508 UriParser.IsKnownScheme ("ht tp");
509 // this is undocumented (and I hate exceptions in a boolean method)
513 [ExpectedException (typeof (ArgumentNullException))]
514 public void IsKnownScheme_Null ()
516 UriParser.IsKnownScheme (null);
520 [ExpectedException (typeof (ArgumentOutOfRangeException))]
521 public void IsKnownScheme_Empty ()
523 UriParser.IsKnownScheme (String.Empty);
527 public void Register ()
529 string scheme = prefix + "register.mono";
530 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
532 UnitTestUriParser p = new UnitTestUriParser ();
533 UriParser.Register (p, scheme, 2005);
534 Assert.AreEqual (scheme, p.SchemeName, "SchemeName");
535 Assert.AreEqual (2005, p.DefaultPort, "DefaultPort");
537 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
541 [ExpectedException (typeof (ArgumentNullException))]
542 public void Register_NullParser ()
544 UriParser.Register (null, prefix + "null.parser", 2006);
548 [ExpectedException (typeof (ArgumentNullException))]
549 public void Register_NullScheme ()
551 UnitTestUriParser p = new UnitTestUriParser ();
552 UriParser.Register (p, null, 2006);
556 [ExpectedException (typeof (ArgumentOutOfRangeException))]
557 public void Register_NegativePort ()
559 UnitTestUriParser p = new UnitTestUriParser ();
560 UriParser.Register (p, prefix + "negative.port", -2);
564 public void Register_Minus1Port ()
566 UnitTestUriParser p = new UnitTestUriParser ();
567 UriParser.Register (p, prefix + "minus1.port", -1);
571 public void Register_UInt16PortMinus1 ()
573 UnitTestUriParser p = new UnitTestUriParser ();
574 UriParser.Register (p, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1);
578 [ExpectedException (typeof (ArgumentOutOfRangeException))]
579 public void Register_TooBigPort ()
581 UnitTestUriParser p = new UnitTestUriParser ();
582 UriParser.Register (p, prefix + "too.big.port", UInt16.MaxValue);
586 [ExpectedException (typeof (InvalidOperationException))]
587 public void ReRegister ()
589 string scheme = prefix + "re.register.mono";
590 Assert.IsFalse (UriParser.IsKnownScheme (scheme), "IsKnownScheme-false");
591 UnitTestUriParser p = new UnitTestUriParser ();
592 UriParser.Register (p, scheme, 2005);
593 Assert.IsTrue (UriParser.IsKnownScheme (scheme), "IsKnownScheme-true");
594 UriParser.Register (p, scheme, 2006);