OutputCacheProvider.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // Authors:
  3. // Marek Habersack ([email protected])
  4. //
  5. // (C) 2010 Novell, Inc http://novell.com/
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. #if NET_4_0
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Configuration;
  31. using System.Configuration.Provider;
  32. using System.IO;
  33. using System.Web;
  34. using System.Web.Hosting;
  35. using StandAloneRunnerSupport;
  36. using StandAloneTests;
  37. using NUnit.Framework;
  38. namespace StandAloneTests.OutputCacheProvider
  39. {
  40. [TestCase ("OutputCacheProvider 01", "OutputCacheProvider - custom provider test")]
  41. public sealed class OutputCacheProvider_01 : ITestCase
  42. {
  43. public string PhysicalPath {
  44. get {
  45. return Path.Combine (
  46. Consts.BasePhysicalDir,
  47. Path.Combine ("OutputCacheProvider", "OutputCacheProviderTest_01")
  48. );
  49. }
  50. }
  51. public string VirtualPath {
  52. get { return "/"; }
  53. }
  54. public bool SetUp (List <TestRunItem> runItems)
  55. {
  56. runItems.Add (new TestRunItem ("/Default.aspx", Default_Aspx));
  57. return true;
  58. }
  59. void Default_Aspx (string result, TestRunItem runItem)
  60. {
  61. string originalHtml = @"<pre id=""output"">Default provider name: TestInMemoryProvider
  62. Null context: TestInMemoryProvider
  63. Default context: TestInMemoryProvider
  64. </pre>";
  65. Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
  66. }
  67. }
  68. [TestCase ("OutputCacheProvider 02", "OutputCacheProvider - missing provider test")]
  69. public sealed class OutputCacheProvider_02 : ITestCase
  70. {
  71. public string PhysicalPath {
  72. get {
  73. return Path.Combine (
  74. Consts.BasePhysicalDir,
  75. Path.Combine ("OutputCacheProvider", "OutputCacheProviderTest_02")
  76. );
  77. }
  78. }
  79. public string VirtualPath {
  80. get { return "/"; }
  81. }
  82. public bool SetUp (List <TestRunItem> runItems)
  83. {
  84. runItems.Add (new TestRunItem ("/Default.aspx", Default_Aspx));
  85. return true;
  86. }
  87. void Default_Aspx (string result, TestRunItem runItem)
  88. {
  89. Assert.IsTrue (Helpers.HasException (result, typeof (ConfigurationErrorsException)), "#A1");
  90. }
  91. }
  92. [TestCase ("OutputCacheProvider 03", "OutputCacheProvider - per request provider test")]
  93. public sealed class OutputCacheProvider_03 : ITestCase
  94. {
  95. public string PhysicalPath {
  96. get {
  97. return Path.Combine (
  98. Consts.BasePhysicalDir,
  99. Path.Combine ("OutputCacheProvider", "OutputCacheProviderTest_03")
  100. );
  101. }
  102. }
  103. public string VirtualPath {
  104. get { return "/"; }
  105. }
  106. public bool SetUp (List <TestRunItem> runItems)
  107. {
  108. runItems.Add (new TestRunItem ("/Default.aspx", Default_Aspx));
  109. runItems.Add (new TestRunItem ("/Default.aspx?ocp=InMemory", Default_InMemory_Aspx));
  110. runItems.Add (new TestRunItem ("/Default.aspx?ocp=AnotherInMemory", Default_AnotherInMemory_Aspx));
  111. runItems.Add (new TestRunItem ("/Default.aspx?ocp=invalid", Default_Invalid_Aspx));
  112. return true;
  113. }
  114. void Default_Aspx (string result, TestRunItem runItem)
  115. {
  116. string originalHtml = @"<pre id=""output"">Default provider name: AspNetInternalProvider
  117. Default context: AspNetInternalProvider
  118. </pre>";
  119. Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
  120. }
  121. void Default_InMemory_Aspx (string result, TestRunItem runItem)
  122. {
  123. string originalHtml = @"<pre id=""output"">Default provider name: AspNetInternalProvider
  124. Default context: TestInMemoryProvider
  125. </pre>";
  126. Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
  127. }
  128. void Default_AnotherInMemory_Aspx (string result, TestRunItem runItem)
  129. {
  130. string originalHtml = @"<pre id=""output"">Default provider name: AspNetInternalProvider
  131. Default context: TestAnotherInMemoryProvider
  132. </pre>";
  133. Helpers.ExtractAndCompareCodeFromHtml (result, originalHtml, "#A1");
  134. }
  135. void Default_Invalid_Aspx (string result, TestRunItem runItem)
  136. {
  137. Assert.IsTrue (Helpers.HasException (result, typeof (ProviderException)), "#A1");
  138. }
  139. }
  140. }
  141. #endif