public async Task RenderSectionAsync_ThrowsIfNotInvokedFromLayoutPage() { // Arrange var expected = new HelperResult(NullAsyncWrite); var page = CreatePage(async v => { v.Path = "/Views/TestPath/Test.cshtml"; await v.RenderSectionAsync("header"); }); // Act & Assert var ex = await Assert.ThrowsAsync<InvalidOperationException>(page.ExecuteAsync); Assert.Equal( "RenderSectionAsync invocation in '/Views/TestPath/Test.cshtml' is invalid. " + "RenderSectionAsync can only be called from a layout page.", ex.Message); }
public async Task RenderSectionAsync_ThrowsIfSectionIsRenderedMoreThanOnce_WithSyncMethod() { // Arrange var expected = new HelperResult(NullAsyncWrite); var page = CreatePage(async v => { v.Path = "/Views/TestPath/Test.cshtml"; v.RenderSection("header"); await v.RenderSectionAsync("header"); }); page.PreviousSectionWriters = new Dictionary<string, RenderAsyncDelegate> { { "header", _nullRenderAsyncDelegate } }; // Act & Assert var ex = await Assert.ThrowsAsync<InvalidOperationException>(page.ExecuteAsync); Assert.Equal( "RenderSectionAsync invocation in '/Views/TestPath/Test.cshtml' is invalid." + " The section 'header' has already been rendered.", ex.Message); }