From 1ca6202e7e39b11103f48272c37b91f9ccee5d21 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 1 Mar 2019 10:49:54 -0800 Subject: [PATCH] Add some additional logging to ErrorPageMiddlewareWebSite (#8049) * Add some additional logging to ErrorPageMiddlewareWebSite DeveloperExceptionMiddleware will log an error if rendering the exception page throws. The test failure in https://github.com/aspnet/AspNetCore-Internal/issues/1730 suggests that we encountered an error like so but do not have anything further to go by. This change adds logging to the test so we could identify possible issues --- .../Mvc.FunctionalTests/ErrorPageTests.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs index 644a4ac067..ec976ac0dc 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs @@ -1,27 +1,44 @@ // 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.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text.Encodings.Web; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; using Xunit; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests { /// /// Functional test to verify the error reporting of Razor compilation by diagnostic middleware. /// - public class ErrorPageTests : IClassFixture> + public class ErrorPageTests : IClassFixture>, IDisposable { private static readonly string PreserveCompilationContextMessage = HtmlEncoder.Default.Encode( "One or more compilation references are missing. Ensure that your project is referencing " + "'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false."); - public ErrorPageTests(MvcTestFixture fixture) + private readonly AssemblyTestLog _assemblyTestLog; + + public ErrorPageTests( + MvcTestFixture fixture, + ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + _assemblyTestLog = AssemblyTestLog.ForAssembly(GetType().Assembly); + + var loggerProvider = _assemblyTestLog.CreateLoggerFactory(testOutputHelper, GetType().Name); + + var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); + Client = factory + .WithWebHostBuilder(builder => builder.ConfigureLogging(l => l.Services.AddSingleton(loggerProvider))) + .CreateDefaultClient(); } public HttpClient Client { get; } @@ -144,5 +161,10 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests Assert.Contains(nullReferenceException, content); Assert.Contains(indexOutOfRangeException, content); } + + public void Dispose() + { + _assemblyTestLog.Dispose(); + } } }