Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mcs / class / System.Web / Test / System.Web / VirtualPathUtilityTest.cs
1 //
2 // System.Web.VirtualPathUtilityTest.cs - Unit tests for System.Web.VirtualPathUtility
3 //
4 // Author:
5 //      Chris Toshok  <toshok@novell.com>
6 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
7 //
8 // Copyright (C) 2005,2006 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 #if NET_2_0
31
32 using System;
33 using System.Web;
34 using VPU = System.Web.VirtualPathUtility;
35 using MonoTests.SystemWeb.Framework;
36 using MonoTests.stand_alone.WebHarness;
37 using System.Web.UI;
38
39 using NUnit.Framework;
40
41 namespace MonoTests.System.Web {
42
43         [TestFixture]
44         public class VirtualPathUtilityTest {
45
46                 const string NunitWebAppName = "NunitWeb";
47
48                 [Test]
49                 public void AppendTrailingSlash ()
50                 {
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");
56                 }
57
58                 [Test]
59                 public void Combine ()
60                 {
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");
64                         
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");
68
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");
72                 }
73
74                 [Test]
75                 public void Combine3 ()
76                 {
77                         Assert.AreEqual ("/", VPU.Combine ("/hi/", ".."), "A1");
78                         Assert.AreEqual ("/", VPU.Combine ("/hi/there", ".."), "A2");
79                         Assert.AreEqual ("/hi", VPU.Combine ("/hi/there/", ".."), "A3");
80
81                         Assert.AreEqual ("/", VPU.Combine ("/hi/", "../"), "A1");
82                         Assert.AreEqual ("/", VPU.Combine ("/hi/there", "../"), "A2");
83                         Assert.AreEqual ("/hi/", VPU.Combine ("/hi/there/", "../"), "A3");
84                         
85                         Assert.AreEqual ("/", VPU.Combine ("/", "."), "A1");
86                         Assert.AreEqual ("/", VPU.Combine ("/hi", "."), "A2");
87                         Assert.AreEqual ("/hi", VPU.Combine ("/hi/", "."), "A3");
88
89                         Assert.AreEqual ("/", VPU.Combine ("/", "./"), "A1");
90                         Assert.AreEqual ("/", VPU.Combine ("/hi", "./"), "A2");
91                         Assert.AreEqual ("/hi/", VPU.Combine ("/hi/", "./"), "A3");
92
93                         Assert.AreEqual ("/", VPU.Combine ("/hi", "there/../"), "A1");
94                         Assert.AreEqual ("/hi", VPU.Combine ("/hi/there", "you/.."), "A2");
95
96                         Assert.AreEqual ("/there/", VPU.Combine ("/hi", "there/./"), "A1");
97                         Assert.AreEqual ("/hi/you", VPU.Combine ("/hi/there", "you/."), "A2");
98                         
99                         Assert.AreEqual ("/blah2/", VPU.Combine ("/ROOT", "/blah1/../blah2/"));
100                         Assert.AreEqual ("/blah1/blah2/", VPU.Combine ("/ROOT", "/blah1/./blah2/"));
101
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/../"));
106
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", "/./"));
111
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");
119                 }
120
121                 [Test]
122                 public void Combine4 ()
123                 {
124                         new WebTest (PageInvoker.CreateOnLoad (Combine4_Load)).Run ();
125                 }
126
127                 public static void Combine4_Load (Page p)
128                 {
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/"));
132
133                         Assert.AreEqual ("~/blah2/", VPU.Combine ("/ROOT", "~/blah1/../blah2/"));
134                         Assert.AreEqual ("~/blah1/blah2/", VPU.Combine ("/ROOT", "~/blah1/./blah2/"));
135
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/../"));
140
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", "~/./"));
145
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/"));
153
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"));
158                         
159                         Assert.AreEqual ("/me", VPU.Combine ("~/..", "me"));
160
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");
168                         
169                         Assert.AreEqual (HttpRuntime.AppDomainAppVirtualPath, VPU.Combine ("/ROOT", HttpRuntime.AppDomainAppVirtualPath));
170                         Assert.AreEqual (HttpRuntime.AppDomainAppVirtualPath, VPU.Combine ("~/ROOT", HttpRuntime.AppDomainAppVirtualPath));
171                 }
172
173                 [Test]
174                 [ExpectedException (typeof (ArgumentException))]
175                 // The relative virtual path 'hi/there' is not allowed here.
176                 public void Combine_ArgException1 ()
177                 {
178                         Assert.AreEqual ("hi/there/you", VPU.Combine ("hi/there", "you"), "A1");
179                 }
180
181                 [Test]
182                 [ExpectedException (typeof (ArgumentException))]
183                 // The relative virtual path 'hi/there' is not allowed here.
184                 public void Combine_ArgException2 ()
185                 {
186                         Assert.AreEqual ("hi/there", VPU.Combine ("hi/there", null), "A1");
187                 }
188
189                 [Test]
190                 [ExpectedException (typeof (ArgumentNullException))]
191                 public void Combine_ArgException2_1 ()
192                 {
193                         Assert.AreEqual ("hi/there", VPU.Combine ("/hi/there", null), "A1");
194                 }
195
196                 [Test]
197                 [ExpectedException (typeof (ArgumentException))]
198                 // The relative virtual path 'hi/there' is not allowed here.
199                 public void Combine_ArgException2_2 ()
200                 {
201                         Assert.AreEqual ("hi/there", VPU.Combine ("hi/there", "/dir"), "A1");
202                 }
203                 
204                 [Test]
205                 [ExpectedException (typeof (HttpException))]
206                 public void Combine_ArgException2_3 ()
207                 {
208                         Assert.AreEqual ("hi/there", VPU.Combine ("/../hi", null), "A1");
209                 }
210
211                 [Test]
212                 [ExpectedException (typeof (ArgumentNullException))]
213                 public void Combine_ArgException3 ()
214                 {
215                         Assert.AreEqual ("hi/there", VPU.Combine (null, "there"), "A1");
216                 }
217
218                 [Test]
219                 [ExpectedException (typeof (ArgumentNullException))]
220                 /* stack trace is:
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()
224                 */
225                 public void Combine_ArgException4 ()
226                 {
227                         Assert.AreEqual ("/you", VPU.Combine ("", "you"), "A1");
228                 }
229
230                 [Test]
231                 [ExpectedException (typeof (ArgumentNullException))]
232                 /* stack trace is:
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()
236                 */
237                 public void Combine_ArgException5 ()
238                 {
239                         Assert.AreEqual ("/hi", VPU.Combine ("/hi", ""), "A1");
240                 }
241                 
242                 [Test]
243                 [ExpectedException (typeof (HttpException))]
244                 public void Combine_ArgException6 ()
245                 {
246                         VPU.Combine ("/ROOT", "..");
247                 }
248
249                 [Test]
250                 [ExpectedException (typeof (HttpException))]
251                 public void Combine_ArgException7 ()
252                 {
253                         VPU.Combine ("/ROOT", "/..");
254                 }
255
256                 [Test]
257                 [ExpectedException (typeof (HttpException))]
258                 public void Combine_ArgException8 () {
259                         VPU.Combine ("/ROOT", "./..");
260                 }
261
262                 [Test]
263                 public void GetExtension ()
264                 {
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");
269
270                         Assert.AreEqual (".aspx", VPU.GetExtension ("/hi/./index.aspx"), "A1");
271                         Assert.AreEqual ("", VPU.GetExtension ("hi/index"), "A2");
272
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");
277
278                         Assert.AreEqual ("", VPU.GetExtension (".."), "A2");
279                         Assert.AreEqual ("", VPU.GetExtension ("../.."), "A2");
280                         Assert.AreEqual (".aspx", VPU.GetExtension ("../../file.aspx"), "A2");
281                 }
282
283                 [Test]
284                 public void GetFileName ()
285                 {
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");
289                 }
290
291                 [Test]
292                 public void IsAbsolute ()
293                 {
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");
298
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");
303                 }
304
305                 [Test]
306                 [ExpectedException (typeof (ArgumentNullException))]
307                 public void IsAbsolute_ArgException1 ()
308                 {
309                         Assert.IsFalse (VPU.IsAbsolute (""), "A1");
310                 }
311
312                 [Test]
313                 [ExpectedException (typeof (ArgumentNullException))]
314                 public void IsAbsolute_ArgException2 ()
315                 {
316                         Assert.IsFalse (VPU.IsAbsolute (null), "A1");
317                 }
318
319                 [Test]
320                 public void IsAppRelative ()
321                 {
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");
328                         
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");
335                 }
336
337                 [Test]
338                 [ExpectedException (typeof (ArgumentNullException))]
339                 public void IsAppRelative_ArgException1 ()
340                 {
341                         Assert.IsFalse (VPU.IsAppRelative (""), "A1");
342                 }
343
344                 [Test]
345                 [ExpectedException (typeof (ArgumentNullException))]
346                 public void IsAppRelative_ArgException2 ()
347                 {
348                         Assert.IsFalse (VPU.IsAppRelative (null), "A1");
349                 }
350
351 #if false
352                 [Test]
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()
358                 */
359                 public void MakeRelative ()
360                 {
361                         Assert.AreEqual ("../bar", VPU.MakeRelative ("~/foo/hi", "~/foo/bar"), "A1");
362                 }
363 #endif
364
365                 [Test]
366                 public void RemoveTrailingSlash ()
367                 {
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");
373                 }
374
375                 [Test]
376                 [ExpectedException (typeof (ArgumentNullException))]
377                 public void Combine1 ()
378                 {
379                         VPU.Combine (null, "something");
380                 }
381
382                 [Test]
383                 [ExpectedException (typeof (ArgumentException))]
384                 public void Combine2 ()
385                 {
386                         VPU.Combine ("something", null);
387                 }
388
389                 [Test]
390                 [ExpectedException (typeof (ArgumentNullException))]
391                 public void GetDirectory1 ()
392                 {
393                         VPU.GetDirectory (null);
394                 }
395                 
396                 [Test]
397                 [ExpectedException (typeof (ArgumentNullException))]
398                 public void GetDirectory2 ()
399                 {
400                         VPU.GetDirectory ("");
401                 }
402
403                 [Test]
404                 [ExpectedException (typeof (ArgumentException))]
405                 public void GetDirectory3 ()
406                 {
407                         VPU.GetDirectory ("hola");
408                 }
409
410                 [Test]
411                 public void GetDirectory4 ()
412                 {
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");
419
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"));
425                         
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/"));
431                 }
432
433                 [Test]
434                 public void GetDirectory5 ()
435                 {
436                         new WebTest (PageInvoker.CreateOnLoad (GetDirectory5_Load)).Run ();
437                 }
438
439                 public static void GetDirectory5_Load (Page p)
440                 {
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 ("~"), "~");
448
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"));
454
455                         Assert.AreEqual ("/dir1/", VPU.GetDirectory ("~/../dir1/dir2"), "~/../dir1");
456                         Assert.AreEqual ("/dir1/", VPU.GetDirectory ("~/../dir1/dir2/"), "~/../dir1/");
457                 }
458
459                 [Test]
460                 [ExpectedException (typeof (ArgumentNullException))]
461                 public void GetExtension1 ()
462                 {
463                         VPU.GetExtension (null);
464                 }
465
466                 [Test]
467                 [ExpectedException (typeof (ArgumentNullException))]
468                 public void GetExtension2 ()
469                 {
470                         // Amazing.
471                         VPU.GetExtension ("");
472                 }
473
474                 [Test]
475                 public void GetExtension3 ()
476                 {
477                         Assert.AreEqual ("", VPU.GetExtension ("/direc/somefilenoextension"));
478                         Assert.AreEqual ("", VPU.GetExtension ("/"));
479                         Assert.AreEqual ("/direc/", VPU.GetDirectory ("/////direc///somefile.aspx"));
480                 }
481
482                 [Test]
483                 public void GetFileName1 ()
484                 {
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/."));
490                 }
491
492                 [Test]
493                 public void GetFileName4 ()
494                 {
495                         new WebTest (PageInvoker.CreateOnLoad (GetFileName4_Load)).Run ();
496                 }
497
498                 public static void GetFileName4_Load (Page p)
499                 {
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/."));
505
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/"));
511                 }
512
513                 [Test]
514                 [ExpectedException (typeof (ArgumentException))]
515                 public void GetFileName5 ()
516                 {
517                         VPU.GetFileName ("hi");
518                 }
519
520                 [Test]
521                 [ExpectedException (typeof (ArgumentNullException))]
522                 public void GetFileName2 ()
523                 {
524                         VPU.GetFileName (null);
525                 }
526
527                 [Test]
528                 [ExpectedException (typeof (ArgumentNullException))]
529                 public void GetFileName3 ()
530                 {
531                         VPU.GetFileName ("");
532                 }
533
534                 [Test]
535                 [ExpectedException (typeof (NullReferenceException))]
536                 public void MakeRelative1 ()
537                 {
538                         VPU.MakeRelative (null, "");
539                 }
540
541                 [Test]
542                 [ExpectedException (typeof (NullReferenceException))]
543                 public void MakeRelative2 ()
544                 {
545                         VPU.MakeRelative ("", null);
546                 }
547
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.
552                 [Test]
553                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
554                 public void MakeRelative3 ()
555                 {
556                         VPU.MakeRelative ("/", "i");
557                 }
558
559                 [Test]
560                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
561                 public void MakeRelative4 ()
562                 {
563                         VPU.MakeRelative ("aa", "/i");
564                 }
565
566                 [Test]
567                 public void MakeRelative5 ()
568                 {
569                         Assert.AreEqual ("", VPU.MakeRelative ("", ""));
570                         Assert.AreEqual ("", VPU.MakeRelative ("/something", ""));
571                 }
572
573         [Test]
574         [Category ("NotWorking")]
575         public void MakeRelative6()
576         {
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"));
587                 }
588
589                 [Test]
590                 [Category ("NotWorking")]
591                 public void MakeRelative6_a ()
592                 {
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"));
597                 }
598
599                 [Test]
600                 [Category ("NotWorking")]
601                 [Category ("NunitWeb")]
602                 public void MakeRelative7 ()
603                 {
604                         new WebTest (PageInvoker.CreateOnLoad (MakeRelative7_Load)).Run (); 
605                 }
606
607                 public static void MakeRelative7_Load (Page p)
608                 {
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"));
621
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"));
626
627
628                         Assert.AreEqual ("../", VPU.MakeRelative ("~", "/"));
629                         Assert.AreEqual ("NunitWeb/", VPU.MakeRelative ("/", "~"));
630                 }
631
632                 [Test]
633                 public void RemoveTrailingSlash2 ()
634                 {
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/"));
641                 }
642
643                 [Test]
644         [Category("NunitWeb")]
645                 [ExpectedException (typeof (ArgumentNullException))]
646                 public void ToAbsolute1 ()
647                 {
648             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute1_Load)).Run();
649                 }
650
651         public static void ToAbsolute1_Load(Page p)
652         {
653             VPU.ToAbsolute(null);
654         }
655
656                 [Test]
657         [Category("NunitWeb")]
658                 [ExpectedException (typeof (ArgumentNullException))]
659                 public void ToAbsolute2 ()
660                 {
661             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute2_Load)).Run();
662                 }
663
664         public static void ToAbsolute2_Load(Page p) 
665         {
666             VPU.ToAbsolute("");
667         }
668
669                 [Test]
670         [Category("NunitWeb")]
671                 [ExpectedException (typeof (ArgumentException))]
672                 public void ToAbsolute3 ()
673                 {
674             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute3_Load)).Run();
675                 }
676
677         public static void ToAbsolute3_Load(Page p)
678         {
679             VPU.ToAbsolute("..");
680         }
681
682                 [Test]
683                 [Category ("NunitWeb")]
684                 [ExpectedException (typeof (ArgumentException))]
685                 public void ToAbsolute4 ()
686                 {
687             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute4_Load)).Run();
688                 }
689
690         public static void ToAbsolute4_Load(Page p)
691         {
692             VPU.ToAbsolute("...");
693         }
694
695                 [Test]
696                 [Category ("NunitWeb")]
697                 [ExpectedException (typeof (ArgumentException))]
698                 public void ToAbsolute5 ()
699                 {
700             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute5_Load)).Run();
701                 }
702
703         public static void ToAbsolute5_Load(Page p)
704         {
705             VPU.ToAbsolute("../blah");
706         }
707
708                 [Test]
709         [Category("NunitWeb")]
710         public void ToAbsolute6()
711                 {
712             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute6_Load)).Run();
713                 }
714         public static void ToAbsolute6_Load(Page p)
715         {
716                         Assert.AreEqual ("/" + NunitWebAppName + "/", VPU.ToAbsolute ("~/"));
717                         Assert.AreEqual ("/" + NunitWebAppName, VPU.ToAbsolute ("~"));
718                 }
719
720                 [Test]
721                 [Category("NunitWeb")]
722                 public void ToAbsolute7 ()
723                 {
724             new WebTest(PageInvoker.CreateOnLoad(ToAbsolute7_Load)).Run();
725                 }
726         public static void ToAbsolute7_Load(Page p)
727         {
728                         Assert.AreEqual ("/", VPU.ToAbsolute ("/"));
729                         Assert.AreEqual ("/", VPU.ToAbsolute ("//"));
730         }
731                 [Test]
732                 public void ToAbsolute8 ()
733                 {
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"));
737                 }
738
739                 [Test]
740                 public void ToAbsolute8_a ()
741                 {
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"));
747
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"));
752
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"));
757                 }
758                 
759                 [Test]
760                 public void ToAbsolute8_b ()
761                 {
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/"));
767                 }
768
769                 [Test]
770                 public void ToAbsolute9 ()
771                 {
772                         Assert.AreEqual ("/ROOT/", VPU.ToAbsolute ("~", "/ROOT"));
773                         Assert.AreEqual ("/ROOT/", VPU.ToAbsolute ("~/", "/ROOT"));
774                         Assert.AreEqual ("/ROOT/blah", VPU.ToAbsolute ("~/blah", "/ROOT/"));
775                 }
776
777                 [Test]
778                 public void ToAppRelative ()
779                 {
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"));
784
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/"));
789
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"));
794
795                         Assert.AreEqual ("~/blah2/", VPU.ToAppRelative ("/ROOT/blah1/../blah2/", "/ROOT"));
796                         Assert.AreEqual ("~/blah1/blah2/", VPU.ToAppRelative ("/ROOT/blah1/./blah2/", "/ROOT"));
797
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"));
802
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"));
807
808                         Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT", "/"));
809                         Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT", "/hi/.."));
810                         Assert.AreEqual ("~/ROOT", VPU.ToAppRelative ("/ROOT/hi/..", "/"));
811                 }
812
813                 [Test]
814                 public void ToAppRelative2 ()
815                 {
816                         new WebTest (PageInvoker.CreateOnLoad (ToAppRelative2_Load)).Run ();
817                 }
818                 
819                 public static void ToAppRelative2_Load (Page p)
820                 {
821                         Assert.AreEqual ("~/hi", VPU.ToAppRelative ("~/../NunitWeb/hi", "/NunitWeb"));
822                 }
823                 
824                 [Test]
825                 [ExpectedException(typeof(ArgumentNullException))]
826                 public void ToAppRelative_Exc1 ()
827                 {
828                         VPU.ToAppRelative ("/ROOT/hi", "");
829                 }
830
831                 [Test]
832                 [ExpectedException (typeof (ArgumentNullException))]
833                 public void ToAppRelative_Exc2 ()
834                 {
835                         VPU.ToAppRelative ("/ROOT/hi", null);
836                 }
837
838                 [Test]
839                 [ExpectedException (typeof (ArgumentException))]
840                 public void ToAppRelative_Exc3 ()
841                 {
842                         VPU.ToAppRelative ("/ROOT/hi", "hi");
843                 }
844
845                 [Test]
846                 [ExpectedException (typeof (HttpException))]
847                 public void ToAppRelative_Exc4 () {
848                         VPU.ToAppRelative ("/ROOT/hi", "/../hi");
849                 }
850
851                 [Test]
852                 [ExpectedException (typeof (ArgumentNullException))]
853                 public void ToAppRelative_Exc5 ()
854                 {
855                         VPU.ToAppRelative (null, "/ROOT");
856                 }
857
858                 [Test]
859                 [ExpectedException (typeof (ArgumentNullException))]
860                 public void ToAppRelative_Exc6 ()
861                 {
862                         VPU.ToAppRelative ("", "/ROOT");
863                 }
864
865                 [Test]
866                 [ExpectedException (typeof (ArgumentException))]
867                 //The relative virtual path 'hi' is not allowed here.
868                 public void ToAppRelative_Exc7 ()
869                 {
870                         VPU.ToAppRelative ("hi", "/ROOT");
871                 }
872
873                 [Test]
874                 [ExpectedException (typeof (ArgumentException))]
875                 //The relative virtual path 'hi' is not allowed here.
876                 public void ToAppRelative_Exc7_a ()
877                 {
878                         VPU.ToAppRelative ("hi", null);
879                 }
880
881                 [Test]
882                 [ExpectedException (typeof (HttpException))]
883                 public void ToAppRelative_Exc8 ()
884                 {
885                         VPU.ToAppRelative ("/../ROOT/hi", "/ROOT");
886                 }
887
888                 [Test]
889                 [ExpectedException (typeof (ArgumentException))]
890                 public void ToAbsolute10 ()
891                 {
892                         VPU.ToAbsolute ("../blah", "/ROOT");
893                 }
894
895                 [Test]
896                 [ExpectedException (typeof (ArgumentException))]
897                 public void ToAbsolute11 ()
898                 {
899                         VPU.ToAbsolute ("blah", "/ROOT");
900                 }
901
902                 [Test]
903                 [ExpectedException (typeof (ArgumentException))]
904                 public void ToAbsolute12 ()
905                 {
906                         VPU.ToAbsolute ("~/blah", "ROOT");
907                 }
908
909                 [Test]
910                 public void ToAbsolute13 ()
911                 {
912                         Assert.AreEqual ("/blah", VPU.ToAbsolute ("/blah", "ROOT"));
913                 }
914         }
915 }
916
917 #endif
918
919
920
921