72 lines
3.4 KiB
C#
72 lines
3.4 KiB
C#
// 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.Net;
|
|
using System.Net.Http.Headers;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using ErrorPageMiddlewareWebSite;
|
|
using Microsoft.AspNet.Builder;
|
|
using Microsoft.Framework.DependencyInjection;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|
{
|
|
/// <summary>
|
|
/// Functional test to verify the error reporting of Razor compilation by diagnostic middleware.
|
|
/// </summary>
|
|
public class ErrorPageTests
|
|
{
|
|
private const string SiteName = nameof(ErrorPageMiddlewareWebSite);
|
|
private readonly Action<IApplicationBuilder> _app = new Startup().Configure;
|
|
private readonly Action<IServiceCollection> _configureServices = new Startup().ConfigureServices;
|
|
|
|
private readonly Assembly _resourcesAssembly = typeof(ErrorPageTests).GetTypeInfo().Assembly;
|
|
|
|
[Theory]
|
|
[InlineData("CompilationFailure", "Cannot implicitly convert type 'int' to 'string'")]
|
|
[InlineData("ParserError", "The code block is missing a closing "}" character. Make sure you " +
|
|
"have a matching "}" character for all the "{" characters " +
|
|
"within this block, and that none of the "}" characters are being " +
|
|
"interpreted as markup.")]
|
|
public async Task CompilationFailuresAreListedByErrorPageMiddleware(string action, string expected)
|
|
{
|
|
// Arrange
|
|
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
|
|
var client = server.CreateClient();
|
|
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html");
|
|
|
|
// Act
|
|
var response = await client.GetAsync("http://localhost/" + action);
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
|
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
Assert.Contains($"/Views/ErrorPageMiddleware/{action}.cshtml", content);
|
|
Assert.Contains(expected, content);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CompilationFailuresFromGlobalImportAreListed()
|
|
{
|
|
// Arrange
|
|
var expectedMessage = "The type or namespace name 'NamespaceDoesNotExist' could not be found ("
|
|
+ "are you missing a using directive or an assembly reference?)";
|
|
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
|
|
var client = server.CreateClient();
|
|
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html");
|
|
|
|
// Act
|
|
var response = await client.GetAsync("http://localhost/ErrorFromGlobalImport");
|
|
|
|
// Assert
|
|
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
|
|
Assert.Equal(expectedMediaType, response.Content.Headers.ContentType);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
Assert.Contains(@"Views\ErrorFromGlobalImport\_GlobalImport.cshtml", content);
|
|
Assert.Contains(expectedMessage, content);
|
|
}
|
|
}
|
|
} |