File tree Expand file tree Collapse file tree 4 files changed +29
-1
lines changed
test/System.Web.WebPages.Test/WebPage Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 216216 <data name =" WebPage_CannotRequestDirectly" xml : space =" preserve" >
217217 <value >The file "{0}" cannot be requested directly because it calls the "{1}" method.</value >
218218 </data >
219+ <data name =" WebPage_ExecutePageHierarchyCannotBeInvoked" xml : space =" preserve" >
220+ <value >ExecutePageHierarchy cannot be invoked if PageContext is null.</value >
221+ </data >
219222 <data name =" WebPage_FileNotSupported" xml : space =" preserve" >
220223 <value >The following file could not be rendered because its extension "{0}" might not be supported: "{1}".</value >
221224 </data >
Original file line number Diff line number Diff line change 22using System . Diagnostics . CodeAnalysis ;
33using System . Linq ;
44using System . Web . WebPages . Html ;
5+ using System . Web . WebPages . Resources ;
56using System . Web . WebPages . Scope ;
67
78namespace System . Web . WebPages
@@ -65,6 +66,11 @@ public static void RegisterPageExecutor(IWebPageRequestExecutor executor)
6566
6667 public override void ExecutePageHierarchy ( )
6768 {
69+ if ( PageContext == null )
70+ {
71+ // The ExecutePageHierarchy in WebPageBase assumes a non-null PageContext.
72+ throw new InvalidOperationException ( WebPageResources . WebPage_ExecutePageHierarchyCannotBeInvoked ) ;
73+ }
6874 using ( ScopeStorage . CreateTransientScope ( new ScopeStorageDictionary ( ScopeStorage . CurrentScope , PageData ) ) )
6975 {
7076 ExecutePageHierarchy ( _executors ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ public void CreatePageFromVirtualPathAssignsVirtualPathFactory()
3131 Assert . Equal ( page . VirtualPath , path ) ;
3232 }
3333
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+
3444 [ Fact ]
3545 public void NormalizeLayoutPagePathTest ( )
3646 {
You can’t perform that action at this time.
0 commit comments