Add AggregateExceptionTest (#6135)

Test for aspnet/Common#215
This commit is contained in:
Jass Bagga 2017-04-14 14:20:31 -07:00 committed by GitHub
parent d8a95c731b
commit 3eae7cc393
2 changed files with 51 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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");
}
}
}