|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved.
|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
| 4 | +using System; |
| 5 | +using System.Linq; |
4 | 6 | using System.Net;
|
5 | 7 | using System.Net.Http;
|
6 | 8 | using System.Net.Http.Headers;
|
7 | 9 | using System.Text.Encodings.Web;
|
8 | 10 | using System.Threading.Tasks;
|
| 11 | +using Microsoft.AspNetCore.Hosting; |
| 12 | +using Microsoft.Extensions.DependencyInjection; |
| 13 | +using Microsoft.Extensions.Logging; |
| 14 | +using Microsoft.Extensions.Logging.Testing; |
9 | 15 | using Xunit;
|
| 16 | +using Xunit.Abstractions; |
10 | 17 |
|
11 | 18 | namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
12 | 19 | {
|
13 | 20 | /// <summary>
|
14 | 21 | /// Functional test to verify the error reporting of Razor compilation by diagnostic middleware.
|
15 | 22 | /// </summary>
|
16 |
| - public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>> |
| 23 | + public class ErrorPageTests : IClassFixture<MvcTestFixture<ErrorPageMiddlewareWebSite.Startup>>, IDisposable |
17 | 24 | {
|
18 | 25 | private static readonly string PreserveCompilationContextMessage = HtmlEncoder.Default.Encode(
|
19 | 26 | "One or more compilation references may be missing. " +
|
20 | 27 | "If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.");
|
21 |
| - public ErrorPageTests(MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture) |
| 28 | + private readonly AssemblyTestLog _assemblyTestLog; |
| 29 | + |
| 30 | + public ErrorPageTests( |
| 31 | + MvcTestFixture<ErrorPageMiddlewareWebSite.Startup> fixture, |
| 32 | + ITestOutputHelper testOutputHelper) |
22 | 33 | {
|
23 |
| - Client = fixture.CreateDefaultClient(); |
| 34 | + _assemblyTestLog = AssemblyTestLog.ForAssembly(GetType().Assembly); |
| 35 | + |
| 36 | + var loggerProvider = _assemblyTestLog.CreateLoggerFactory(testOutputHelper, GetType().Name); |
| 37 | + |
| 38 | + var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup<ErrorPageMiddlewareWebSite.Startup>()); |
| 39 | + Client = factory |
| 40 | + .WithWebHostBuilder(builder => builder.ConfigureLogging(l => l.Services.AddSingleton<ILoggerFactory>(loggerProvider))) |
| 41 | + .CreateDefaultClient(); |
24 | 42 | }
|
25 | 43 |
|
26 | 44 | public HttpClient Client { get; }
|
@@ -143,5 +161,10 @@ public async Task AggregateException_FlattensInnerExceptions()
|
143 | 161 | Assert.Contains(nullReferenceException, content);
|
144 | 162 | Assert.Contains(indexOutOfRangeException, content);
|
145 | 163 | }
|
| 164 | + |
| 165 | + public void Dispose() |
| 166 | + { |
| 167 | + _assemblyTestLog.Dispose(); |
| 168 | + } |
146 | 169 | }
|
147 | 170 | }
|
0 commit comments