Added a test to verify ReflectionTypeLoadException

This commit is contained in:
Ajay Bhargav Baaskaran 2016-07-21 21:09:25 -07:00
parent 49a48a0a33
commit 4600100695
2 changed files with 32 additions and 0 deletions

View File

@ -115,5 +115,23 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Contains("/Views/ErrorPageMiddleware/RuntimeError.cshtml", content);
Assert.Contains(expectedMessage, content);
}
[Fact]
public async Task LoaderExceptionsFromReflectionTypeLoadExceptionsAreListed()
{
// Arrange
var expectedMessage = "Custom Loader Exception.";
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
// Act
var response = await Client.GetAsync("http://localhost/LoaderException");
// Assert
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
var content = await response.Content.ReadAsStringAsync();
Assert.Contains("Loader Exceptions:", content);
Assert.Contains(expectedMessage, content);
}
}
}

View File

@ -1,6 +1,8 @@
// 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.Reflection;
using Microsoft.AspNetCore.Mvc;
namespace ErrorPageMiddlewareWebSite
@ -27,5 +29,17 @@ namespace ErrorPageMiddlewareWebSite
[HttpGet("/RuntimeError")]
public IActionResult RuntimeError() => View();
[HttpGet("/LoaderException")]
public IActionResult ReflectionTypeLoadException()
{
throw new ReflectionTypeLoadException(
new[] { typeof(SomeType) },
new[] { new TypeLoadException("Custom Loader Exception.") });
}
private class SomeType
{
}
}
}