Merge remote-tracking branch 'origin/release/2.2'
This commit is contained in:
commit
b8ff40fbbd
|
|
@ -258,8 +258,14 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
|
||||||
if (childContent == null)
|
if (childContent == null)
|
||||||
{
|
{
|
||||||
_startTagHelperWritingScope(null);
|
_startTagHelperWritingScope(null);
|
||||||
await _executeChildContentAsync();
|
try
|
||||||
childContent = _endTagHelperWritingScope();
|
{
|
||||||
|
await _executeChildContentAsync();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
childContent = _endTagHelperWritingScope();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Assert(!Output.IsContentModified);
|
Debug.Assert(!Output.IsContentModified);
|
||||||
|
|
@ -292,8 +298,14 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
|
||||||
if (!useCachedResult || childContent == null)
|
if (!useCachedResult || childContent == null)
|
||||||
{
|
{
|
||||||
_startTagHelperWritingScope(encoder);
|
_startTagHelperWritingScope(encoder);
|
||||||
await _executeChildContentAsync();
|
try
|
||||||
childContent = _endTagHelperWritingScope();
|
{
|
||||||
|
await _executeChildContentAsync();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
childContent = _endTagHelperWritingScope();
|
||||||
|
}
|
||||||
|
|
||||||
if (encoder == null)
|
if (encoder == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,53 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
|
||||||
{
|
{
|
||||||
public class TagHelperExecutionContextTest
|
public class TagHelperExecutionContextTest
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task SetOutputContentAsync_CanHandleExceptionThrowingChildContent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var calledEnd = false;
|
||||||
|
var executionContext = new TagHelperExecutionContext(
|
||||||
|
"p",
|
||||||
|
tagMode: TagMode.StartTagAndEndTag,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => throw new Exception(),
|
||||||
|
startTagHelperWritingScope: _ => { },
|
||||||
|
endTagHelperWritingScope: () =>
|
||||||
|
{
|
||||||
|
calledEnd = true;
|
||||||
|
return new DefaultTagHelperContent();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
await Assert.ThrowsAsync<Exception>(async () => await executionContext.SetOutputContentAsync());
|
||||||
|
Assert.True(calledEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetChildContentAsync_CanHandleExceptionThrowingChildContent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var calledEnd = false;
|
||||||
|
var executionContext = new TagHelperExecutionContext(
|
||||||
|
"p",
|
||||||
|
tagMode: TagMode.StartTagAndEndTag,
|
||||||
|
items: new Dictionary<object, object>(),
|
||||||
|
uniqueId: string.Empty,
|
||||||
|
executeChildContentAsync: () => throw new Exception(),
|
||||||
|
startTagHelperWritingScope: _ => { },
|
||||||
|
endTagHelperWritingScope: () =>
|
||||||
|
{
|
||||||
|
calledEnd = true;
|
||||||
|
return new DefaultTagHelperContent();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
await Assert.ThrowsAsync<Exception>(
|
||||||
|
async () => await executionContext.GetChildContentAsync(useCachedResult: false, encoder: null));
|
||||||
|
Assert.True(calledEnd);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SetOutputContentAsync_SetsOutputsContent()
|
public async Task SetOutputContentAsync_SetsOutputsContent()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue