VirtualPathProviderTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 VirtualDirectory GetDirectory (string virtualDir)
  55. {
  56. VirtualDirectory vd = base.GetDirectory (virtualDir);
  57. return vd;
  58. }
  59. public override CacheDependency GetCacheDependency (string virtualPath,
  60. IEnumerable virtualPathDependencies, DateTime utcStart)
  61. {
  62. CacheDependency cd = base.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart);
  63. return cd;
  64. }
  65. }
  66. [TestFixture]
  67. public class VirtualPathProviderTest {
  68. // Unhosted tests: not running inside an ASP.NET appdomain.
  69. // Some tests may yield different results when hosted. I'll add those later.
  70. [Test]
  71. public void FileExists1 ()
  72. {
  73. DummyVPP dummy = new DummyVPP ();
  74. Assert.IsNull (dummy.FileExists ("hola.aspx"));
  75. }
  76. [Test]
  77. public void DirectoryExists1 ()
  78. {
  79. DummyVPP dummy = new DummyVPP ();
  80. Assert.IsNull (dummy.DirectoryExists ("hola"));
  81. }
  82. [Test]
  83. public void GetFile1 ()
  84. {
  85. DummyVPP dummy = new DummyVPP ();
  86. Assert.IsNull (dummy.GetFile ("index.aspx"));
  87. }
  88. [Test]
  89. public void GetDirectory1 ()
  90. {
  91. DummyVPP dummy = new DummyVPP ();
  92. Assert.IsNull (dummy.GetDirectory ("some_directory"));
  93. }
  94. [Test]
  95. public void GetCacheDependency1 ()
  96. {
  97. DummyVPP dummy = new DummyVPP ();
  98. Assert.IsNull (dummy.GetCacheDependency (null, null, DateTime.UtcNow));
  99. }
  100. [Test]
  101. public void GetCacheKey1 ()
  102. {
  103. DummyVPP dummy = new DummyVPP ();
  104. Assert.IsNull (dummy.GetCacheKey ("index.aspx"));
  105. }
  106. [Test]
  107. [ExpectedException (typeof (NullReferenceException))]
  108. public void OpenFile1 ()
  109. {
  110. VirtualPathProvider.OpenFile ("index.aspx");
  111. }
  112. [Test]
  113. public void CombineVirtualPaths1 ()
  114. {
  115. DummyVPP dummy = new DummyVPP ();
  116. Assert.AreEqual ("/otherroot", dummy.CombineVirtualPaths ("/root", "/otherroot"));
  117. }
  118. [Test]
  119. public void CombineVirtualPaths2 ()
  120. {
  121. DummyVPP dummy = new DummyVPP ();
  122. Assert.AreEqual ("/otherleaf", dummy.CombineVirtualPaths ("/root", "otherleaf"));
  123. }
  124. [Test]
  125. public void CombineVirtualPaths3 ()
  126. {
  127. DummyVPP dummy = new DummyVPP ();
  128. Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "otherleaf/index.aspx"));
  129. }
  130. [Test]
  131. public void CombineVirtualPaths4 ()
  132. {
  133. DummyVPP dummy = new DummyVPP ();
  134. Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "./otherleaf/index.aspx"));
  135. }
  136. [Test]
  137. [ExpectedException (typeof (ArgumentException))]
  138. public void CombineVirtualPaths5 ()
  139. {
  140. DummyVPP dummy = new DummyVPP ();
  141. dummy.CombineVirtualPaths ("root", "./otherleaf/index.aspx");
  142. }
  143. }
  144. }
  145. #endif