2 // System.Web.VirtualPathUtilityTest.cs - Unit tests for System.Web.VirtualPathUtility
5 // Chris Toshok <toshok@novell.com>
6 // Gonzalo Paniagua Javier (gonzalo@novell.com)
8 // Copyright (C) 2005,2006 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using VPU = System.Web.VirtualPathUtility;
35 using MonoTests.SystemWeb.Framework;
36 using MonoTests.stand_alone.WebHarness;
39 using NUnit.Framework;
41 namespace MonoTests.System.Web {
44 public class VirtualPathUtilityTest {
46 const string NunitWebAppName = "NunitWeb";
49 public void AppendTrailingSlash ()
51 Assert.AreEqual ("/hithere/", VPU.AppendTrailingSlash ("/hithere"), "A1");
52 Assert.AreEqual ("/hithere/", VPU.AppendTrailingSlash ("/hithere/"), "A2");
53 Assert.AreEqual ("/", VPU.AppendTrailingSlash ("/"), "A3");
54 Assert.AreEqual ("", VPU.AppendTrailingSlash (""), "A4");
55 Assert.AreEqual (null, VPU.AppendTrailingSlash (null), "A5");
59 public void Combine ()
61 Assert.AreEqual ("/there", VPU.Combine ("/hi", "there"), "A1");
62 Assert.AreEqual ("/hi/you", VPU.Combine ("/hi/there", "you"), "A2");
63 Assert.AreEqual ("/hi/there/you", VPU.Combine ("/hi/there/", "you"), "A3");
65 Assert.AreEqual ("/there/", VPU.Combine ("/hi", "there/"), "A1");
66 Assert.AreEqual ("/hi/you/", VPU.Combine ("/hi/there", "you/"), "A2");
67 Assert.AreEqual ("/hi/there/you/", VPU.Combine ("/hi/there/", "you/"), "A3");
69 Assert.AreEqual ("/there", VPU.Combine ("/hi", "/there"), "A1");
70 Assert.AreEqual ("/you", VPU.Combine ("/hi/there", "/you"), "A2");
71 Assert.AreEqual ("/you", VPU.Combine ("/hi/there/", "/you"), "A3");
75 public void Combine3 ()
77 Assert.AreEqual ("/", VPU.Combine ("/hi/", ".."), "A1");
78 Assert.AreEqual ("/", VPU.Combine ("/hi/there", ".."), "A2");
79 Assert.AreEqual ("/hi", VPU.Combine ("/hi/there/", ".."), "A3");
81 Assert.AreEqual ("/", VPU.Combine ("/hi/", "../"), "A1");
82 Assert.AreEqual ("/", VPU.Combine ("/hi/there", "../"), "A2");
83 Assert.AreEqual ("/hi/", VPU.Combine ("/hi/there/", "../"), "A3");
85 Assert.AreEqual ("/", VPU.Combine ("/", "."), "A1");
86 Assert.AreEqual ("/", VPU.Combine ("/hi", "."), "A2");
87 Assert.AreEqual ("/hi", VPU.Combine ("/hi/", "."), "A3");
89 Assert.AreEqual ("/", VPU.Combine ("/", "./"), "A1");
90 Assert.AreEqual ("/", VPU.Combine ("/hi", "./"), "A2");
91 Assert.AreEqual ("/hi/", VPU.Combine ("/hi/", "./"), "A3");
93 Assert.AreEqual ("/", VPU.Combine ("/hi", "there/../"), "A1");
94 Assert.AreEqual ("/hi", VPU.Combine ("/hi/there", "you/.."), "A2");
96 Assert.AreEqual ("/there/", VPU.Combine ("/hi", "there/./"), "A1");
97 Assert.AreEqual ("/hi/you", VPU.Combine ("/hi/there", "you/."), "A2");
99 Assert.AreEqual ("/blah2/", VPU.Combine ("/ROOT", "/blah1/../blah2/"));
100 Assert.AreEqual ("/blah1/blah2/", VPU.Combine ("/ROOT", "/blah1/./blah2/"));
102 Assert.AreEqual ("/blah1", VPU.Combine ("/ROOT", "/blah1/blah2/.."));
103 Assert.AreEqual ("/", VPU.Combine ("/ROOT", "/blah1/.."));
104 Assert.AreEqual ("/blah1/", VPU.Combine ("/ROOT", "/blah1/blah2/../"));
105 Assert.AreEqual ("/", VPU.Combine ("/ROOT", "/blah1/../"));
107 Assert.AreEqual ("/blah1", VPU.Combine ("/ROOT", "/blah1/."));
108 Assert.AreEqual ("/", VPU.Combine ("/ROOT", "/."));
109 Assert.AreEqual ("/blah1/", VPU.Combine ("/ROOT", "/blah1/./"));
110 Assert.AreEqual ("/", VPU.Combine ("/ROOT", "/./"));
112 Assert.AreEqual ("/", VPU.Combine ("///hi/", ".."), "A1");
113 Assert.AreEqual ("/", VPU.Combine ("/hi/there/me/..", ".."), "A1");
114 Assert.AreEqual ("/", VPU.Combine ("/hi/there/../", ".."), "A1");
115 Assert.AreEqual ("/hi/me", VPU.Combine ("/hi/there/../", "me"), "A1");
116 Assert.AreEqual ("/", VPU.Combine ("/hi/there/../you", ".."), "A1");
117 Assert.AreEqual ("/hi/me", VPU.Combine ("/hi/there/../you", "me"), "A1");
118 Assert.AreEqual ("/hi/you/me", VPU.Combine ("/hi/there/../you/", "me"), "A1");
122 public void Combine4 ()
124 new WebTest (PageInvoker.CreateOnLoad (Combine4_Load)).Run ();
127 public static void Combine4_Load (Page p)
129 Assert.AreEqual ("~", VPU.Combine ("/ROOT", "~"), "/ROOT, ~");
130 Assert.AreEqual ("~/blah1", VPU.Combine ("/ROOT", "~/blah1"), "/ROOT, ~/blah1");
131 Assert.AreEqual ("~/blah1/", VPU.Combine ("/ROOT", "~/blah1/"));
133 Assert.AreEqual ("~/blah2/", VPU.Combine ("/ROOT", "~/blah1/../blah2/"));
134 Assert.AreEqual ("~/blah1/blah2/", VPU.Combine ("/ROOT", "~/blah1/./blah2/"));
136 Assert.AreEqual ("~/blah1", VPU.Combine ("/ROOT", "~/blah1/blah2/.."));
137 Assert.AreEqual ("~", VPU.Combine ("/ROOT", "~/blah1/.."));
138 Assert.AreEqual ("~/blah1/", VPU.Combine ("/ROOT", "~/blah1/blah2/../"));
139 Assert.AreEqual ("~/", VPU.Combine ("/ROOT", "~/blah1/../"));
141 Assert.AreEqual ("~/blah1", VPU.Combine ("/ROOT", "~/blah1/."));
142 Assert.AreEqual ("~", VPU.Combine ("/ROOT", "~/."));
143 Assert.AreEqual ("~/blah1/", VPU.Combine ("/ROOT", "~/blah1/./"));
144 Assert.AreEqual ("~/", VPU.Combine ("/ROOT", "~/./"));
146 Assert.AreEqual ("/", VPU.Combine ("~/ROOT", "~/.."), "~/ROOT, ~/..");
147 Assert.AreEqual ("/", VPU.Combine ("~/ROOT", ".."));
148 Assert.AreEqual ("~", VPU.Combine ("~/ROOT/", ".."));
149 Assert.AreEqual ("~/", VPU.Combine ("~/ROOT/", "../"));
150 Assert.AreEqual ("~/folder", VPU.Combine ("~/ROOT", "folder"));
151 Assert.AreEqual ("~/ROOT/folder", VPU.Combine ("~/ROOT/", "folder"));
152 Assert.AreEqual ("~/ROOT/folder/", VPU.Combine ("~/ROOT/", "folder/"));
154 Assert.AreEqual ("/", VPU.Combine ("~", ".."));
155 Assert.AreEqual ("~/me", VPU.Combine ("~", "me"));
156 Assert.AreEqual ("/me", VPU.Combine ("~", "../me"));
157 Assert.AreEqual ("~/me", VPU.Combine ("~", "./me"));
159 Assert.AreEqual ("/me", VPU.Combine ("~/..", "me"));
161 Assert.AreEqual ("/", VPU.Combine ("~/hi/there/..", ".."), "A1");
162 Assert.AreEqual ("~", VPU.Combine ("~/hi/there/../", ".."), "A1");
163 Assert.AreEqual ("/", VPU.Combine ("~/hi/there/../", "../.."), "A1");
164 Assert.AreEqual ("~/hi/me", VPU.Combine ("~/hi/there/../", "me"), "A1");
165 Assert.AreEqual ("~", VPU.Combine ("~/hi/there/../you", ".."), "A1");
166 Assert.AreEqual ("~/hi/me", VPU.Combine ("~/hi/there/../you", "me"), "A1");
167 Assert.AreEqual ("~/hi/you/me", VPU.Combine ("~/hi/there/../you/", "me"), "A1");
169 Assert.AreEqual (HttpRuntime.AppDomainAppVirtualPath, VPU.Combine ("/ROOT", HttpRuntime.AppDomainAppVirtualPath));
170 Assert.AreEqual (HttpRuntime.AppDomainAppVirtualPath, VPU.Combine ("~/ROOT", HttpRuntime.AppDomainAppVirtualPath));
174 [ExpectedException (typeof (ArgumentException))]
175 // The relative virtual path 'hi/there' is not allowed here.
176 public void Combine_ArgException1 ()
178 Assert.AreEqual ("hi/there/you", VPU.Combine ("hi/there", "you"), "A1");
182 [ExpectedException (typeof (ArgumentException))]
183 // The relative virtual path 'hi/there' is not allowed here.
184 public void Combine_ArgException2 ()
186 Assert.AreEqual ("hi/there", VPU.Combine ("hi/there", null), "A1");
190 [ExpectedException (typeof (ArgumentNullException))]
191 public void Combine_ArgException2_1 ()
193 Assert.AreEqual ("hi/there", VPU.Combine ("/hi/there", null), "A1");
197 [ExpectedException (typeof (ArgumentException))]
198 // The relative virtual path 'hi/there' is not allowed here.
199 public void Combine_ArgException2_2 ()
201 Assert.AreEqual ("hi/there", VPU.Combine ("hi/there", "/dir"), "A1");
205 [ExpectedException (typeof (HttpException))]
206 public void Combine_ArgException2_3 ()
208 Assert.AreEqual ("hi/there", VPU.Combine ("/../hi", null), "A1");
212 [ExpectedException (typeof (ArgumentNullException))]
213 public void Combine_ArgException3 ()
215 Assert.AreEqual ("hi/there", VPU.Combine (null, "there"), "A1");
219 [ExpectedException (typeof (ArgumentNullException))]
221 at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
222 at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
223 at MonoTests.System.Web.VirtualPathUtilityTest.Combine()
225 public void Combine_ArgException4 ()
227 Assert.AreEqual ("/you", VPU.Combine ("", "you"), "A1");
231 [ExpectedException (typeof (ArgumentNullException))]
233 at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
234 at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
235 at MonoTests.System.Web.VirtualPathUtilityTest.Combine()
237 public void Combine_ArgException5 ()
239 Assert.AreEqual ("/hi", VPU.Combine ("/hi", ""), "A1");
243 [ExpectedException (typeof (HttpException))]
244 public void Combine_ArgException6 ()
246 VPU.Combine ("/ROOT", "..");
250 [ExpectedException (typeof (HttpException))]
251 public void Combine_ArgException7 ()
253 VPU.Combine ("/ROOT", "/..");
257 [ExpectedException (typeof (HttpException))]
258 public void Combine_ArgException8 () {
259 VPU.Combine ("/ROOT", "./..");
263 public void GetExtension ()
265 Assert.AreEqual (".aspx", VPU.GetExtension ("/hi/index.aspx"), "A1");
266 Assert.AreEqual ("", VPU.GetExtension ("/hi/index.aspx/"), "A1");
267 Assert.AreEqual (".aspx", VPU.GetExtension ("index.aspx"), "A2");
268 Assert.AreEqual ("", VPU.GetExtension ("/hi/index"), "A3");
270 Assert.AreEqual (".aspx", VPU.GetExtension ("/hi/./index.aspx"), "A1");
271 Assert.AreEqual ("", VPU.GetExtension ("hi/index"), "A2");
273 Assert.AreEqual ("", VPU.GetExtension ("/hi/index.aspx/file"), "A1");
274 Assert.AreEqual ("", VPU.GetExtension ("/hi/index.aspx\\file"), "A1");
275 Assert.AreEqual ("", VPU.GetExtension ("/hi/index.aspx/../file"), "A1");
276 Assert.AreEqual (".htm", VPU.GetExtension ("/hi/index.aspx/../file.htm"), "A1");
278 Assert.AreEqual ("", VPU.GetExtension (".."), "A2");
279 Assert.AreEqual ("", VPU.GetExtension ("../.."), "A2");
280 Assert.AreEqual (".aspx", VPU.GetExtension ("../../file.aspx"), "A2");
284 public void GetFileName ()
286 Assert.AreEqual ("index.aspx", VPU.GetFileName ("/hi/index.aspx"), "A1");
287 Assert.AreEqual ("index.aspx", VPU.GetFileName ("/hi/index.aspx/"), "A1");
288 Assert.AreEqual ("hi", VPU.GetFileName ("/hi/"), "A2");
292 public void IsAbsolute ()
294 Assert.IsTrue (VPU.IsAbsolute ("/"), "A1");
295 Assert.IsTrue (VPU.IsAbsolute ("/hi/there"), "A2");
296 Assert.IsFalse (VPU.IsAbsolute ("hi/there"), "A3");
297 Assert.IsFalse (VPU.IsAbsolute ("./hi"), "A4");
299 Assert.IsTrue (VPU.IsAbsolute ("\\"), "A1");
300 Assert.IsTrue (VPU.IsAbsolute ("\\hi\\there"), "A2");
301 Assert.IsFalse (VPU.IsAbsolute ("hi\\there"), "A3");
302 Assert.IsFalse (VPU.IsAbsolute (".\\hi"), "A4");
306 [ExpectedException (typeof (ArgumentNullException))]
307 public void IsAbsolute_ArgException1 ()
309 Assert.IsFalse (VPU.IsAbsolute (""), "A1");
313 [ExpectedException (typeof (ArgumentNullException))]
314 public void IsAbsolute_ArgException2 ()
316 Assert.IsFalse (VPU.IsAbsolute (null), "A1");
320 public void IsAppRelative ()
322 Assert.IsTrue (VPU.IsAppRelative ("~"), "A0");
323 Assert.IsTrue (VPU.IsAppRelative ("~/Stuff"), "A1");
324 Assert.IsFalse (VPU.IsAppRelative ("./Stuff"), "A2");
325 Assert.IsFalse (VPU.IsAppRelative ("/Stuff"), "A3");
326 Assert.IsFalse (VPU.IsAppRelative ("/"), "A4");
327 Assert.IsFalse (VPU.IsAppRelative ("~Stuff"), "A5");
329 Assert.IsTrue (VPU.IsAppRelative ("~"), "A0");
330 Assert.IsTrue (VPU.IsAppRelative ("~\\Stuff"), "A1");
331 Assert.IsFalse (VPU.IsAppRelative (".\\Stuff"), "A2");
332 Assert.IsFalse (VPU.IsAppRelative ("\\Stuff"), "A3");
333 Assert.IsFalse (VPU.IsAppRelative ("\\"), "A4");
334 Assert.IsFalse (VPU.IsAppRelative ("~Stuff"), "A5");
338 [ExpectedException (typeof (ArgumentNullException))]
339 public void IsAppRelative_ArgException1 ()
341 Assert.IsFalse (VPU.IsAppRelative (""), "A1");
345 [ExpectedException (typeof (ArgumentNullException))]
346 public void IsAppRelative_ArgException2 ()
348 Assert.IsFalse (VPU.IsAppRelative (null), "A1");
353 /* this test when run on MS generates the following stack trace (NRE):
354 at System.Web.Util.UrlPath.MakeVirtualPathAppAbsolute(String virtualPath, String applicationPath)
355 at System.Web.Util.UrlPath.MakeRelative(String from, String to)
356 at System.Web.VirtualPathUtility.MakeRelative(String fromPath, String toPath)
357 at MonoTests.System.Web.VirtualPathUtilityTest.MakeRelative()
359 public void MakeRelative ()
361 Assert.AreEqual ("../bar", VPU.MakeRelative ("~/foo/hi", "~/foo/bar"), "A1");
366 public void RemoveTrailingSlash ()
368 Assert.AreEqual ("/hi/there", VPU.RemoveTrailingSlash ("/hi/there/"), "A1");
369 Assert.AreEqual ("/hi/there", VPU.RemoveTrailingSlash ("/hi/there"), "A2");
370 Assert.AreEqual ("/", VPU.RemoveTrailingSlash ("/"), "A3");
371 Assert.AreEqual (null, VPU.RemoveTrailingSlash (""), "A4");
372 Assert.AreEqual (null, VPU.RemoveTrailingSlash (null), "A5");
376 [ExpectedException (typeof (ArgumentNullException))]
377 public void Combine1 ()
379 VPU.Combine (null, "something");
383 [ExpectedException (typeof (ArgumentException))]
384 public void Combine2 ()
386 VPU.Combine ("something", null);
390 [ExpectedException (typeof (ArgumentNullException))]
391 public void GetDirectory1 ()
393 VPU.GetDirectory (null);
397 [ExpectedException (typeof (ArgumentNullException))]
398 public void GetDirectory2 ()
400 VPU.GetDirectory ("");
404 [ExpectedException (typeof (ArgumentException))]
405 public void GetDirectory3 ()
407 VPU.GetDirectory ("hola");
411 public void GetDirectory4 ()
413 Assert.AreEqual ("/direc/", VPU.GetDirectory ("/direc/somefilenoextension"));
414 Assert.AreEqual ("/direc/", VPU.GetDirectory ("/direc/somefile.aspx"));
415 Assert.AreEqual ("/direc/", VPU.GetDirectory ("/////direc///somefile.aspx"));
416 Assert.AreEqual ("/direc/", VPU.GetDirectory ("\\\\direc\\///somefile.aspx"));
417 Assert.AreEqual ("/direc/", VPU.GetDirectory ("/direc/somefilenoextension/"));
418 Assert.AreEqual (null, VPU.GetDirectory ("/"), "A3");
420 Assert.AreEqual (null, VPU.GetDirectory ("/dir1/.."), "/dir1/..");
421 Assert.AreEqual (null, VPU.GetDirectory ("/dir1/../"), "/dir1/../");
422 Assert.AreEqual ("/", VPU.GetDirectory ("/dir1/../dir2"), "/dir1/../dir2");
423 Assert.AreEqual ("/", VPU.GetDirectory ("/dir1/../dir2/"), "/dir1/../dir2/");
424 Assert.AreEqual ("/dir2/", VPU.GetDirectory ("/dir1/../dir2/somefile.aspx"));
426 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefilenoextension"));
427 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefile.aspx"));
428 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/////direc///somefile.aspx"));
429 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~\\\\direc\\///somefile.aspx"));
430 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefilenoextension/"));
434 public void GetDirectory5 ()
436 new WebTest (PageInvoker.CreateOnLoad (GetDirectory5_Load)).Run ();
439 public static void GetDirectory5_Load (Page p)
441 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefilenoextension"));
442 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefile.aspx"));
443 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/////direc///somefile.aspx"));
444 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~\\\\direc\\///somefile.aspx"));
445 Assert.AreEqual ("~/direc/", VPU.GetDirectory ("~/direc/somefilenoextension/"));
446 Assert.AreEqual ("/", VPU.GetDirectory ("~/"), "~/");
447 Assert.AreEqual ("/", VPU.GetDirectory ("~"), "~");
449 Assert.AreEqual ("/", VPU.GetDirectory ("~/dir1/.."), "/dir1/..");
450 Assert.AreEqual ("/", VPU.GetDirectory ("~/dir1/../"), "/dir1/../");
451 Assert.AreEqual ("~/", VPU.GetDirectory ("~/dir1/../dir2"), "/dir1/../dir2");
452 Assert.AreEqual ("~/", VPU.GetDirectory ("~/dir1/../dir2/"), "/dir1/../dir2/");
453 Assert.AreEqual ("~/dir2/", VPU.GetDirectory ("~/dir1/../dir2/somefile.aspx"));
455 Assert.AreEqual ("/dir1/", VPU.GetDirectory ("~/../dir1/dir2"), "~/../dir1");
456 Assert.AreEqual ("/dir1/", VPU.GetDirectory ("~/../dir1/dir2/"), "~/../dir1/");
460 [ExpectedException (typeof (ArgumentNullException))]
461 public void GetExtension1 ()
463 VPU.GetExtension (null);
467 [ExpectedException (typeof (ArgumentNullException))]
468 public void GetExtension2 ()
471 VPU.GetExtension ("");
475 public void GetExtension3 ()
477 Assert.AreEqual ("", VPU.GetExtension ("/direc/somefilenoextension"));
478 Assert.AreEqual ("", VPU.GetExtension ("/"));
479 Assert.AreEqual ("/direc/", VPU.GetDirectory ("/////direc///somefile.aspx"));
483 public void GetFileName1 ()
485 Assert.AreEqual ("", VPU.GetFileName ("/"));
486 Assert.AreEqual ("hola", VPU.GetFileName ("/hola"));
487 Assert.AreEqual ("hola", VPU.GetFileName ("/hola/"));
488 Assert.AreEqual ("hi", VPU.GetFileName ("/hi/there/.."));
489 Assert.AreEqual ("there", VPU.GetFileName ("/hi/there/."));
493 public void GetFileName4 ()
495 new WebTest (PageInvoker.CreateOnLoad (GetFileName4_Load)).Run ();
498 public static void GetFileName4_Load (Page p)
500 Assert.AreEqual (NunitWebAppName, VPU.GetFileName ("~/"));
501 Assert.AreEqual ("hola", VPU.GetFileName ("~/hola"));
502 Assert.AreEqual ("hola", VPU.GetFileName ("~/hola/"));
503 Assert.AreEqual ("hi", VPU.GetFileName ("~/hi/there/.."));
504 Assert.AreEqual ("there", VPU.GetFileName ("~/hi/there/."));
506 Assert.AreEqual (NunitWebAppName, VPU.GetFileName ("~"));
507 Assert.AreEqual ("", VPU.GetFileName ("~/.."));
508 Assert.AreEqual ("", VPU.GetFileName ("~/../"));
509 Assert.AreEqual ("hi", VPU.GetFileName ("~/../hi"));
510 Assert.AreEqual ("hi", VPU.GetFileName ("~/../hi/"));
514 [ExpectedException (typeof (ArgumentException))]
515 public void GetFileName5 ()
517 VPU.GetFileName ("hi");
521 [ExpectedException (typeof (ArgumentNullException))]
522 public void GetFileName2 ()
524 VPU.GetFileName (null);
528 [ExpectedException (typeof (ArgumentNullException))]
529 public void GetFileName3 ()
531 VPU.GetFileName ("");
535 [ExpectedException (typeof (NullReferenceException))]
536 public void MakeRelative1 ()
538 VPU.MakeRelative (null, "");
542 [ExpectedException (typeof (NullReferenceException))]
543 public void MakeRelative2 ()
545 VPU.MakeRelative ("", null);
548 // LAMESPEC: MSDN: If the fromPath and toPath parameters are not rooted; that is,
549 // they do not equal the root operator (the tilde [~]), do not start with a tilde (~),
550 // such as a tilde and a slash mark (~/) or a tilde and a double backslash (~//),
551 // or do not start with a slash mark (/), an ArgumentException exception is thrown.
553 [ExpectedException (typeof (ArgumentOutOfRangeException))]
554 public void MakeRelative3 ()
556 VPU.MakeRelative ("/", "i");
560 [ExpectedException (typeof (ArgumentOutOfRangeException))]
561 public void MakeRelative4 ()
563 VPU.MakeRelative ("aa", "/i");
567 public void MakeRelative5 ()
569 Assert.AreEqual ("", VPU.MakeRelative ("", ""));
570 Assert.AreEqual ("", VPU.MakeRelative ("/something", ""));
574 [Category ("NotWorking")]
575 public void MakeRelative6()
577 Assert.AreEqual ("./", VPU.MakeRelative ("/", "/"));
578 Assert.AreEqual ("directory1", VPU.MakeRelative ("/directory1", "/directory1"));
579 Assert.AreEqual ("directory2", VPU.MakeRelative ("/directory1", "/directory2"));
580 Assert.AreEqual ("directory1", VPU.MakeRelative ("/", "/directory1"));
581 Assert.AreEqual ("", VPU.MakeRelative ("/directory1", "/"));
582 Assert.AreEqual ("./", VPU.MakeRelative ("/directory1/", "/directory1/"));
583 Assert.AreEqual ("directory1/file1.aspx", VPU.MakeRelative ("/directory1", "/directory1/file1.aspx"));
584 Assert.AreEqual ("file1.aspx", VPU.MakeRelative ("/directory1/file1.aspx", "/directory1/file1.aspx"));
585 Assert.AreEqual ("file1.aspx", VPU.MakeRelative ("/directory1/", "/directory1/file1.aspx"));
586 Assert.AreEqual ("../directory2/file2.aspx", VPU.MakeRelative ("/directory1/file1.aspx", "/directory2/file2.aspx"));
590 [Category ("NotWorking")]
591 public void MakeRelative6_a ()
593 Assert.AreEqual ("directory1", VPU.MakeRelative ("/directory1/../", "/directory1"));
594 Assert.AreEqual ("", VPU.MakeRelative ("/directory1", "/directory1/../"));
595 Assert.AreEqual ("./", VPU.MakeRelative ("/", "/directory1/../"));
596 Assert.AreEqual ("directory1", VPU.MakeRelative ("/directory1", "/directory2/../directory1"));
600 [Category ("NotWorking")]
601 [Category ("NunitWeb")]
602 public void MakeRelative7 ()
604 new WebTest (PageInvoker.CreateOnLoad (MakeRelative7_Load)).Run ();
607 public static void MakeRelative7_Load (Page p)
609 Assert.AreEqual ("./", VPU.MakeRelative ("~", "~"), "~, ~");
610 Assert.AreEqual ("./", VPU.MakeRelative ("~/", "~/"));
611 Assert.AreEqual ("./", VPU.MakeRelative ("~//", "~//"));
612 Assert.AreEqual ("./", VPU.MakeRelative ("~", "~//"), "~, ~//");
613 Assert.AreEqual ("directory1", VPU.MakeRelative ("~/directory1", "~/directory1"));
614 Assert.AreEqual ("directory2", VPU.MakeRelative ("~/directory1", "~/directory2"));
615 Assert.AreEqual ("directory1", VPU.MakeRelative ("~/", "~/directory1"));
616 Assert.AreEqual ("", VPU.MakeRelative ("~/directory1", "~/"));
617 Assert.AreEqual ("./", VPU.MakeRelative ("~/directory1/", "~/directory1/"));
618 Assert.AreEqual ("directory1/file1.aspx", VPU.MakeRelative ("~/directory1", "~/directory1/file1.aspx"));
619 Assert.AreEqual ("file1.aspx", VPU.MakeRelative ("~/directory1/", "~/directory1/file1.aspx"));
620 Assert.AreEqual ("../directory2/file2.aspx", VPU.MakeRelative ("~/directory1/file1.aspx", "~/directory2/file2.aspx"));
622 Assert.AreEqual ("directory1", VPU.MakeRelative ("~/directory1/../", "~/directory1"));
623 Assert.AreEqual ("", VPU.MakeRelative ("~/directory1", "~/directory1/../"));
624 Assert.AreEqual ("./", VPU.MakeRelative ("~/", "~/directory1/../"));
625 Assert.AreEqual ("directory1", VPU.MakeRelative ("~/directory1", "~/directory2/../directory1"));
628 Assert.AreEqual ("../", VPU.MakeRelative ("~", "/"));
629 Assert.AreEqual ("NunitWeb/", VPU.MakeRelative ("/", "~"));
633 public void RemoveTrailingSlash2 ()
635 Assert.AreEqual (null, VPU.RemoveTrailingSlash (null));
636 Assert.AreEqual (null, VPU.RemoveTrailingSlash (""));
637 Assert.AreEqual ("/", VPU.RemoveTrailingSlash ("/"));
638 Assert.AreEqual ("////", VPU.RemoveTrailingSlash ("/////"));
639 Assert.AreEqual ("/pepe", VPU.RemoveTrailingSlash ("/pepe"));
640 Assert.AreEqual ("/pepe", VPU.RemoveTrailingSlash ("/pepe/"));
644 [Category("NunitWeb")]
645 [ExpectedException (typeof (ArgumentNullException))]
646 public void ToAbsolute1 ()
648 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute1_Load)).Run();
651 public static void ToAbsolute1_Load(Page p)
653 VPU.ToAbsolute(null);
657 [Category("NunitWeb")]
658 [ExpectedException (typeof (ArgumentNullException))]
659 public void ToAbsolute2 ()
661 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute2_Load)).Run();
664 public static void ToAbsolute2_Load(Page p)
670 [Category("NunitWeb")]
671 [ExpectedException (typeof (ArgumentException))]
672 public void ToAbsolute3 ()
674 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute3_Load)).Run();
677 public static void ToAbsolute3_Load(Page p)
679 VPU.ToAbsolute("..");
683 [Category ("NunitWeb")]
684 [ExpectedException (typeof (ArgumentException))]
685 public void ToAbsolute4 ()
687 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute4_Load)).Run();
690 public static void ToAbsolute4_Load(Page p)
692 VPU.ToAbsolute("...");
696 [Category ("NunitWeb")]
697 [ExpectedException (typeof (ArgumentException))]
698 public void ToAbsolute5 ()
700 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute5_Load)).Run();
703 public static void ToAbsolute5_Load(Page p)
705 VPU.ToAbsolute("../blah");
709 [Category("NunitWeb")]
710 public void ToAbsolute6()
712 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute6_Load)).Run();
714 public static void ToAbsolute6_Load(Page p)
716 Assert.AreEqual ("/" + NunitWebAppName + "/", VPU.ToAbsolute ("~/"));
717 Assert.AreEqual ("/" + NunitWebAppName, VPU.ToAbsolute ("~"));
721 [Category("NunitWeb")]
722 public void ToAbsolute7 ()
724 new WebTest(PageInvoker.CreateOnLoad(ToAbsolute7_Load)).Run();
726 public static void ToAbsolute7_Load(Page p)
728 Assert.AreEqual ("/", VPU.ToAbsolute ("/"));
729 Assert.AreEqual ("/", VPU.ToAbsolute ("//"));
732 public void ToAbsolute8 ()
734 Assert.AreEqual ("/", VPU.ToAbsolute ("/", "/ROOT"));
735 Assert.AreEqual ("/blah/blah/", VPU.ToAbsolute ("/blah//blah//", "/ROOT"));
736 Assert.AreEqual ("/blah/blah/", VPU.ToAbsolute ("/blah\\blah/", "/ROOT"));
740 public void ToAbsolute8_a ()
742 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1/../blah2/", "/ROOT"));
743 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1//../blah2/", "/ROOT"));
744 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1/\\../blah2/", "/ROOT"));
745 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1\\\\../blah2/", "/ROOT"));
746 Assert.AreEqual ("/blah1/blah2/", VPU.ToAbsolute ("/blah1/./blah2/", "/ROOT"));
748 Assert.AreEqual ("/blah1", VPU.ToAbsolute ("/blah1/blah2/..", "/ROOT"));
749 Assert.AreEqual ("/", VPU.ToAbsolute ("/blah1/..", "/ROOT"));
750 Assert.AreEqual ("/blah1/", VPU.ToAbsolute ("/blah1/blah2/../", "/ROOT"));
751 Assert.AreEqual ("/", VPU.ToAbsolute ("/blah1/../", "/ROOT"));
753 Assert.AreEqual ("/blah1", VPU.ToAbsolute ("/blah1/.", "/ROOT"));
754 Assert.AreEqual ("/", VPU.ToAbsolute ("/.", "/ROOT"));
755 Assert.AreEqual ("/blah1/", VPU.ToAbsolute ("/blah1/./", "/ROOT"));
756 Assert.AreEqual ("/", VPU.ToAbsolute ("/./", "/ROOT"));
760 public void ToAbsolute8_b ()
762 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1/../blah2/"));
763 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1//../blah2/"));
764 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1/\\../blah2/"));
765 Assert.AreEqual ("/blah2/", VPU.ToAbsolute ("/blah1\\\\../blah2/"));
766 Assert.AreEqual ("/blah1/blah2/", VPU.ToAbsolute ("/blah1/./blah2/"));
770 public void ToAbsolute9 ()
772 Assert.AreEqual ("/ROOT/", VPU.ToAbsolute ("~", "/ROOT"));
773 Assert.AreEqual ("/ROOT/", VPU.ToAbsolute ("~/", "/ROOT"));
774 Assert.AreEqual ("/ROOT/blah", VPU.ToAbsolute ("~/blah", "/ROOT/"));
778 public void ToAppRelative ()
780 Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/hi", null));
781 Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/hi", ""));
782 Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/hi", "/.."));
783 Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/hi", "me"));
785 Assert.AreEqual ("~", VPU.ToAppRelative ("~", "/ROOT"));
786 Assert.AreEqual ("~/", VPU.ToAppRelative ("~/", "/ROOT"));
787 Assert.AreEqual ("~/blah", VPU.ToAppRelative ("~/blah", "/ROOT/"));
788 Assert.AreEqual ("~/blah2/", VPU.ToAppRelative ("~/blah1/../blah2/", "/ROOT/"));
790 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT", "/ROOT"));
791 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT/", "/ROOT"));
792 Assert.AreEqual ("~/blah/blah/", VPU.ToAppRelative ("/ROOT/blah//blah//", "/ROOT"));
793 Assert.AreEqual ("~/blah/blah/", VPU.ToAppRelative ("/ROOT/blah\\blah/", "/ROOT"));
795 Assert.AreEqual ("~/blah2/", VPU.ToAppRelative ("/ROOT/blah1/../blah2/", "/ROOT"));
796 Assert.AreEqual ("~/blah1/blah2/", VPU.ToAppRelative ("/ROOT/blah1/./blah2/", "/ROOT"));
798 Assert.AreEqual ("~/blah1", VPU.ToAppRelative ("/ROOT/blah1/blah2/..", "/ROOT"));
799 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT/blah1/..", "/ROOT"));
800 Assert.AreEqual ("~/blah1/", VPU.ToAppRelative ("/ROOT/blah1/blah2/../", "/ROOT"));
801 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT/blah1/../", "/ROOT"));
803 Assert.AreEqual ("~/blah1", VPU.ToAppRelative ("/ROOT/blah1/.", "/ROOT"));
804 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT/.", "/ROOT"));
805 Assert.AreEqual ("~/blah1/", VPU.ToAppRelative ("/ROOT/blah1/./", "/ROOT"));
806 Assert.AreEqual ("~/", VPU.ToAppRelative ("/ROOT/./", "/ROOT"));
808 Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT", "/"));
809 Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT", "/hi/.."));
810 Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT/hi/..", "/"));
814 public void ToAppRelative2 ()
816 new WebTest (PageInvoker.CreateOnLoad (ToAppRelative2_Load)).Run ();
819 public static void ToAppRelative2_Load (Page p)
821 Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/../NunitWeb/hi", "/NunitWeb"));
825 [ExpectedException(typeof(ArgumentNullException))]
826 public void ToAppRelative_Exc1 ()
828 VPU.ToAppRelative ("/ROOT/hi", "");
832 [ExpectedException (typeof (ArgumentNullException))]
833 public void ToAppRelative_Exc2 ()
835 VPU.ToAppRelative ("/ROOT/hi", null);
839 [ExpectedException (typeof (ArgumentException))]
840 public void ToAppRelative_Exc3 ()
842 VPU.ToAppRelative ("/ROOT/hi", "hi");
846 [ExpectedException (typeof (HttpException))]
847 public void ToAppRelative_Exc4 () {
848 VPU.ToAppRelative ("/ROOT/hi", "/../hi");
852 [ExpectedException (typeof (ArgumentNullException))]
853 public void ToAppRelative_Exc5 ()
855 VPU.ToAppRelative (null, "/ROOT");
859 [ExpectedException (typeof (ArgumentNullException))]
860 public void ToAppRelative_Exc6 ()
862 VPU.ToAppRelative ("", "/ROOT");
866 [ExpectedException (typeof (ArgumentException))]
867 //The relative virtual path 'hi' is not allowed here.
868 public void ToAppRelative_Exc7 ()
870 VPU.ToAppRelative ("hi", "/ROOT");
874 [ExpectedException (typeof (ArgumentException))]
875 //The relative virtual path 'hi' is not allowed here.
876 public void ToAppRelative_Exc7_a ()
878 VPU.ToAppRelative ("hi", null);
882 [ExpectedException (typeof (HttpException))]
883 public void ToAppRelative_Exc8 ()
885 VPU.ToAppRelative ("/../ROOT/hi", "/ROOT");
889 [ExpectedException (typeof (ArgumentException))]
890 public void ToAbsolute10 ()
892 VPU.ToAbsolute ("../blah", "/ROOT");
896 [ExpectedException (typeof (ArgumentException))]
897 public void ToAbsolute11 ()
899 VPU.ToAbsolute ("blah", "/ROOT");
903 [ExpectedException (typeof (ArgumentException))]
904 public void ToAbsolute12 ()
906 VPU.ToAbsolute ("~/blah", "ROOT");
910 public void ToAbsolute13 ()
912 Assert.AreEqual ("/blah", VPU.ToAbsolute ("/blah", "ROOT"));