diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ErrorPageTests.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ErrorPageTests.cs index 8e302a7d84..94784a2134 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ErrorPageTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ErrorPageTests.cs @@ -136,5 +136,23 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests Assert.Contains("Loader Exceptions:", content); Assert.Contains(expectedMessage, content); } + + [Fact] + public async void AggregateException_FlattensInnerExceptions() + { + // Arrange + var aggregateException = "AggregateException: One or more errors occurred."; + var nullReferenceException = "NullReferenceException: Foo cannot be null"; + var indexOutOfRangeException = "IndexOutOfRangeException: Index is out of range"; + + // Act + var response = await Client.GetAsync("http://localhost/AggregateException"); + var content = await response.Content.ReadAsStringAsync(); + + // Assert + Assert.Contains(aggregateException, content); + Assert.Contains(nullReferenceException, content); + Assert.Contains(indexOutOfRangeException, content); + } } } \ No newline at end of file diff --git a/test/WebSites/ErrorPageMiddlewareWebSite/AggregateExceptionController.cs b/test/WebSites/ErrorPageMiddlewareWebSite/AggregateExceptionController.cs new file mode 100644 index 0000000000..b648318cb0 --- /dev/null +++ b/test/WebSites/ErrorPageMiddlewareWebSite/AggregateExceptionController.cs @@ -0,0 +1,33 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace ErrorPageMiddlewareWebSite +{ + public class AggregateExceptionController : Controller + { + [HttpGet("/AggregateException")] + public IActionResult Index() + { + var firstException = ThrowNullReferenceException(); + var secondException = ThrowIndexOutOfRangeException(); + Task.WaitAll(firstException, secondException); + return View(); + } + + private static async Task ThrowNullReferenceException() + { + await Task.Delay(0); + throw new NullReferenceException("Foo cannot be null"); + } + + private static async Task ThrowIndexOutOfRangeException() + { + await Task.Delay(0); + throw new IndexOutOfRangeException("Index is out of range"); + } + } +}