Skip to content

Add some additional logging to ErrorPageMiddlewareWebSite #8049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Functional test to verify the error reporting of Razor compilation by diagnostic middleware.
/// </summary>
public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>
public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>, 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<ErrorPageMiddlewareWebSite.Startup> fixture)
private readonly AssemblyTestLog _assemblyTestLog;

public ErrorPageTests(
MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> 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<ErrorPageMiddlewareWebSite.Startup>());
Client = factory
.WithWebHostBuilder(builder => builder.ConfigureLogging(l => l.Services.AddSingleton<ILoggerFactory>(loggerProvider)))
.CreateDefaultClient();
}

public HttpClient Client { get; }
Expand Down Expand Up @@ -144,5 +161,10 @@ public async void AggregateException_FlattensInnerExceptions()
Assert.Contains(nullReferenceException, content);
Assert.Contains(indexOutOfRangeException, content);
}

public void Dispose()
{
_assemblyTestLog.Dispose();
}
}
}