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