Permalink
Browse files

257966: Parameterless overload of WebPage::ExecutePageHierarchy throws

when called.
  • Loading branch information...
pranavkm committed Apr 5, 2012
1 parent 5391de5 commit a565f101ffe8d28a415668cad7f558585efc0cc6

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -216,6 +216,9 @@
<data name="WebPage_CannotRequestDirectly" xml:space="preserve">
<value>The file "{0}" cannot be requested directly because it calls the "{1}" method.</value>
</data>
+ <data name="WebPage_ExecutePageHierarchyCannotBeInvoked" xml:space="preserve">
+ <value>ExecutePageHierarchy cannot be invoked if PageContext is null.</value>
+ </data>
<data name="WebPage_FileNotSupported" xml:space="preserve">
<value>The following file could not be rendered because its extension "{0}" might not be supported: "{1}".</value>
</data>
@@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Web.WebPages.Html;
+using System.Web.WebPages.Resources;
using System.Web.WebPages.Scope;
namespace System.Web.WebPages
@@ -65,6 +66,11 @@ public static void RegisterPageExecutor(IWebPageRequestExecutor executor)
public override void ExecutePageHierarchy()
{
+ if (PageContext == null)
+ {
+ // The ExecutePageHierarchy in WebPageBase assumes a non-null PageContext.
+ throw new InvalidOperationException(WebPageResources.WebPage_ExecutePageHierarchyCannotBeInvoked);
+ }
using (ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData)))
{
ExecutePageHierarchy(_executors);
@@ -31,6 +31,16 @@ public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
Assert.Equal(page.VirtualPath, path);
}
+ [Fact]
+ public void ExecutePageHierarchyThrowsIfPageContextIsNotSet()
+ {
+ // Arrange
+ var page = new Mock<WebPage>() { CallBase = true };
+
+ // Act and Assert
+ Assert.Throws<InvalidOperationException>(() => page.Object.ExecutePageHierarchy(), "ExecutePageHierarchy cannot be invoked if PageContext is null.");
+ }
+
[Fact]
public void NormalizeLayoutPagePathTest()
{

0 comments on commit a565f10

Please sign in to comment.