2
0

VirtualPathProviderTest.cs 4.8 KB

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