Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

257966: Parameterless overload of WebPage::ExecutePageHierarchy throws

when called.
  • Loading branch information...
commit a565f101ffe8d28a415668cad7f558585efc0cc6 1 parent 5391de5
Pranav K pranavkm authored
11 src/System.Web.WebPages/Resources/WebPageResources.Designer.cs
@@ -349,6 +349,15 @@ internal class WebPageResources {
349 349 }
350 350
351 351 /// <summary>
  352 + /// Looks up a localized string similar to ExecutePageHierarchy cannot be invoked if PageContext is null..
  353 + /// </summary>
  354 + internal static string WebPage_ExecutePageHierarchyCannotBeInvoked {
  355 + get {
  356 + return ResourceManager.GetString("WebPage_ExecutePageHierarchyCannotBeInvoked", resourceCulture);
  357 + }
  358 + }
  359 +
  360 + /// <summary>
352 361 /// Looks up a localized string similar to The following file could not be rendered because its extension &quot;{0}&quot; might not be supported: &quot;{1}&quot;..
353 362 /// </summary>
354 363 internal static string WebPage_FileNotSupported {
@@ -438,4 +447,4 @@ internal class WebPageResources {
438 447 }
439 448 }
440 449 }
441   -}
  450 +}
3  src/System.Web.WebPages/Resources/WebPageResources.resx
@@ -216,6 +216,9 @@
216 216 <data name="WebPage_CannotRequestDirectly" xml:space="preserve">
217 217 <value>The file "{0}" cannot be requested directly because it calls the "{1}" method.</value>
218 218 </data>
  219 + <data name="WebPage_ExecutePageHierarchyCannotBeInvoked" xml:space="preserve">
  220 + <value>ExecutePageHierarchy cannot be invoked if PageContext is null.</value>
  221 + </data>
219 222 <data name="WebPage_FileNotSupported" xml:space="preserve">
220 223 <value>The following file could not be rendered because its extension "{0}" might not be supported: "{1}".</value>
221 224 </data>
6 src/System.Web.WebPages/WebPage.cs
@@ -2,6 +2,7 @@
2 2 using System.Diagnostics.CodeAnalysis;
3 3 using System.Linq;
4 4 using System.Web.WebPages.Html;
  5 +using System.Web.WebPages.Resources;
5 6 using System.Web.WebPages.Scope;
6 7
7 8 namespace System.Web.WebPages
@@ -65,6 +66,11 @@ public static void RegisterPageExecutor(IWebPageRequestExecutor executor)
65 66
66 67 public override void ExecutePageHierarchy()
67 68 {
  69 + if (PageContext == null)
  70 + {
  71 + // The ExecutePageHierarchy in WebPageBase assumes a non-null PageContext.
  72 + throw new InvalidOperationException(WebPageResources.WebPage_ExecutePageHierarchyCannotBeInvoked);
  73 + }
68 74 using (ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData)))
69 75 {
70 76 ExecutePageHierarchy(_executors);
10 test/System.Web.WebPages.Test/WebPage/WebPageTest.cs
@@ -32,6 +32,16 @@ public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
32 32 }
33 33
34 34 [Fact]
  35 + public void ExecutePageHierarchyThrowsIfPageContextIsNotSet()
  36 + {
  37 + // Arrange
  38 + var page = new Mock<WebPage>() { CallBase = true };
  39 +
  40 + // Act and Assert
  41 + Assert.Throws<InvalidOperationException>(() => page.Object.ExecutePageHierarchy(), "ExecutePageHierarchy cannot be invoked if PageContext is null.");
  42 + }
  43 +
  44 + [Fact]
35 45 public void NormalizeLayoutPagePathTest()
36 46 {
37 47 var layoutPage = "Layout.cshtml";

0 comments on commit a565f10

Please sign in to comment.
Something went wrong with that request. Please try again.