* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.Hosting / VirtualPathProviderTest.cs
1 //
2 // System.Web.Hosting.VirtualPathProviderTest
3 // 
4 // Author:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 //
8 // Copyright (C) 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 #if NET_2_0
30 using System;
31 using System.Collections;
32 using System.IO;
33 using System.Web;
34 using System.Web.Caching;
35 using System.Web.Hosting;
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Web.Hosting {
39         class DummyVPP : VirtualPathProvider {
40                 public override bool FileExists (string virtualPath)
41                 {
42                         bool de = base.FileExists (virtualPath);
43                         return de;
44                 }
45
46                 public override bool DirectoryExists (string virtualDir)
47                 {
48                         bool de = base.DirectoryExists (virtualDir);
49                         return de;
50                 }
51
52                 public override VirtualFile GetFile (string virtualPath)
53                 {
54                         VirtualFile vf = base.GetFile (virtualPath);
55                         return vf;
56                 }
57
58                 public override string GetFileHash (string virtualPath, IEnumerable dependencies)
59                 {
60                         return base.GetFileHash (virtualPath, dependencies);
61                 }
62
63                 public override VirtualDirectory GetDirectory (string virtualDir)
64                 {
65                         VirtualDirectory vd = base.GetDirectory (virtualDir);
66                         return vd;
67                 }
68
69                 public override CacheDependency GetCacheDependency (string virtualPath,
70                                                 IEnumerable virtualPathDependencies, DateTime utcStart)
71                 {
72                         CacheDependency cd = base.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart);
73                         return cd;
74                 }
75         }
76
77         [TestFixture]
78         public class VirtualPathProviderTest {
79                 // Unhosted tests: not running inside an ASP.NET appdomain.
80                 // Some tests may yield different results when hosted. I'll add those later.
81                 [Test]
82                 public void FileExists1 ()
83                 {
84                         DummyVPP dummy = new DummyVPP ();
85                         Assert.IsNull (dummy.FileExists ("hola.aspx"));
86                 }
87
88                 [Test]
89                 public void DirectoryExists1 ()
90                 {
91                         DummyVPP dummy = new DummyVPP ();
92                         Assert.IsNull (dummy.DirectoryExists ("hola"));
93                 }
94
95                 [Test]
96                 public void GetFile1 ()
97                 {
98                         DummyVPP dummy = new DummyVPP ();
99                         Assert.IsNull (dummy.GetFile ("index.aspx"));
100                 }
101
102                 [Test]
103                 public void GetFileHash1 ()
104                 {
105                         DummyVPP dummy = new DummyVPP ();
106                         Assert.IsNull (dummy.GetFileHash (null, null));
107                 }
108
109                 [Test]
110                 public void GetFileHash2 ()
111                 {
112                         DummyVPP dummy = new DummyVPP ();
113                         Assert.IsNull (dummy.GetFileHash ("something", null));
114                 }
115
116                 [Test]
117                 public void GetDirectory1 ()
118                 {
119                         DummyVPP dummy = new DummyVPP ();
120                         Assert.IsNull (dummy.GetDirectory ("some_directory"));
121                 }
122
123                 [Test]
124                 public void GetCacheDependency1 ()
125                 {
126                         DummyVPP dummy = new DummyVPP ();
127                         Assert.IsNull (dummy.GetCacheDependency (null, null, DateTime.UtcNow));
128                 }
129
130                 [Test]
131                 public void GetCacheKey1 ()
132                 {
133                         DummyVPP dummy = new DummyVPP ();
134                         Assert.IsNull (dummy.GetCacheKey ("index.aspx"));
135                 }
136
137                 [Test]
138                 [ExpectedException (typeof (NullReferenceException))]
139                 public void OpenFile1 ()
140                 {
141                         VirtualPathProvider.OpenFile ("index.aspx");
142                 }
143
144                 [Test]
145                 public void CombineVirtualPaths1 ()
146                 {
147                         DummyVPP dummy = new DummyVPP ();
148                         Assert.AreEqual ("/otherroot", dummy.CombineVirtualPaths ("/root", "/otherroot"));
149                 }
150
151                 [Test]
152                 public void CombineVirtualPaths2 ()
153                 {
154                         DummyVPP dummy = new DummyVPP ();
155                         Assert.AreEqual ("/otherleaf", dummy.CombineVirtualPaths ("/root", "otherleaf"));
156                 }
157
158                 [Test]
159                 public void CombineVirtualPaths3 ()
160                 {
161                         DummyVPP dummy = new DummyVPP ();
162                         Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "otherleaf/index.aspx"));
163                 }
164
165                 [Test]
166                 public void CombineVirtualPaths4 ()
167                 {
168                         DummyVPP dummy = new DummyVPP ();
169                         Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "./otherleaf/index.aspx"));
170                 }
171
172                 [Test]
173                 [ExpectedException (typeof (ArgumentException))]
174                 public void CombineVirtualPaths5 ()
175                 {
176                         DummyVPP dummy = new DummyVPP ();
177                         dummy.CombineVirtualPaths ("root", "./otherleaf/index.aspx");
178                 }
179         }
180         
181 }
182 #endif
183