1 //
2 // UriTest2.cs - More NUnit Test Cases for System.Uri
3 //
4 
5 using System;
6 using System.IO;
7 using System.Reflection;
8 using System.Text;
9 using NUnit.Framework;
10 
11 namespace MonoTests.System
12 {
13 	// help bring Moonlight tests back to mono/mcs nunit
14 
TestCode()15 	public delegate void TestCode ();
16 
17 	static class Assert2 {
18 
19 		public static void Throws<TException> (TestCode code, string message) where TException : Exception
20 		{
21 			Throws (code, typeof (TException), null, message);
22 		}
23 
Throws(TestCode code, Type expected_exception, Type expected_inner_exception, string message)24 		public static void Throws (TestCode code, Type expected_exception, Type expected_inner_exception, string message)
25 		{
26 			bool failed = false;
27 			try {
28 				code ();
29 				failed = true;
30 			}
31 			catch (Exception ex) {
32 				if (!(ex.GetType () == expected_exception))
33 					throw new AssertionException (string.Format ("Expected '{0}', got '{1}'. {2}", expected_exception.FullName, ex.GetType ().FullName, message));
34 				//System.Diagnostics.Debug.WriteLine (ex.ToString ());
35 				if (expected_inner_exception != null) {
36 					// we only check if the inner exception was supplied
37 					if (ex.InnerException.GetType () != expected_inner_exception)
38 						throw new AssertionException (string.Format ("Expected InnerException '{0}', got '{1}'. {2}", expected_inner_exception.FullName, ex.InnerException.GetType ().FullName, message));
39 				}
40 			}
41 			if (failed)
42 				throw new AssertionException (string.Format ("Expected '{0}', but got no exception. {1}", expected_exception.FullName, message));
43 		}
44 	}
45 
46 	[TestFixture]
47 	public class UriTest2
48 	{
49 		protected bool isWin32 = false;
50 		public bool IriParsing;
51 
52 		[SetUp]
SetUp()53 		public void SetUp ()
54 		{
55 			isWin32 = (Path.DirectorySeparatorChar == '\\');
56 
57 			//Make sure Uri static constructor is called
58 			Uri.EscapeDataString ("");
59 
60 			FieldInfo iriParsingField = typeof (Uri).GetField ("s_IriParsing",
61 				BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
62 			if (iriParsingField != null)
63 				IriParsing = (bool)iriParsingField.GetValue (null);
64 		}
65 
66 		// Segments cannot be validated here...
AssertUri(string relsrc, Uri uri, string toString, string absoluteUri, string scheme, string host, string localPath, string query, int port, bool isFile, bool isUnc, bool isLoopback, bool userEscaped, UriHostNameType hostNameType, string absolutePath, string pathAndQuery, string authority, string fragment, string userInfo)67 		public void AssertUri (string relsrc, Uri uri,
68 			string toString,
69 			string absoluteUri,
70 			string scheme,
71 			string host,
72 			string localPath,
73 			string query,
74 			int port,
75 			bool isFile,
76 			bool isUnc,
77 			bool isLoopback,
78 			bool userEscaped,
79 			UriHostNameType hostNameType,
80 			string absolutePath,
81 			string pathAndQuery,
82 			string authority,
83 			string fragment,
84 			string userInfo)
85 		{
86 			Assert.AreEqual (absoluteUri, uri.AbsoluteUri, relsrc + " AbsoluteUri");
87 			Assert.AreEqual (scheme, uri.Scheme, relsrc + " Scheme");
88 			Assert.AreEqual (host, uri.Host, relsrc + " Host");
89 			Assert.AreEqual (port, uri.Port, relsrc + " Port");
90 			// Windows UNC path is not automatically testable on *nix environment,
91 			if (relsrc.StartsWith ("\\\\") && Path.DirectorySeparatorChar == '\\')
92 				Assert.AreEqual (localPath, uri.LocalPath, relsrc + " LocalPath");
93 			Assert.AreEqual (query, uri.Query, relsrc + " Query");
94 			Assert.AreEqual (fragment, uri.Fragment, relsrc + " Fragment");
95 			Assert.AreEqual (isFile, uri.IsFile, relsrc + " IsFile");
96 			Assert.AreEqual (isUnc, uri.IsUnc, relsrc + " IsUnc");
97 			Assert.AreEqual (isLoopback, uri.IsLoopback, relsrc + " IsLoopback");
98 			Assert.AreEqual (authority, uri.Authority, relsrc + " Authority");
99 			Assert.AreEqual (userEscaped, uri.UserEscaped, relsrc + " UserEscaped");
100 			Assert.AreEqual (userInfo, uri.UserInfo, relsrc + " UserInfo");
101 			Assert.AreEqual (hostNameType, uri.HostNameType, relsrc + " HostNameType");
102 			Assert.AreEqual (absolutePath, uri.AbsolutePath, relsrc + " AbsolutePath");
103 			Assert.AreEqual (pathAndQuery, uri.PathAndQuery, relsrc + " PathAndQuery");
104 			Assert.AreEqual (toString, uri.ToString (), relsrc + " ToString()");
105 		}
106 
107 		[Test]
108 		[Ignore ("Tests needs to be updated for 2.0")]
AbsoluteUriFromFile()109 		public void AbsoluteUriFromFile ()
110 		{
111 			FromResource ("test-uri-props.txt", null);
112 		}
113 
114 		[Test]
115 		[Category("NotDotNet")]
116 		[Ignore ("Tests needs to be updated for 2.0")]
AbsoluteUriFromFileManual()117 		public void AbsoluteUriFromFileManual ()
118 		{
119 			if (Path.DirectorySeparatorChar == '\\')
120 				return;
121 			FromResource ("test-uri-props-manual.txt", null);
122 		}
123 
124 		[Test]
125 		[Ignore ("Tests needs to be updated for 2.0")]
RelativeUriFromFile()126 		public void RelativeUriFromFile ()
127 		{
128 			FromResource ("test-uri-relative-props.txt", new Uri ("http://www.go-mono.com"));
129 		}
130 
FromResource(string res, Uri baseUri)131 		private void FromResource (string res, Uri baseUri)
132 		{
133 			Assembly a = Assembly.GetExecutingAssembly ();
134 			Stream s = a.GetManifestResourceStream (res);
135 			StreamReader sr = new StreamReader (s, Encoding.UTF8);
136 			while (sr.Peek () > 0) {
137 				sr.ReadLine (); // skip
138 				string uriString = sr.ReadLine ();
139 /*
140 TextWriter sw = Console.Out;
141 				sw.WriteLine ("-------------------------");
142 				sw.WriteLine (uriString);
143 */
144 				if (uriString == null || uriString.Length == 0)
145 					break;
146 
147 				try {
148 					Uri uri = baseUri == null ? new Uri (uriString) : new Uri (baseUri, uriString);
149 /*
150 				sw.WriteLine ("ToString(): " + uri.ToString ());
151 				sw.WriteLine (uri.AbsoluteUri);
152 				sw.WriteLine (uri.Scheme);
153 				sw.WriteLine (uri.Host);
154 				sw.WriteLine (uri.LocalPath);
155 				sw.WriteLine (uri.Query);
156 				sw.WriteLine ("Port: " + uri.Port);
157 				sw.WriteLine (uri.IsFile);
158 				sw.WriteLine (uri.IsUnc);
159 				sw.WriteLine (uri.IsLoopback);
160 				sw.WriteLine (uri.UserEscaped);
161 				sw.WriteLine ("HostNameType: " + uri.HostNameType);
162 				sw.WriteLine (uri.AbsolutePath);
163 				sw.WriteLine ("PathAndQuery: " + uri.PathAndQuery);
164 				sw.WriteLine (uri.Authority);
165 				sw.WriteLine (uri.Fragment);
166 				sw.WriteLine (uri.UserInfo);
167 */
168 					AssertUri (uriString, uri,
169 						sr.ReadLine (),
170 						sr.ReadLine (),
171 						sr.ReadLine (),
172 						sr.ReadLine (),
173 						sr.ReadLine (),
174 						sr.ReadLine (),
175 						int.Parse (sr.ReadLine ()),
176 						bool.Parse (sr.ReadLine ()),
177 						bool.Parse (sr.ReadLine ()),
178 						bool.Parse (sr.ReadLine ()),
179 						bool.Parse (sr.ReadLine ()),
180 						(UriHostNameType) Enum.Parse (typeof (UriHostNameType), sr.ReadLine (), false),
181 						sr.ReadLine (),
182 						sr.ReadLine (),
183 						sr.ReadLine (),
184 						sr.ReadLine (),
185 						sr.ReadLine ());
186 //				Console.WriteLine ("Passed: " + uriString);
187 				} catch (UriFormatException ex) {
188 					Assert.Fail (String.Format ("Construction failed: [{0}] {1}", uriString, ex.Message));
189 				}
190 			}
191 		}
192 
193 		[Test]
MoreUnescape()194 		public void MoreUnescape () // bug 733316
195 		{
196 			int index = 0;
197 			char unesc = Uri.HexUnescape ("%F6", ref index);
198 			Assert.AreEqual (3, index, "#01");
199 			Assert.AreEqual (0xf6, unesc, "#02");
200 		}
201 
202 		[Test]
UriScheme()203 		public void UriScheme ()
204 		{
205 			Assert.AreEqual ("://", Uri.SchemeDelimiter, "://");
206 			Assert.AreEqual ("file", Uri.UriSchemeFile, "file");
207 			Assert.AreEqual ("ftp", Uri.UriSchemeFtp, "ftp");
208 			Assert.AreEqual ("gopher", Uri.UriSchemeGopher, "gopher");
209 			Assert.AreEqual ("http", Uri.UriSchemeHttp, "http");
210 			Assert.AreEqual ("https", Uri.UriSchemeHttps, "https");
211 			Assert.AreEqual ("mailto", Uri.UriSchemeMailto, "mailto");
212 			Assert.AreEqual ("news", Uri.UriSchemeNews, "news");
213 			Assert.AreEqual ("nntp", Uri.UriSchemeNntp, "file");
214 			Assert.AreEqual ("net.pipe", Uri.UriSchemeNetPipe, "net.pipe");
215 			Assert.AreEqual ("net.tcp", Uri.UriSchemeNetTcp, "net.tcp");
216 		}
217 
218 		[Test] // bug #71049
219 		[ExpectedException (typeof (UriFormatException))]
StarsInHost()220 		public void StarsInHost ()
221 		{
222 			new Uri ("http://w*w*w.go-mono.com");
223 		}
224 
225 		[Test]
NoHostName1_Bug76146()226 		public void NoHostName1_Bug76146 ()
227 		{
228 			Uri u = new Uri ("foo:///?bar");
229 			Assert.AreEqual ("/", u.AbsolutePath, "AbsolutePath");
230 			Assert.AreEqual ("foo:///?bar", u.AbsoluteUri, "AbsoluteUri");
231 			Assert.AreEqual (String.Empty, u.Authority, "Authority");
232 			Assert.AreEqual (String.Empty, u.Fragment, "Fragment");
233 			Assert.AreEqual (String.Empty, u.Host, "Host");
234 			// FIXME (2.0) - Normally this is never Basic without an Host name :(
235 			// Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "HostNameType");
236 			Assert.IsTrue (u.IsDefaultPort, "IsDefaultPort");
237 			Assert.IsFalse (u.IsFile, "IsFile");
238 			// FIXME Assert.IsTrue (u.IsLoopback, "IsLoopback");
239 			Assert.IsFalse (u.IsUnc, "IsUnc");
240 			Assert.AreEqual ("/", u.LocalPath, "LocalPath");
241 			Assert.AreEqual ("/?bar", u.PathAndQuery, "PathAndQuery");
242 			Assert.AreEqual ("foo", u.Scheme, "Scheme");
243 			Assert.IsFalse (u.UserEscaped, "UserEscaped");
244 			Assert.AreEqual (String.Empty, u.UserInfo, "UserInfo");
245 		}
246 
247 		[Test]
NoHostName2_Bug76146()248 		public void NoHostName2_Bug76146 ()
249 		{
250 			Uri u = new Uri ("foo:///bar");
251 			Assert.AreEqual ("/bar", u.AbsolutePath, "AbsolutePath");
252 			Assert.AreEqual ("foo:///bar", u.AbsoluteUri, "AbsoluteUri");
253 			Assert.AreEqual (String.Empty, u.Authority, "Authority");
254 			Assert.AreEqual (String.Empty, u.Fragment, "Fragment");
255 			Assert.AreEqual (String.Empty, u.Host, "Host");
256 			// FIXME (2.0) - Normally this is never Basic without an Host name :(
257 			// Assert.AreEqual (UriHostNameType.Basic, u.HostNameType, "HostNameType");
258 			Assert.IsTrue (u.IsDefaultPort, "IsDefaultPort");
259 			Assert.IsFalse (u.IsFile, "IsFile");
260 			// FIXME Assert.IsTrue (u.IsLoopback, "IsLoopback");
261 			Assert.IsFalse (u.IsUnc, "IsUnc");
262 			Assert.AreEqual ("/bar", u.LocalPath, "LocalPath");
263 			Assert.AreEqual ("/bar", u.PathAndQuery, "PathAndQuery");
264 			Assert.AreEqual ("foo", u.Scheme, "Scheme");
265 			Assert.IsFalse (u.UserEscaped, "UserEscaped");
266 			Assert.AreEqual (String.Empty, u.UserInfo, "UserInfo");
267 		}
268 
269 		[Test]
270 		[ExpectedException (typeof (UriFormatException))]
InvalidIPAddress_Bug76659()271 		public void InvalidIPAddress_Bug76659 ()
272 		{
273 			new Uri ("http://127.0.0.1::::/");
274 		}
275 
276 		[Test]
File()277 		public void File ()
278 		{
279 			string s = "file:///dir1%2f..%2fdir%2fapp.xap#header";
280 			Uri uri = new Uri (s);
281 			Assert.AreEqual ("/dir/app.xap", uri.AbsolutePath, "AbsolutePath");
282 			// default port is removed
283 			Assert.AreEqual ("file:///dir/app.xap#header", uri.AbsoluteUri, "AbsoluteUri");
284 			Assert.AreEqual (String.Empty, uri.DnsSafeHost, "DnsSafeHost");
285 			Assert.AreEqual ("#header", uri.Fragment, "Fragment");
286 			Assert.AreEqual (String.Empty, uri.Host, "Host");
287 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
288 			Assert.IsFalse (uri.IsUnc, "IsUnc");
289 			Assert.AreEqual ("/dir/app.xap", uri.LocalPath, "LocalPath");
290 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
291 			Assert.AreEqual (-1, uri.Port, "Port");
292 			Assert.AreEqual (String.Empty, uri.Query, "Query");
293 			Assert.AreEqual ("file", uri.Scheme, "Scheme");
294 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
295 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
296 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
297 		}
298 
299 		[Test]
HttpWithDefaultPort()300 		public void HttpWithDefaultPort ()
301 		{
302 			string s = "HTTP://host.domain.com:80/app.xap";
303 			Uri uri = new Uri (s);
304 			Assert.AreEqual ("/app.xap", uri.AbsolutePath, "AbsolutePath");
305 			// default port is removed
306 			Assert.AreEqual ("http://host.domain.com/app.xap", uri.AbsoluteUri, "AbsoluteUri");
307 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
308 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
309 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
310 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
311 			Assert.IsFalse (uri.IsUnc, "IsUnc");
312 			Assert.AreEqual ("/app.xap", uri.LocalPath, "LocalPath");
313 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
314 			Assert.AreEqual (80, uri.Port, "Port");
315 			Assert.AreEqual (String.Empty, uri.Query, "Query");
316 			Assert.AreEqual ("http", uri.Scheme, "Scheme");
317 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
318 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
319 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
320 		}
321 
322 		[Test]
HttpWithoutPort()323 		public void HttpWithoutPort ()
324 		{
325 			string s = "Http://host.DOMAIN.com/dir/app.xap#options";
326 			Uri uri = new Uri (s);
327 			Assert.AreEqual ("/dir/app.xap", uri.AbsolutePath, "AbsolutePath");
328 			Assert.AreEqual ("http://host.domain.com/dir/app.xap#options", uri.AbsoluteUri, "AbsoluteUri");
329 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
330 			Assert.AreEqual ("#options", uri.Fragment, "Fragment");
331 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
332 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
333 			Assert.IsFalse (uri.IsUnc, "IsUnc");
334 			Assert.AreEqual ("/dir/app.xap", uri.LocalPath, "LocalPath");
335 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
336 			Assert.AreEqual (80, uri.Port, "Port");
337 			Assert.AreEqual (String.Empty, uri.Query, "Query");
338 			Assert.AreEqual ("http", uri.Scheme, "Scheme");
339 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
340 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
341 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
342 		}
343 
344 		[Test]
HttpWithNonStandardPort()345 		public void HttpWithNonStandardPort ()
346 		{
347 			string s = "http://monkey:s3kr3t@HOST.domain.Com:8080/dir/../app.xap?option=1";
348 			Uri uri = new Uri (s);
349 			Assert.AreEqual ("/app.xap", uri.AbsolutePath, "AbsolutePath");
350 			// non-standard port is present
351 			Assert.AreEqual ("http://monkey:s3kr3t@host.domain.com:8080/app.xap?option=1", uri.AbsoluteUri, "AbsoluteUri");
352 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
353 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
354 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
355 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
356 			Assert.IsFalse (uri.IsUnc, "IsUnc");
357 			Assert.AreEqual ("/app.xap", uri.LocalPath, "LocalPath");
358 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
359 			Assert.AreEqual (8080, uri.Port, "Port");
360 			Assert.AreEqual ("?option=1", uri.Query, "Query");
361 			Assert.AreEqual ("http", uri.Scheme, "Scheme");
362 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
363 			Assert.AreEqual ("monkey:s3kr3t", uri.UserInfo, "UserInfo");
364 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
365 		}
366 
367 		[Test]
HttpsWithDefaultPort()368 		public void HttpsWithDefaultPort ()
369 		{
370 			string s = "httpS://host.domain.com:443/";
371 			Uri uri = new Uri (s);
372 			Assert.AreEqual ("/", uri.AbsolutePath, "AbsolutePath");
373 			// default port is removed
374 			Assert.AreEqual ("https://host.domain.com/", uri.AbsoluteUri, "AbsoluteUri");
375 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
376 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
377 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
378 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
379 			Assert.IsFalse (uri.IsUnc, "IsUnc");
380 			Assert.AreEqual ("/", uri.LocalPath, "LocalPath");
381 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
382 			Assert.AreEqual (443, uri.Port, "Port");
383 			Assert.AreEqual (String.Empty, uri.Query, "Query");
384 			Assert.AreEqual ("https", uri.Scheme, "Scheme");
385 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
386 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
387 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
388 		}
389 
390 		[Test]
HttpsWithoutPort()391 		public void HttpsWithoutPort ()
392 		{
393 			string s = "Https://host.DOMAIN.com/dir%2fapp.xap#";
394 			Uri uri = new Uri (s);
395 
396 			if (IriParsing)	{
397 				Assert.AreEqual ("/dir%2fapp.xap", uri.AbsolutePath, "AbsolutePath");
398 				Assert.AreEqual ("https://host.domain.com/dir%2fapp.xap#", uri.AbsoluteUri, "AbsoluteUri");
399 			} else {
400 				Assert.AreEqual ("/dir/app.xap", uri.AbsolutePath, "AbsolutePath");
401 				Assert.AreEqual ("https://host.domain.com/dir/app.xap#", uri.AbsoluteUri, "AbsoluteUri");
402 			}
403 
404 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
405 			Assert.AreEqual ("#", uri.Fragment, "Fragment");
406 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
407 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
408 			Assert.IsFalse (uri.IsUnc, "IsUnc");
409 			Assert.AreEqual ("/dir/app.xap", uri.LocalPath, "LocalPath");
410 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
411 			Assert.AreEqual (443, uri.Port, "Port");
412 			Assert.AreEqual (String.Empty, uri.Query, "Query");
413 			Assert.AreEqual ("https", uri.Scheme, "Scheme");
414 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
415 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
416 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
417 		}
418 
419 		[Test]
HttpsWithNonStandardPort()420 		public void HttpsWithNonStandardPort ()
421 		{
422 			string s = "https://monkey:s3kr3t@HOST.domain.Com:4430/dir/..%5Capp.xap?";
423 			Uri uri = new Uri (s);
424 
425 			if (IriParsing) {
426 				Assert.AreEqual ("/dir/..%5Capp.xap", uri.AbsolutePath, "AbsolutePath");
427 				Assert.AreEqual ("https://monkey:s3kr3t@host.domain.com:4430/dir/..%5Capp.xap?", uri.AbsoluteUri, "AbsoluteUri");
428 				Assert.AreEqual ("/dir/..\\app.xap", uri.LocalPath, "LocalPath");
429 			} else {
430 				Assert.AreEqual ("/app.xap", uri.AbsolutePath, "AbsolutePath");
431 				Assert.AreEqual ("https://monkey:s3kr3t@host.domain.com:4430/app.xap?", uri.AbsoluteUri, "AbsoluteUri");
432 				Assert.AreEqual ("/app.xap", uri.LocalPath, "LocalPath");
433 			}
434 
435 			Assert.AreEqual ("host.domain.com", uri.DnsSafeHost, "DnsSafeHost");
436 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
437 			Assert.AreEqual ("host.domain.com", uri.Host, "Host");
438 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
439 			Assert.IsFalse (uri.IsUnc, "IsUnc");
440 			Assert.AreEqual (s, uri.OriginalString, "OriginalString");
441 			Assert.AreEqual (4430, uri.Port, "Port");
442 			Assert.AreEqual ("?", uri.Query, "Query");
443 			Assert.AreEqual ("https", uri.Scheme, "Scheme");
444 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
445 			Assert.AreEqual ("monkey:s3kr3t", uri.UserInfo, "UserInfo");
446 			Assert.AreEqual (uri.AbsoluteUri, uri.ToString (), "ToString");
447 		}
448 
449 		[Test]
Relative()450 		public void Relative ()
451 		{
452 			Uri relative = new Uri ("/Moonlight", UriKind.Relative);
453 
454 			Assert2.Throws<ArgumentNullException> (delegate {
455 				new Uri (null, "/Moonlight");
456 			}, "null,string");
457 			Assert2.Throws<ArgumentNullException> (delegate {
458 				new Uri (null, relative);
459 			}, "null,Uri");
460 
461 			Assert2.Throws<ArgumentOutOfRangeException> (delegate {
462 				new Uri (relative, "/Moonlight");
463 			}, "Uri,string");
464 			Assert2.Throws<ArgumentOutOfRangeException> (delegate {
465 				new Uri (relative, relative);
466 			}, "Uri,Uri");
467 
468 			Assert2.Throws<ArgumentOutOfRangeException> (delegate {
469 				new Uri (relative, (string) null);
470 			}, "Uri,string-null");
471 			Assert2.Throws<ArgumentOutOfRangeException> (delegate {
472 				new Uri (relative, (Uri) null);
473 			}, "Uri,Uri-null");
474 		}
475 
CheckRelativeUri(Uri uri)476 		private void CheckRelativeUri (Uri uri)
477 		{
478 			Assert2.Throws<InvalidOperationException> (delegate {
479 				Assert.IsNotNull (uri.AbsolutePath);
480 			}, "AbsolutePath");
481 			Assert2.Throws<InvalidOperationException> (delegate {
482 				Assert.IsNotNull (uri.AbsoluteUri);
483 			}, "AbsoluteUri");
484 			Assert2.Throws<InvalidOperationException> (delegate {
485 				Assert.IsNotNull (uri.DnsSafeHost);
486 			}, "DnsSafeHost");
487 			Assert2.Throws<InvalidOperationException> (delegate {
488 				Assert.IsNotNull (uri.Fragment);
489 			}, "Fragment");
490 			Assert2.Throws<InvalidOperationException> (delegate {
491 				Assert.IsNotNull (uri.Host);
492 			}, "Host");
493 
494 			Assert.IsFalse (uri.IsAbsoluteUri, "IsAbsoluteUri");
495 
496 			Assert2.Throws<InvalidOperationException> (delegate {
497 				Assert.IsNotNull (uri.IsUnc);
498 			}, "IsUnc");
499 			Assert2.Throws<InvalidOperationException> (delegate {
500 				Assert.IsNotNull (uri.LocalPath);
501 			}, "LocalPath");
502 
503 			Assert.AreEqual ("/Moonlight", uri.OriginalString, "OriginalString");
504 
505 			Assert2.Throws<InvalidOperationException> (delegate {
506 				Assert.IsNotNull (uri.Port);
507 			}, "Port");
508 			Assert2.Throws<InvalidOperationException> (delegate {
509 				Assert.IsNotNull (uri.Query);
510 			}, "Query");
511 			Assert2.Throws<InvalidOperationException> (delegate {
512 				Assert.IsNotNull (uri.Scheme);
513 			}, "Scheme");
514 
515 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
516 
517 			Assert2.Throws<InvalidOperationException> (delegate {
518 				Assert.IsNotNull (uri.UserInfo);
519 			}, "UserInfo");
520 
521 			Assert.AreEqual ("/Moonlight", uri.ToString (), "ToString");
522 		}
523 
524 		[Test]
Relative_AsRelative()525 		public void Relative_AsRelative ()
526 		{
527 			Uri uri = new Uri ("/Moonlight", UriKind.Relative);
528 			CheckRelativeUri (uri);
529 		}
530 
531 		[Test]
Bug496783()532 		public void Bug496783 ()
533 		{
534 			string s = "tcp://csve2.csse.unimelb.edu.au:9090/Aneka";
535 			Uri uri = new Uri (s);
536 			// this is not parsed by a known UriParser
537 			Assert.IsFalse (UriParser.IsKnownScheme (uri.Scheme), "UriParser");
538 
539 			Uri uri2 = new Uri ("tcp://csve2.csse.unimelb.edu.au:9090/");
540 			Assert.IsTrue (uri2.IsBaseOf (uri), "IsBaseOf");
541 
542 			Assert.AreEqual (uri.AbsoluteUri, uri.GetComponents (UriComponents.AbsoluteUri, UriFormat.Unescaped), "AbsoluteUri");
543 			Assert.AreEqual (uri.Fragment, uri.GetComponents (UriComponents.Fragment, UriFormat.Unescaped), "Fragment");
544 			Assert.AreEqual (uri.Host, uri.GetComponents (UriComponents.Host, UriFormat.Unescaped), "Host");
545 			Assert.AreEqual (uri.Authority, uri.GetComponents (UriComponents.HostAndPort, UriFormat.Unescaped), "HostAndPort");
546 			Assert.AreEqual (uri.AbsoluteUri, uri.GetComponents (UriComponents.HttpRequestUrl, UriFormat.Unescaped), "HttpRequestUrl");
547 			Assert.AreEqual (String.Empty, uri.GetComponents (UriComponents.KeepDelimiter, UriFormat.Unescaped), "KeepDelimiter");
548 			Assert.AreEqual ("Aneka", uri.GetComponents (UriComponents.Path, UriFormat.Unescaped), "Path");
549 			Assert.AreEqual (uri.LocalPath, uri.GetComponents (UriComponents.PathAndQuery, UriFormat.Unescaped), "PathAndQuery");
550 			Assert.AreEqual (uri.Port.ToString (), uri.GetComponents (UriComponents.Port, UriFormat.Unescaped), "Port");
551 			Assert.AreEqual (uri.Query, uri.GetComponents (UriComponents.Query, UriFormat.Unescaped), "Query");
552 			Assert.AreEqual (uri.Scheme, uri.GetComponents (UriComponents.Scheme, UriFormat.Unescaped), "Scheme");
553 			Assert.AreEqual ("tcp://csve2.csse.unimelb.edu.au:9090", uri.GetComponents (UriComponents.SchemeAndServer, UriFormat.Unescaped), "SchemeAndServer");
554 			Assert.AreEqual (uri.OriginalString, uri.GetComponents (UriComponents.SerializationInfoString, UriFormat.Unescaped), "SerializationInfoString");
555 			Assert.AreEqual (uri.Authority, uri.GetComponents (UriComponents.StrongAuthority, UriFormat.Unescaped), "StrongAuthority");
556 			Assert.AreEqual (uri.Port.ToString (), uri.GetComponents (UriComponents.StrongPort, UriFormat.Unescaped), "StrongPort");
557 			Assert.AreEqual (uri.UserInfo, uri.GetComponents (UriComponents.UserInfo, UriFormat.Unescaped), "UserInfo");
558 		}
559 
560 		[Test]
Merge_Query_Fragment()561 		public void Merge_Query_Fragment ()
562 		{
563 			Uri absolute = new Uri ("http://host/dir/subdir/weird;name?moonlight");
564 			Assert.AreEqual ("?moonlight", absolute.Query, "absolute.Query");
565 
566 			Uri merged = new Uri (absolute, "#mono");
567 			Assert.AreEqual ("#mono", merged.Fragment, "merged.Fragment");
568 			Assert.AreEqual ("?moonlight", merged.Query, "merged.Query");
569 			Assert.AreEqual ("http://host/dir/subdir/weird;name?moonlight#mono", merged.ToString (), "merged.ToString");
570 		}
571 
572 		[Test]
Merge_Query_Query()573 		public void Merge_Query_Query ()
574 		{
575 			Uri absolute = new Uri ("http://host/dir/subdir/weird;name?moonlight");
576 			Assert.AreEqual ("?moonlight", absolute.Query, "absolute.Query");
577 
578 			Uri merged = new Uri (absolute, "?moon");
579 			Assert.AreEqual ("?moon", merged.Query, "merged.Query");
580 			Assert.AreEqual ("http://host/dir/subdir/weird;name?moon", merged.ToString (), "merged.ToString");
581 		}
582 
583 		[Test]
Merge_Query_RelativePath()584 		public void Merge_Query_RelativePath ()
585 		{
586 			Uri absolute = new Uri ("http://host/dir/subdir/weird;name?moonlight");
587 			Assert.AreEqual ("?moonlight", absolute.Query, "absolute.Query");
588 
589 			Uri merged = new Uri (absolute, "../");
590 			Assert.AreEqual (String.Empty, merged.Query, "../Query");
591 			Assert.AreEqual ("http://host/dir/", merged.ToString (), "../ToString");
592 
593 			merged = new Uri (absolute, "..");
594 			Assert.AreEqual (String.Empty, merged.Query, "..Query");
595 			Assert.AreEqual ("http://host/dir/", merged.ToString (), "..ToString");
596 
597 			merged = new Uri (absolute, "./");
598 			Assert.AreEqual (String.Empty, merged.Query, "./Query");
599 			Assert.AreEqual ("http://host/dir/subdir/", merged.ToString (), "./ToString");
600 
601 			merged = new Uri (absolute, ".");
602 			Assert.AreEqual (String.Empty, merged.Query, ".Query");
603 			Assert.AreEqual ("http://host/dir/subdir/", merged.ToString (), ".ToString");
604 
605 			merged = new Uri (absolute, "/");
606 			Assert.AreEqual (String.Empty, merged.Query, "/Query");
607 			Assert.AreEqual ("http://host/", merged.ToString (), "/ToString");
608 
609 			merged = new Uri (absolute, "index.html");
610 			Assert.AreEqual (String.Empty, merged.Query, "index.html Query");
611 			Assert.AreEqual ("http://host/dir/subdir/index.html", merged.ToString (), "index.html ToString");
612 
613 			merged = new Uri (absolute, "i");
614 			Assert.AreEqual (String.Empty, merged.Query, "i Query");
615 			Assert.AreEqual ("http://host/dir/subdir/i", merged.ToString (), "i ToString");
616 
617 			merged = new Uri (absolute, String.Empty);
618 			Assert.AreEqual ("?moonlight", merged.Query, "Query");
619 			Assert.AreEqual ("http://host/dir/subdir/weird;name?moonlight", merged.ToString (), "ToString");
620 		}
621 
622 		[Test]
Merge_Fragment_RelativePath()623 		public void Merge_Fragment_RelativePath ()
624 		{
625 			Uri absolute = new Uri ("http://host/dir/subdir/weird;name#mono");
626 			Assert.AreEqual ("#mono", absolute.Fragment, "absolute.Fragment");
627 
628 			Uri merged = new Uri (absolute, "../");
629 			Assert.AreEqual (String.Empty, merged.Fragment, "../Fragment");
630 			Assert.AreEqual ("http://host/dir/", merged.ToString (), "../ToString");
631 
632 			merged = new Uri (absolute, "..");
633 			Assert.AreEqual (String.Empty, merged.Fragment, "..Fragment");
634 			Assert.AreEqual ("http://host/dir/", merged.ToString (), "..ToString");
635 
636 			merged = new Uri (absolute, "./");
637 			Assert.AreEqual (String.Empty, merged.Fragment, "./Fragment");
638 			Assert.AreEqual ("http://host/dir/subdir/", merged.ToString (), "./ToString");
639 
640 			merged = new Uri (absolute, ".");
641 			Assert.AreEqual (String.Empty, merged.Fragment, ".Fragment");
642 			Assert.AreEqual ("http://host/dir/subdir/", merged.ToString (), ".ToString");
643 
644 			merged = new Uri (absolute, "/");
645 			Assert.AreEqual (String.Empty, merged.Fragment, "/Fragment");
646 			Assert.AreEqual ("http://host/", merged.ToString (), "/ToString");
647 
648 			merged = new Uri (absolute, "index.html");
649 			Assert.AreEqual (String.Empty, merged.Fragment, "index.html Fragment");
650 			Assert.AreEqual ("http://host/dir/subdir/index.html", merged.ToString (), "index.html ToString");
651 
652 			merged = new Uri (absolute, "i");
653 			Assert.AreEqual (String.Empty, merged.Fragment, "i Fragment");
654 			Assert.AreEqual ("http://host/dir/subdir/i", merged.ToString (), "i ToString");
655 
656 			merged = new Uri (absolute, String.Empty);
657 			Assert.AreEqual ("#mono", merged.Fragment, "Fragment");
658 			Assert.AreEqual ("http://host/dir/subdir/weird;name#mono", merged.ToString (), "ToString");
659 		}
660 
661 		[Test]
Host_Drive()662 		public void Host_Drive ()
663 		{
664 			Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("c:"), "c:");
665 			Assert.AreEqual (UriHostNameType.Dns, Uri.CheckHostName ("c"), "c");
666 
667 			Uri uri = new Uri ("http://c:/dir/subdir/file");
668 			Assert.AreEqual ("c", uri.Authority, "http.Authority");
669 			Assert.AreEqual ("c", uri.DnsSafeHost, "http.DnsSafeHost");
670 			Assert.AreEqual ("c", uri.Host, "http.Host");
671 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "http.HostNameType");
672 			Assert.AreEqual ("http://c/dir/subdir/file", uri.ToString (), "http.ToString");
673 
674 			uri = new Uri ("https://c:/dir/subdir/file");
675 			Assert.AreEqual ("c", uri.Authority, "https.Authority");
676 			Assert.AreEqual ("c", uri.DnsSafeHost, "https.DnsSafeHost");
677 			Assert.AreEqual ("c", uri.Host, "https.Host");
678 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "https.HostNameType");
679 			Assert.AreEqual ("https://c/dir/subdir/file", uri.ToString (), "https.ToString");
680 
681 			uri = new Uri ("ftp://c:/dir/subdir/file");
682 			Assert.AreEqual ("c", uri.Authority, "ftp.Authority");
683 			Assert.AreEqual ("c", uri.DnsSafeHost, "ftp.DnsSafeHost");
684 			Assert.AreEqual ("c", uri.Host, "ftp.Host");
685 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "ftp.HostNameType");
686 			Assert.AreEqual ("ftp://c/dir/subdir/file", uri.ToString (), "ftp.ToString");
687 
688 			uri = new Uri ("nntp://c:/123456@c");
689 			Assert.AreEqual ("c", uri.Authority, "nntp.Authority");
690 			Assert.AreEqual ("c", uri.DnsSafeHost, "nntp.DnsSafeHost");
691 			Assert.AreEqual ("c", uri.Host, "nntp.Host");
692 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "nntp.HostNameType");
693 			Assert.AreEqual ("nntp://c/123456@c", uri.ToString (), "nntp.ToString");
694 
695 			uri = new Uri ("file://c:/dir/subdir/file");
696 			Assert.AreEqual (String.Empty, uri.Authority, "file.Authority");
697 			Assert.AreEqual (String.Empty, uri.DnsSafeHost, "file.DnsSafeHost");
698 			Assert.AreEqual (String.Empty, uri.Host, "file.Host");
699 			Assert.AreEqual (UriHostNameType.Basic, uri.HostNameType, "file.HostNameType");
700 			Assert.AreEqual ("file:///c:/dir/subdir/file", uri.ToString (), "file.ToString");
701 		}
702 
703 		[Test]
UnknownScheme()704 		public void UnknownScheme ()
705 		{
706 			Uri uri = new Uri ("mono:c:\\dir\\subdir\\file");
707 			Assert.IsFalse (uri.IsWellFormedOriginalString (), "IsWellFormedOriginalString");
708 			Assert.AreEqual (String.Empty, uri.Host, "Host");
709 			Assert.AreEqual ("c:\\dir\\subdir\\file", uri.LocalPath, "LocalPath");
710 			// make the next assert work on both Windows and Mac (wrt Silverlight)
711 			Assert.AreEqual ("mono:c:/dir/subdir/file", uri.ToString ().Replace ("%5C", "/"), "ToString");
712 
713 			uri = new Uri ("mono://host/dir/subdir/file");
714 			Assert.IsTrue (uri.IsWellFormedOriginalString (), "2/IsWellFormedOriginalString");
715 			Assert.AreEqual ("host", uri.Host, "2/Host");
716 			Assert.AreEqual ("/dir/subdir/file", uri.AbsolutePath, "2/AbsolutePath");
717 			Assert.AreEqual ("/dir/subdir/file", uri.LocalPath, "2/LocalPath");
718 
719 			uri = new Uri ("mono:///host/dir/subdir/file");
720 			Assert.IsTrue (uri.IsWellFormedOriginalString (), "3/IsWellFormedOriginalString");
721 			Assert.AreEqual (String.Empty, uri.Host, "3/Host");
722 			Assert.AreEqual ("/host/dir/subdir/file", uri.AbsolutePath, "3/AbsolutePath");
723 			Assert.AreEqual ("/host/dir/subdir/file", uri.LocalPath, "3/LocalPath");
724 
725 			uri = new Uri ("mono:////host/dir/subdir/file");
726 			Assert.IsTrue (uri.IsWellFormedOriginalString (), "4/IsWellFormedOriginalString");
727 			Assert.AreEqual (String.Empty, uri.Host, "4/Host");
728 			Assert.AreEqual ("//host/dir/subdir/file", uri.AbsolutePath, "4/AbsolutePath");
729 			Assert.AreEqual ("//host/dir/subdir/file", uri.LocalPath, "4/LocalPath");
730 
731 			// query and fragment
732 			uri = new Uri ("mono://host/dir/subdir/file?query#fragment");
733 			Assert.AreEqual ("/dir/subdir/file", uri.AbsolutePath, "qf.AbsolutePath");
734 			Assert.AreEqual ("?query", uri.Query, "qf.Query");
735 			Assert.AreEqual ("#fragment", uri.Fragment, "qf.Fragment");
736 
737 			// special characters
738 			uri = new Uri ("mono://host/<>%\"{}|\\^`;/:@&=+$,[]#abc");
739 			if (IriParsing)
740 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/:@&=+$,[]", uri.AbsolutePath, "Special");
741 			else
742 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/:@&=+$,%5B%5D", uri.AbsolutePath, "Special");
743 		}
744 
745 		[Test]
DriveAndForwardSlashes_Segments()746 		public void DriveAndForwardSlashes_Segments ()
747 		{
748 			Uri uri = new Uri ("mono:c:\\dir\\subdir\\file");
749 			string [] segments = uri.Segments;
750 			Assert.AreEqual (4, segments.Length, "segments");
751 			// make the tests work on both Windows and Mac (wrt Silverlight)
752 			Assert.AreEqual ("c:/", segments [0].Replace ("%5C", "/"), "s[0]");
753 			Assert.AreEqual ("dir/", segments [1].Replace ("%5C", "/"), "s[1]");
754 			Assert.AreEqual ("subdir/", segments [2].Replace ("%5C", "/"), "s[2]");
755 			Assert.AreEqual ("file", segments [3], "s[3]");
756 		}
757 
758 		[Test]
NewsScheme()759 		public void NewsScheme ()
760 		{
761 			Uri uri = new Uri ("news:novell.mono.moonlight/uri?query");
762 
763 			Assert.AreEqual ("novell.mono.moonlight/uri%3Fquery", uri.AbsolutePath, "AbsolutePath");
764 			Assert.AreEqual ("news:novell.mono.moonlight/uri%3Fquery", uri.AbsoluteUri, "AbsoluteUri");
765 			Assert.AreEqual (String.Empty, uri.Authority, "Authority");
766 			Assert.AreEqual (String.Empty, uri.DnsSafeHost, "DnsSafeHost");
767 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
768 			Assert.AreEqual (String.Empty, uri.Host, "Host");
769 			Assert.AreEqual (UriHostNameType.Unknown, uri.HostNameType, "HostNameType");
770 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
771 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
772 			Assert.IsFalse (uri.IsFile, "IsFile");
773 			Assert.IsFalse (uri.IsLoopback, "IsLoopback");
774 			Assert.IsFalse (uri.IsUnc, "IsUnc");
775 			Assert.AreEqual ("novell.mono.moonlight/uri?query", uri.LocalPath, "LocalPath");
776 			Assert.AreEqual ("news:novell.mono.moonlight/uri?query", uri.OriginalString, "OriginalString");
777 			Assert.AreEqual ("novell.mono.moonlight/uri%3Fquery", uri.PathAndQuery, "PathAndQuery");
778 			Assert.AreEqual (-1, uri.Port, "Port");
779 			Assert.AreEqual (String.Empty, uri.Query, "Query");
780 			Assert.AreEqual ("news", uri.Scheme, "Scheme");
781 			Assert.AreEqual ("novell.mono.moonlight/", uri.Segments [0], "Segments [0]");
782 			Assert.AreEqual ("uri%3Fquery", uri.Segments [1], "Segments [1]");
783 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
784 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
785 
786 			// special escaped characters - they differs a bit from other URI
787 			uri = new Uri ("news:novell.mono.moonlight/<>%\"{}|\\^`;/?:@&=+$,[]#abc");
788 			Assert.AreEqual ("#abc", uri.Fragment, "Special/Fragment");
789 			if (IriParsing)
790 				Assert.AreEqual ("novell.mono.moonlight/%3C%3E%25%22%7B%7D%7C%5C%5E%60;/%3F:@&=+$,[]", uri.AbsolutePath, "Special");
791 			else
792 				Assert.AreEqual ("novell.mono.moonlight/%3C%3E%25%22%7B%7D%7C%5C%5E%60;/%3F:@&=+$,%5B%5D", uri.AbsolutePath, "Special");
793 		}
794 
795 		[Test]
NntpScheme()796 		public void NntpScheme ()
797 		{
798 			Uri uri = new Uri ("nntp://news.mono-project.com/novell.mono.moonlight/uri?query");
799 
800 			Assert.AreEqual ("/novell.mono.moonlight/uri%3Fquery", uri.AbsolutePath, "AbsolutePath");
801 			Assert.AreEqual ("nntp://news.mono-project.com/novell.mono.moonlight/uri%3Fquery", uri.AbsoluteUri, "AbsoluteUri");
802 			Assert.AreEqual ("news.mono-project.com", uri.Authority, "Authority");
803 			Assert.AreEqual ("news.mono-project.com", uri.DnsSafeHost, "DnsSafeHost");
804 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
805 			Assert.AreEqual ("news.mono-project.com", uri.Host, "Host");
806 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "HostNameType");
807 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
808 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
809 			Assert.IsFalse (uri.IsFile, "IsFile");
810 			Assert.IsFalse (uri.IsLoopback, "IsLoopback");
811 			Assert.IsFalse (uri.IsUnc, "IsUnc");
812 			Assert.AreEqual ("/novell.mono.moonlight/uri?query", uri.LocalPath, "LocalPath");
813 			Assert.AreEqual ("nntp://news.mono-project.com/novell.mono.moonlight/uri?query", uri.OriginalString, "OriginalString");
814 			Assert.AreEqual ("/novell.mono.moonlight/uri%3Fquery", uri.PathAndQuery, "PathAndQuery");
815 			Assert.AreEqual (119, uri.Port, "Port");
816 			Assert.AreEqual (String.Empty, uri.Query, "Query");
817 			Assert.AreEqual ("nntp", uri.Scheme, "Scheme");
818 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
819 			Assert.AreEqual ("novell.mono.moonlight/", uri.Segments [1], "Segments [1]");
820 			Assert.AreEqual ("uri%3Fquery", uri.Segments [2], "Segments [2]");
821 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
822 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
823 
824 			// special escaped characters - they differs a bit from other URI
825 			uri = new Uri ("nntp://news.mono-project.com/novell.mono.moonlight/<>%\"{}|\\^`;/?:@&=+$,[]#abc");
826 			Assert.AreEqual ("#abc", uri.Fragment, "Special/Fragment");
827 			if (IriParsing)
828 				Assert.AreEqual ("/novell.mono.moonlight/%3C%3E%25%22%7B%7D%7C%5C%5E%60;/%3F:@&=+$,[]", uri.AbsolutePath, "Special");
829 			else
830 				Assert.AreEqual ("/novell.mono.moonlight/%3C%3E%25%22%7B%7D%7C%5C%5E%60;/%3F:@&=+$,%5B%5D", uri.AbsolutePath, "Special");
831 		}
832 
833 		[Test]
FtpScheme()834 		public void FtpScheme ()
835 		{
836 			// user, password, custom port and a "query"
837 			Uri uri = new Uri ("ftp://user:password@ftp.mono-project.com:2121/mono.zip?latest-n-greatest");
838 			Assert.AreEqual ("/mono.zip%3Flatest-n-greatest", uri.AbsolutePath, "AbsolutePath");
839 			Assert.AreEqual ("ftp://user:password@ftp.mono-project.com:2121/mono.zip%3Flatest-n-greatest", uri.AbsoluteUri, "AbsoluteUri");
840 			Assert.AreEqual ("ftp.mono-project.com:2121", uri.Authority, "Authority");
841 			Assert.AreEqual ("ftp.mono-project.com", uri.DnsSafeHost, "DnsSafeHost");
842 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
843 			Assert.AreEqual ("ftp.mono-project.com", uri.Host, "Host");
844 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "HostNameType");
845 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
846 			Assert.IsFalse (uri.IsDefaultPort, "IsDefaultPort");
847 			Assert.IsFalse (uri.IsFile, "IsFile");
848 			Assert.IsFalse (uri.IsLoopback, "IsLoopback");
849 			Assert.IsFalse (uri.IsUnc, "IsUnc");
850 			Assert.AreEqual ("/mono.zip?latest-n-greatest", uri.LocalPath, "LocalPath");
851 			Assert.AreEqual ("ftp://user:password@ftp.mono-project.com:2121/mono.zip?latest-n-greatest", uri.OriginalString, "OriginalString");
852 			Assert.AreEqual ("/mono.zip%3Flatest-n-greatest", uri.PathAndQuery, "PathAndQuery");
853 			Assert.AreEqual (2121, uri.Port, "Port");
854 			Assert.AreEqual (String.Empty, uri.Query, "Query");
855 			Assert.AreEqual ("ftp", uri.Scheme, "Scheme");
856 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
857 			Assert.AreEqual ("mono.zip%3Flatest-n-greatest", uri.Segments [1], "Segments [1]");
858 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
859 			Assert.AreEqual ("user:password", uri.UserInfo, "UserInfo");
860 
861 			// special characters and fragment
862 			uri = new Uri ("ftp://ftp.mono-project.com/<>%\"{}|\\^`;/?:@&=+$,[]#abc");
863 			Assert.AreEqual ("#abc", uri.Fragment, "Special/Fragment");
864 			if (IriParsing)
865 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/%3F:@&=+$,[]", uri.AbsolutePath, "Special");
866 			else
867 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/%3F:@&=+$,%5B%5D", uri.AbsolutePath, "Special");
868 		}
869 
870 		[Test]
FileScheme()871 		public void FileScheme ()
872 		{
873 			Uri uri = new Uri ("file://host/dir/subdir/file?this-is-not-a-query#but-this-is-a-fragment");
874 
875 			if (IriParsing)	{
876 				Assert.AreEqual ("/dir/subdir/file", uri.AbsolutePath, "AbsolutePath");
877 				Assert.AreEqual ("file://host/dir/subdir/file?this-is-not-a-query#but-this-is-a-fragment", uri.AbsoluteUri, "AbsoluteUri");
878 				Assert.AreEqual ("\\\\host\\dir\\subdir\\file", uri.LocalPath, "LocalPath");
879 				Assert.AreEqual ("/dir/subdir/file?this-is-not-a-query", uri.PathAndQuery, "PathAndQuery");
880 				Assert.AreEqual ("?this-is-not-a-query", uri.Query, "Query");
881 				Assert.AreEqual ("file", uri.Segments [3], "Segments [3]");
882 			} else {
883 				Assert.AreEqual ("/dir/subdir/file%3Fthis-is-not-a-query", uri.AbsolutePath, "AbsolutePath");
884 				Assert.AreEqual ("file://host/dir/subdir/file%3Fthis-is-not-a-query#but-this-is-a-fragment", uri.AbsoluteUri, "AbsoluteUri");
885 				Assert.AreEqual (isWin32 ? "\\\\host\\dir\\subdir\\file?this-is-not-a-query" : "/dir/subdir/file?this-is-not-a-query", uri.LocalPath, "LocalPath");
886 				Assert.AreEqual ("/dir/subdir/file%3Fthis-is-not-a-query", uri.PathAndQuery, "PathAndQuery");
887 				Assert.AreEqual (String.Empty, uri.Query, "Query");
888 				Assert.AreEqual ("file%3Fthis-is-not-a-query", uri.Segments [3], "Segments [3]");
889 			}
890 
891 			Assert.AreEqual ("host", uri.Authority, "Authority");
892 			Assert.AreEqual ("host", uri.DnsSafeHost, "DnsSafeHost");
893 			Assert.AreEqual ("#but-this-is-a-fragment", uri.Fragment, "Fragment");
894 			Assert.AreEqual ("host", uri.Host, "Host");
895 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "HostNameType");
896 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
897 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
898 			Assert.IsTrue (uri.IsFile, "IsFile");
899 			Assert.IsFalse (uri.IsLoopback, "IsLoopback");
900 			Assert.AreEqual (isWin32, uri.IsUnc, "IsUnc");
901 			Assert.AreEqual ("file://host/dir/subdir/file?this-is-not-a-query#but-this-is-a-fragment", uri.OriginalString, "OriginalString");
902 			Assert.AreEqual (-1, uri.Port, "Port");
903 			Assert.AreEqual ("file", uri.Scheme, "Scheme");
904 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
905 			Assert.AreEqual ("dir/", uri.Segments [1], "Segments [1]");
906 			Assert.AreEqual ("subdir/", uri.Segments [2], "Segments [2]");
907 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
908 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
909 
910 			// special characters
911 			uri = new Uri ("file://host/<>%\"{}|\\^`;/:@&=+$,[]?#abc");
912 			if (IriParsing)
913 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/:@&=+$,[]", uri.AbsolutePath, "Special");
914 			else
915 				Assert.AreEqual ("/%3C%3E%25%22%7B%7D%7C/%5E%60;/:@&=+$,%5B%5D%3F", uri.AbsolutePath, "Special");
916 		}
917 
918 		[Test]
LocalFile()919 		public void LocalFile ()
920 		{
921 			Uri uri = new Uri ("file:///c:/subdir/file");
922 
923 			Assert.AreEqual ("c:/subdir/file", uri.AbsolutePath, "AbsolutePath");
924 			Assert.AreEqual ("file:///c:/subdir/file", uri.AbsoluteUri, "AbsoluteUri");
925 			Assert.AreEqual ("c:\\subdir\\file", uri.LocalPath, "LocalPath");
926 			Assert.AreEqual ("c:/subdir/file", uri.PathAndQuery, "PathAndQuery");
927 			Assert.AreEqual (String.Empty, uri.Query, "Query");
928 			Assert.AreEqual ("file", uri.Segments [3], "Segments [3]");
929 
930 			Assert.AreEqual (String.Empty, uri.Authority, "Authority");
931 			Assert.AreEqual (String.Empty, uri.DnsSafeHost, "DnsSafeHost");
932 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
933 			Assert.AreEqual (String.Empty, uri.Host, "Host");
934 			Assert.AreEqual (UriHostNameType.Basic, uri.HostNameType, "HostNameType");
935 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
936 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
937 			Assert.IsTrue (uri.IsFile, "IsFile");
938 			Assert.IsTrue (uri.IsLoopback, "IsLoopback");
939 			Assert.IsFalse (uri.IsUnc, "IsUnc");
940 			Assert.AreEqual ("file:///c:/subdir/file", uri.OriginalString, "OriginalString");
941 			Assert.AreEqual (-1, uri.Port, "Port");
942 			Assert.AreEqual ("file", uri.Scheme, "Scheme");
943 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
944 			Assert.AreEqual ("c:/", uri.Segments [1], "Segments [1]");
945 			Assert.AreEqual ("subdir/", uri.Segments [2], "Segments [2]");
946 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
947 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
948 		}
949 
950 		[Test]
LocalhostWinFile()951 		public void LocalhostWinFile ()
952 		{
953 			Uri uri = new Uri ("file://localhost/c:/subdir/file");
954 
955 			Assert.AreEqual ("/c:/subdir/file", uri.AbsolutePath, "AbsolutePath");
956 			Assert.AreEqual ("file://localhost/c:/subdir/file", uri.AbsoluteUri, "AbsoluteUri");
957 			Assert.AreEqual (isWin32 ? "\\\\localhost\\c:\\subdir\\file" : "/c:/subdir/file", uri.LocalPath, "LocalPath");
958 			Assert.AreEqual ("/c:/subdir/file", uri.PathAndQuery, "PathAndQuery");
959 			Assert.AreEqual (String.Empty, uri.Query, "Query");
960 			Assert.AreEqual ("file", uri.Segments [3], "Segments [3]");
961 
962 			Assert.AreEqual ("localhost", uri.Authority, "Authority");
963 			Assert.AreEqual ("localhost", uri.DnsSafeHost, "DnsSafeHost");
964 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
965 			Assert.AreEqual ("localhost", uri.Host, "Host");
966 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "HostNameType");
967 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
968 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
969 			Assert.IsTrue (uri.IsFile, "IsFile");
970 			Assert.IsTrue (uri.IsLoopback, "IsLoopback");
971 			Assert.AreEqual (isWin32, uri.IsUnc, "IsUnc");
972 			Assert.AreEqual ("file://localhost/c:/subdir/file", uri.OriginalString, "OriginalString");
973 			Assert.AreEqual (-1, uri.Port, "Port");
974 			Assert.AreEqual ("file", uri.Scheme, "Scheme");
975 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
976 			Assert.AreEqual ("c:/", uri.Segments [1], "Segments [1]");
977 			Assert.AreEqual ("subdir/", uri.Segments [2], "Segments [2]");
978 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
979 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
980 		}
981 
982 		[Test]
LocalhostFile()983 		public void LocalhostFile ()
984 		{
985 			Uri uri = new Uri ("file://localhost/dir/subdir/file");
986 
987 			Assert.AreEqual ("/dir/subdir/file", uri.AbsolutePath, "AbsolutePath");
988 			Assert.AreEqual ("file://localhost/dir/subdir/file", uri.AbsoluteUri, "AbsoluteUri");
989 			Assert.AreEqual (isWin32 ? "\\\\localhost\\dir\\subdir\\file" : "/dir/subdir/file", uri.LocalPath, "LocalPath");
990 			Assert.AreEqual ("/dir/subdir/file", uri.PathAndQuery, "PathAndQuery");
991 			Assert.AreEqual (String.Empty, uri.Query, "Query");
992 			Assert.AreEqual ("file", uri.Segments [3], "Segments [3]");
993 
994 			Assert.AreEqual ("localhost", uri.Authority, "Authority");
995 			Assert.AreEqual ("localhost", uri.DnsSafeHost, "DnsSafeHost");
996 			Assert.AreEqual (String.Empty, uri.Fragment, "Fragment");
997 			Assert.AreEqual ("localhost", uri.Host, "Host");
998 			Assert.AreEqual (UriHostNameType.Dns, uri.HostNameType, "HostNameType");
999 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
1000 			Assert.IsTrue (uri.IsDefaultPort, "IsDefaultPort");
1001 			Assert.IsTrue (uri.IsFile, "IsFile");
1002 			Assert.IsTrue (uri.IsLoopback, "IsLoopback");
1003 			Assert.AreEqual (isWin32, uri.IsUnc, "IsUnc");
1004 			Assert.AreEqual ("file://localhost/dir/subdir/file", uri.OriginalString, "OriginalString");
1005 			Assert.AreEqual (-1, uri.Port, "Port");
1006 			Assert.AreEqual ("file", uri.Scheme, "Scheme");
1007 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
1008 			Assert.AreEqual ("dir/", uri.Segments [1], "Segments [1]");
1009 			Assert.AreEqual ("subdir/", uri.Segments [2], "Segments [2]");
1010 			Assert.IsFalse (uri.UserEscaped, "UserEscaped");
1011 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
1012 		}
1013 
1014 		[Test]
PathReduction_2e()1015 		public void PathReduction_2e ()
1016 		{
1017 			Uri uri = new Uri ("http://host/dir/%2e%2E/file");
1018 			Assert.AreEqual ("/file", uri.AbsolutePath, "AbsolutePath");
1019 			Assert.AreEqual ("http://host/file", uri.AbsoluteUri, "AbsoluteUri");
1020 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
1021 			Assert.AreEqual ("file", uri.Segments [1], "Segments [1]");
1022 		}
1023 
1024 		[Test]
ColonButNoPort()1025 		public void ColonButNoPort ()
1026 		{
1027 			Uri uri = new Uri ("http://host:");
1028 			Assert.AreEqual ("http", uri.Scheme, "1.Scheme");
1029 			Assert.AreEqual ("host", uri.Host, "1.Host");
1030 			Assert.AreEqual (80, uri.Port, "1.Port");
1031 			Assert.IsTrue (uri.IsDefaultPort, "1.IsDefaultPort");
1032 
1033 			uri = new Uri ("ftp://host:/dir/file");
1034 			Assert.AreEqual ("ftp", uri.Scheme, "2.Scheme");
1035 			Assert.AreEqual ("host", uri.Host, "2.Host");
1036 			Assert.AreEqual (21, uri.Port, "2.Port");
1037 			Assert.IsTrue (uri.IsDefaultPort, "2.IsDefaultPort");
1038 		}
1039 
1040 		[Test]
IPv6SafeDnsName()1041 		public void IPv6SafeDnsName ()
1042 		{
1043 			Uri uri = new Uri ("http://[1:2:3:4:5:6:7:8]");
1044 			Assert.AreEqual (UriHostNameType.IPv6, uri.HostNameType, "1.HostNameType");
1045 			if (IriParsing) {
1046 				Assert.AreEqual ("[1:2:3:4:5:6:7:8]", uri.Authority, "1.Authority");
1047 				Assert.AreEqual ("1:2:3:4:5:6:7:8", uri.DnsSafeHost, "1.DnsSafeHost");
1048 				Assert.AreEqual ("[1:2:3:4:5:6:7:8]", uri.Host, "1.Host");
1049 			} else {
1050 				Assert.AreEqual ("[0001:0002:0003:0004:0005:0006:0007:0008]", uri.Authority, "1.Authority");
1051 				Assert.AreEqual ("0001:0002:0003:0004:0005:0006:0007:0008", uri.DnsSafeHost, "1.DnsSafeHost");
1052 				Assert.AreEqual ("[0001:0002:0003:0004:0005:0006:0007:0008]", uri.Host, "1.Host");
1053 			}
1054 
1055 			uri = new Uri ("http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm");
1056 			Assert.AreEqual (UriHostNameType.IPv6, uri.HostNameType, "1.HostNameType");
1057 			if (IriParsing)	{
1058 				Assert.AreEqual ("[fe80::200:39ff:fe36:1a2d]", uri.Authority, "2.Authority");
1059 				Assert.AreEqual ("fe80::200:39ff:fe36:1a2d%4", uri.DnsSafeHost, "2.DnsSafeHost");
1060 				Assert.AreEqual ("[fe80::200:39ff:fe36:1a2d]", uri.Host, "2.Host");
1061 			} else {
1062 				Assert.AreEqual ("[FE80:0000:0000:0000:0200:39FF:FE36:1A2D]", uri.Authority, "2.Authority");
1063 				Assert.AreEqual ("FE80:0000:0000:0000:0200:39FF:FE36:1A2D%4", uri.DnsSafeHost, "2.DnsSafeHost");
1064 				Assert.AreEqual ("[FE80:0000:0000:0000:0200:39FF:FE36:1A2D]", uri.Host, "2.Host");
1065 			}
1066 		}
1067 
1068 		[Test]
RelativeEscapes()1069 		public void RelativeEscapes ()
1070 		{
1071 			Uri uri = new Uri ("%2e%2e/dir/%2e%2e/subdir/file?query#fragment", UriKind.Relative);
1072 			if (IriParsing)
1073 				Assert.AreEqual ("../dir/../subdir/file?query#fragment", uri.ToString (), "1.ToString");
1074 			else
1075 				Assert.AreEqual ("%2e%2e/dir/%2e%2e/subdir/file?query#fragment", uri.ToString (), "1.ToString");
1076 		}
1077 
1078 		[Test]
BadUri()1079 		public void BadUri ()
1080 		{
1081 			Assert2.Throws<UriFormatException> (delegate {
1082 				new Uri ("a:b", UriKind.Absolute);
1083 			}, "a:b - Absolute");
1084 
1085 			Uri abs = new Uri ("http://novell.com", UriKind.Absolute);
1086 			Assert2.Throws<UriFormatException> (delegate {
1087 				new Uri (abs, "a:b");
1088 			}, "a:b - Relative");
1089 		}
1090 
1091 		[Test]
MergeWithConfusingRelativeUri()1092 		public void MergeWithConfusingRelativeUri ()
1093 		{
1094 			Uri abs = new Uri ("http://novell.com", UriKind.Absolute);
1095 
1096 			// note: invalid scheme
1097 			string srel = "http@ftp://mono-project.com/dir/file";
1098 			Uri uri = new Uri (abs, srel);
1099 			Assert.AreEqual ("http://novell.com/http@ftp://mono-project.com/dir/file", uri.ToString (), "1.ToString");
1100 
1101 			Uri rel = new Uri (srel, UriKind.Relative);
1102 			Assert.AreEqual ("http@ftp://mono-project.com/dir/file", rel.ToString (), "2.ToString");
1103 
1104 			uri = new Uri (abs, rel);
1105 			Assert.AreEqual ("http://novell.com/http@ftp://mono-project.com/dir/file", uri.ToString (), "3.ToString");
1106 		}
1107 
1108 		[Test]
EmptyUserInfo()1109 		public void EmptyUserInfo ()
1110 		{
1111 			Uri uri = new Uri ("http://@www.mono-project.com");
1112 			Assert.AreEqual ("http://@www.mono-project.com/", uri.AbsoluteUri, "AbsoluteUri");
1113 			Assert.AreEqual ("http://@www.mono-project.com", uri.GetLeftPart (UriPartial.Authority), "UriPartial.Authority");
1114 			Assert.AreEqual ("http://@www.mono-project.com/", uri.GetLeftPart (UriPartial.Path), "UriPartial.Path");
1115 			Assert.AreEqual (String.Empty, uri.UserInfo, "UserInfo");
1116 		}
1117 
1118 		[Test]
Fragment_SpecialCharacters()1119 		public void Fragment_SpecialCharacters ()
1120 		{
1121 			Uri uri = new Uri ("http://host/dir/file#fragment <>%\"{}|\\^`;/?:@&=+$,[]#second");
1122 			Assert.AreEqual ("http://host/dir/file#fragment <>%25\"{}|\\^`;/?:@&=+$,[]%23second", uri.ToString (), "ToString");
1123 			if (IriParsing)
1124 				Assert.AreEqual ("#fragment%20%3C%3E%25%22%7B%7D%7C%5C%5E%60;/?:@&=+$,[]#second", uri.Fragment, "Fragment");
1125 			else
1126 				Assert.AreEqual ("#fragment%20%3C%3E%25%22%7B%7D%7C%5C%5E%60;/?:@&=+$,%5B%5D%23second", uri.Fragment, "Fragment");
1127 		}
1128 
1129 		[Test]
Query_SpecialCharacters()1130 		public void Query_SpecialCharacters ()
1131 		{
1132 			Uri uri = new Uri ("http://host/dir/file?query <>%\"{}|\\^`;/?:@&=+$,[]");
1133 			Assert.AreEqual ("http://host/dir/file?query <>%25\"{}|\\^`;/?:@&=+$,[]", uri.ToString (), "ToString");
1134 			if (IriParsing)
1135 				Assert.AreEqual ("?query%20%3C%3E%25%22%7B%7D%7C%5C%5E%60;/?:@&=+$,[]", uri.Query, "Query");
1136 			else
1137 				Assert.AreEqual ("?query%20%3C%3E%25%22%7B%7D%7C%5C%5E%60;/?:@&=+$,%5B%5D", uri.Query, "Query");
1138 		}
1139 
1140 		[Test]
OriginalPathEscaped()1141 		public void OriginalPathEscaped ()
1142 		{
1143 			Uri uri = new Uri ("http://www.mono-project.com/%41/%42/%43", UriKind.Absolute);
1144 			Assert.AreEqual ("/A/B/C", uri.LocalPath, "LocalPath");
1145 			if (IriParsing)	{
1146 				Assert.AreEqual ("http://www.mono-project.com/A/B/C", uri.AbsoluteUri, "AbsoluteUri");
1147 				Assert.AreEqual ("/A/B/C", uri.AbsolutePath, "AbsolutePath");
1148 				Assert.AreEqual ("http://www.mono-project.com/A/B/C", uri.GetLeftPart (UriPartial.Path), "GetLeftPart(Path)");
1149 			} else {
1150 				Assert.AreEqual ("http://www.mono-project.com/%41/%42/%43", uri.AbsoluteUri, "AbsoluteUri");
1151 				Assert.AreEqual ("/%41/%42/%43", uri.AbsolutePath, "AbsolutePath");
1152 				Assert.AreEqual ("http://www.mono-project.com/%41/%42/%43", uri.GetLeftPart (UriPartial.Path), "GetLeftPart(Path)");
1153 			}
1154 		}
1155 
1156 		[Test]
CheckHostName()1157 		public void CheckHostName ()
1158 		{
1159 			Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("host;machine"), "CheckHostName ;");
1160 			Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("www..mono-project.com"), "CheckHostName ..");
1161 			Assert.AreEqual (UriHostNameType.Unknown, Uri.CheckHostName ("www.mono-project.com\\"), "CheckHostName \\");
1162 		}
1163 
1164 		[Test]
Ports()1165 		public void Ports ()
1166 		{
1167 			Assert2.Throws<UriFormatException> (delegate {
1168 				new Uri ("http://host:-1/");
1169 			}, "negative");
1170 
1171 			Uri uri = new Uri ("http://host:0/");
1172 			Assert.AreEqual (0, uri.Port, "Port = 0");
1173 
1174 			Assert2.Throws<UriFormatException> (delegate {
1175 				new Uri ("http://host:+1/");
1176 			}, "positive");
1177 
1178 			uri = new Uri ("http://host:" + UInt16.MaxValue.ToString ());
1179 			Assert.AreEqual (65535, uri.Port, "Port = 65535");
1180 
1181 			Assert2.Throws<UriFormatException> (delegate {
1182 				new Uri ("http://host:" + (UInt16.MaxValue + 1).ToString ());
1183 			}, "too big");
1184 
1185 			Assert2.Throws<UriFormatException> (delegate {
1186 				new Uri ("http://host:3.14");
1187 			}, "float");
1188 		}
1189 
1190 		[Test]
NonAsciiHost()1191 		public void NonAsciiHost ()
1192 		{
1193 			Uri uri = new Uri ("ftp://β:2121/", UriKind.Absolute);
1194 			Assert.AreEqual ("/", uri.AbsolutePath, "AbsolutePath");
1195 			Assert.AreEqual ("ftp://β:2121/", uri.AbsoluteUri, "AbsoluteUri");
1196 			Assert.AreEqual ("β:2121", uri.Authority, "Authority");
1197 			Assert.AreEqual ("β", uri.DnsSafeHost, "DnsSafeHost");
1198 			Assert.AreEqual ("β", uri.Host, "Host");
1199 			Assert.IsTrue (uri.IsAbsoluteUri, "IsAbsoluteUri");
1200 			Assert.IsFalse (uri.IsDefaultPort, "IsDefaultPort");
1201 			Assert.AreEqual ("/", uri.LocalPath, "LocalPath");
1202 			Assert.AreEqual ("ftp://β:2121/", uri.OriginalString, "OriginalString");
1203 			Assert.AreEqual ("/", uri.PathAndQuery, "PathAndQuery");
1204 			Assert.AreEqual (2121, uri.Port, "Port");
1205 			Assert.AreEqual ("ftp", uri.Scheme, "Scheme");
1206 			Assert.AreEqual ("/", uri.Segments [0], "Segments [0]");
1207 		}
1208 	}
1209 }
1210