2 // System.Web.Hosting.VirtualPathProviderTest
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // Copyright (C) 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.
31 using System.Collections;
34 using System.Web.Caching;
35 using System.Web.Hosting;
36 using NUnit.Framework;
38 namespace MonoTests.System.Web.Hosting {
39 class DummyVPP : VirtualPathProvider {
40 public override bool FileExists (string virtualPath)
42 bool de = base.FileExists (virtualPath);
46 public override bool DirectoryExists (string virtualDir)
48 bool de = base.DirectoryExists (virtualDir);
52 public override VirtualFile GetFile (string virtualPath)
54 VirtualFile vf = base.GetFile (virtualPath);
58 public override VirtualDirectory GetDirectory (string virtualDir)
60 VirtualDirectory vd = base.GetDirectory (virtualDir);
64 public override CacheDependency GetCacheDependency (string virtualPath,
65 IEnumerable virtualPathDependencies, DateTime utcStart)
67 CacheDependency cd = base.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart);
73 public class VirtualPathProviderTest {
74 // Unhosted tests: not running inside an ASP.NET appdomain.
75 // Some tests may yield different results when hosted. I'll add those later.
77 public void FileExists1 ()
79 DummyVPP dummy = new DummyVPP ();
80 Assert.IsNull (dummy.FileExists ("hola.aspx"));
84 public void DirectoryExists1 ()
86 DummyVPP dummy = new DummyVPP ();
87 Assert.IsNull (dummy.DirectoryExists ("hola"));
91 public void GetFile1 ()
93 DummyVPP dummy = new DummyVPP ();
94 Assert.IsNull (dummy.GetFile ("index.aspx"));
98 public void GetDirectory1 ()
100 DummyVPP dummy = new DummyVPP ();
101 Assert.IsNull (dummy.GetDirectory ("some_directory"));
105 public void GetCacheDependency1 ()
107 DummyVPP dummy = new DummyVPP ();
108 Assert.IsNull (dummy.GetCacheDependency (null, null, DateTime.UtcNow));
112 public void GetCacheKey1 ()
114 DummyVPP dummy = new DummyVPP ();
115 Assert.IsNull (dummy.GetCacheKey ("index.aspx"));
119 [ExpectedException (typeof (NullReferenceException))]
120 public void OpenFile1 ()
122 VirtualPathProvider.OpenFile ("index.aspx");
126 public void CombineVirtualPaths1 ()
128 DummyVPP dummy = new DummyVPP ();
129 Assert.AreEqual ("/otherroot", dummy.CombineVirtualPaths ("/root", "/otherroot"));
133 public void CombineVirtualPaths2 ()
135 DummyVPP dummy = new DummyVPP ();
136 Assert.AreEqual ("/otherleaf", dummy.CombineVirtualPaths ("/root", "otherleaf"));
140 public void CombineVirtualPaths3 ()
142 DummyVPP dummy = new DummyVPP ();
143 Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "otherleaf/index.aspx"));
147 public void CombineVirtualPaths4 ()
149 DummyVPP dummy = new DummyVPP ();
150 Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "./otherleaf/index.aspx"));
154 [ExpectedException (typeof (ArgumentException))]
155 public void CombineVirtualPaths5 ()
157 DummyVPP dummy = new DummyVPP ();
158 dummy.CombineVirtualPaths ("root", "./otherleaf/index.aspx");