diff --git a/src/Mvc/Mvc.slnf b/src/Mvc/Mvc.slnf index 1ca37ea7f216..61da89ec072d 100644 --- a/src/Mvc/Mvc.slnf +++ b/src/Mvc/Mvc.slnf @@ -28,6 +28,7 @@ "src\\Http\\Authentication.Core\\src\\Microsoft.AspNetCore.Authentication.Core.csproj", "src\\Http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", "src\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj", + "src\\Http\\Http.Extensions\\gen\\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj", "src\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj", "src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", "src\\Http\\Http.Results\\src\\Microsoft.AspNetCore.Http.Results.csproj", @@ -35,8 +36,8 @@ "src\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", "src\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", "src\\Http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj", - "src\\Http\\samples\\MinimalSample\\MinimalSample.csproj", "src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", + "src\\Http\\samples\\MinimalSample\\MinimalSample.csproj", "src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj", "src\\Localization\\Abstractions\\src\\Microsoft.Extensions.Localization.Abstractions.csproj", "src\\Localization\\Localization\\src\\Microsoft.Extensions.Localization.csproj", diff --git a/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryAuthTests.cs b/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryAuthTests.cs index 6b4b2d603d5d..311e2288b276 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryAuthTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryAuthTests.cs @@ -1,20 +1,32 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; using SecurityWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AntiforgeryAuthTests : IClassFixture> +public class AntiforgeryAuthTests : LoggedTest { - public AntiforgeryAuthTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AutomaticAuthenticationBeforeAntiforgery() diff --git a/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryTests.cs b/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryTests.cs index 904b2739c3b5..375f65d2aa73 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AntiforgeryTests.cs @@ -3,17 +3,29 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AntiforgeryTests : IClassFixture> +public class AntiforgeryTests : LoggedTest { - public AntiforgeryTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task MultipleAFTokensWithinTheSamePage_GeneratesASingleCookieToken() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ApiBehaviorTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ApiBehaviorTest.cs index 9b895e88b10d..5a1959b1d772 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ApiBehaviorTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ApiBehaviorTest.cs @@ -4,28 +4,40 @@ using System; using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using BasicWebSite.Models; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.NewtonsoftJson; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class ApiBehaviorTestBase : IClassFixture> where TStartup : class +public abstract class ApiBehaviorTestBase : LoggedTest where TStartup : class { - protected ApiBehaviorTestBase(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public virtual async Task ActionsReturnBadRequest_WhenModelStateIsInvalid() @@ -374,11 +386,6 @@ public virtual async Task SerializingValidationProblemDetails_WithExtensionData( public class ApiBehaviorTest : ApiBehaviorTestBase { - public ApiBehaviorTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override Task ActionsReturnBadRequest_WhenModelStateIsInvalid() { @@ -412,21 +419,16 @@ public override Task SerializingValidationProblemDetails_WithExtensionData() public class ApiBehaviorTestNewtonsoftJson : ApiBehaviorTestBase { - public ApiBehaviorTestNewtonsoftJson(MvcTestFixture fixture) - : base(fixture) - { - var factory = fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - CustomInvalidModelStateClient = factory.CreateDefaultClient(); - } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient CustomInvalidModelStateClient { get; } - [Fact] public async Task ActionsReturnBadRequest_UsesProblemDescriptionProviderAndApiConventionsToConfigureErrorResponse() { + await using var factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(ConfigureWebHostBuilder); + var customInvalidModelStateClient = factory.CreateDefaultClient(); + // Arrange var contactModel = new Contact { @@ -442,7 +444,7 @@ public async Task ActionsReturnBadRequest_UsesProblemDescriptionProviderAndApiCo }; // Act - var response = await CustomInvalidModelStateClient.PostAsJsonAsync("/contact/PostWithVnd", contactModel); + var response = await customInvalidModelStateClient.PostAsJsonAsync("/contact/PostWithVnd", contactModel); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.BadRequest); diff --git a/src/Mvc/test/Mvc.FunctionalTests/ApiExplorerTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ApiExplorerTest.cs index 574311cd3952..0ed76f604947 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ApiExplorerTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ApiExplorerTest.cs @@ -8,17 +8,29 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json; +using Microsoft.Extensions.Logging; +using System.Reflection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ApiExplorerTest : IClassFixture> +public class ApiExplorerTest : LoggedTest { - public ApiExplorerTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ApiExplorer_IsVisible_EnabledWithConvention() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ApplicationModelTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ApplicationModelTest.cs index 43314fc6faf1..ce20aa109936 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ApplicationModelTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ApplicationModelTest.cs @@ -3,17 +3,29 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ApplicationModelTest : IClassFixture> +public class ApplicationModelTest : LoggedTest { - public ApplicationModelTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ControllerModel_CustomizedWithAttribute() diff --git a/src/Mvc/test/Mvc.FunctionalTests/AsyncActionsTests.cs b/src/Mvc/test/Mvc.FunctionalTests/AsyncActionsTests.cs index 5845927598fa..b7e3f265ba41 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AsyncActionsTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AsyncActionsTests.cs @@ -1,19 +1,31 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AsyncActionsTests : IClassFixture> +public class AsyncActionsTests : LoggedTest { - public AsyncActionsTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AsyncVoidAction_ReturnsOK() diff --git a/src/Mvc/test/Mvc.FunctionalTests/AsyncDisposalTest.cs b/src/Mvc/test/Mvc.FunctionalTests/AsyncDisposalTest.cs index 6277d64486dc..c3de7f0ab28e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AsyncDisposalTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AsyncDisposalTest.cs @@ -3,28 +3,39 @@ using System.Net; using System.Net.Http; +using System.Reflection; using BasicWebSite.Controllers; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AsyncDisposalTest : IClassFixture> +public class AsyncDisposalTest : LoggedTest { - public AsyncDisposalTest(MvcTestFixture fixture) + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); Client = Factory.CreateDefaultClient(); } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup() .ConfigureServices(s => s.AddSingleton()); - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } - public HttpClient Client { get; } + public HttpClient Client { get; private set; } [Fact] public async Task CanDisposeAsyncController() diff --git a/src/Mvc/test/Mvc.FunctionalTests/AsyncEnumerableTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/AsyncEnumerableTestBase.cs index 7ec9d831c5d5..dbb0534e11ba 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AsyncEnumerableTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AsyncEnumerableTestBase.cs @@ -3,20 +3,32 @@ using System.Net; using System.Net.Http; +using System.Reflection; using System.Text.Json; using System.Xml.Linq; using FormatterWebSite; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AsyncEnumerableTestBase : IClassFixture> +public class AsyncEnumerableTestBase : LoggedTest { - public AsyncEnumerableTestBase(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public Task AsyncEnumerableReturnedWorks() => AsyncEnumerableWorks("getallprojects"); diff --git a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTest.cs index f21644ebc1e5..2aad065cd1df 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTest.cs @@ -5,8 +5,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class AuthMiddlewareAndFilterTest : AuthMiddlewareAndFilterTestBase { - public AuthMiddlewareAndFilterTest(MvcTestFixture fixture) - : base(fixture) - { - } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTestBase.cs index 8cc1cd699a77..c5bc988f48d0 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterTestBase.cs @@ -4,21 +4,33 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class AuthMiddlewareAndFilterTestBase : IClassFixture> where TStartup : class +public abstract class AuthMiddlewareAndFilterTestBase : LoggedTest where TStartup : class { - protected AuthMiddlewareAndFilterTestBase(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AllowAnonymousOnActionsWork() diff --git a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterWithoutEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterWithoutEndpointRoutingTest.cs index 845bbc30e797..171c0c563b29 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterWithoutEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareAndFilterWithoutEndpointRoutingTest.cs @@ -5,8 +5,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class AuthMiddlewareAndFilterWithoutEndpointRoutingTest : AuthMiddlewareAndFilterTestBase { - public AuthMiddlewareAndFilterWithoutEndpointRoutingTest(MvcTestFixture fixture) - : base(fixture) - { - } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareUsingRequireAuthTest.cs b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareUsingRequireAuthTest.cs index f7b71ad5654e..a0cca07d73f9 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareUsingRequireAuthTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/AuthMiddlewareUsingRequireAuthTest.cs @@ -1,24 +1,36 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class AuthMiddlewareUsingRequireAuthTest : IClassFixture> +public class AuthMiddlewareUsingRequireAuthTest : LoggedTest { - public AuthMiddlewareUsingRequireAuthTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task RequireAuthConfiguredGlobally_AppliesToControllers() diff --git a/src/Mvc/test/Mvc.FunctionalTests/BasicTests.cs b/src/Mvc/test/Mvc.FunctionalTests/BasicTests.cs index 9f5af3bf3486..3e278208a28a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/BasicTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/BasicTests.cs @@ -9,10 +9,12 @@ using System.Reflection; using System.Text.Json; using BasicWebSite.Models; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class BasicTests : IClassFixture> +public class BasicTests : LoggedTest { // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -20,12 +22,21 @@ public class BasicTests : IClassFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CanRender_CSharp7Views() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ClientValidationOptionsTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ClientValidationOptionsTests.cs index 1d101e27eb13..96663a73cf1f 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ClientValidationOptionsTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ClientValidationOptionsTests.cs @@ -1,24 +1,35 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ClientValidationOptionsTests : IClassFixture> +public class ClientValidationOptionsTests : LoggedTest { - public ClientValidationOptionsTests(MvcTestFixture fixture) => - Fixture = fixture; + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public MvcTestFixture Fixture { get; } + public MvcTestFixture Factory { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/55926")] [Fact] public async Task DisablingClientValidation_DisablesItForPagesAndViews() { // Arrange - var client = Fixture + var client = Factory .WithWebHostBuilder(whb => whb.UseStartup()) .CreateClient(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/CompilationOptionsTests.cs b/src/Mvc/test/Mvc.FunctionalTests/CompilationOptionsTests.cs index cd081fb52062..3584233b6bb2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/CompilationOptionsTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/CompilationOptionsTests.cs @@ -2,19 +2,31 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; // Test to verify compilation options from the application are used to compile // precompiled and dynamically compiled views. -public class CompilationOptionsTests : IClassFixture> +public class CompilationOptionsTests : LoggedTest { - public CompilationOptionsTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CompilationOptions_AreUsedByViewsAndPartials() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ComponentRenderingFunctionalTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ComponentRenderingFunctionalTests.cs index 181f67db3af7..21acf9a563a7 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ComponentRenderingFunctionalTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ComponentRenderingFunctionalTests.cs @@ -3,23 +3,32 @@ using System.Net; using System.Net.Http; +using System.Reflection; using AngleSharp.Parser.Html; using BasicWebSite; using BasicWebSite.Services; using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ComponentRenderingFunctionalTests : IClassFixture> +public class ComponentRenderingFunctionalTests : LoggedTest { - public ComponentRenderingFunctionalTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture; + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); } - public MvcTestFixture Factory { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } [Fact] public async Task Renders_BasicComponent() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeEndpointRoutingTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeEndpointRoutingTests.cs index ee1e7fc3f810..6201834b99d3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeEndpointRoutingTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeEndpointRoutingTests.cs @@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class ConsumesAttributeEndpointRoutingTests : ConsumesAttributeTestsBase { - public ConsumesAttributeEndpointRoutingTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTests.cs index f6664623e29c..59f895feb1a0 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTests.cs @@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class ConsumesAttributeTests : ConsumesAttributeTestsBase { - public ConsumesAttributeTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTestsBase.cs index 79e8c37c0451..9e7bed9259b3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ConsumesAttributeTestsBase.cs @@ -3,26 +3,39 @@ using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using BasicWebSite.Models; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class ConsumesAttributeTestsBase : IClassFixture> where TStartup : class +public abstract class ConsumesAttributeTestsBase : LoggedTest where TStartup : class { - protected ConsumesAttributeTestsBase(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public abstract Task HasEndpointMatch(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/ContentNegotiationTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ContentNegotiationTest.cs index 0b4e5e8722c3..b2caac2b812d 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ContentNegotiationTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ContentNegotiationTest.cs @@ -10,17 +10,29 @@ using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json; +using Microsoft.Extensions.Logging; +using System.Reflection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ContentNegotiationTest : IClassFixture> +public class ContentNegotiationTest : LoggedTest { - public ContentNegotiationTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ProducesAttribute_SingleContentType_PicksTheFirstSupportedFormatter() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ControllerEndpointFiltersTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ControllerEndpointFiltersTest.cs index 64a6d255274c..5fb2f304f6a2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ControllerEndpointFiltersTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ControllerEndpointFiltersTest.cs @@ -4,25 +4,34 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using System.Text.Json; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ControllerEndpointFiltersTest : IClassFixture> +public class ControllerEndpointFiltersTest : LoggedTest { - public ControllerEndpointFiltersTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/55929")] [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/ControllerFromServicesTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ControllerFromServicesTests.cs index 0c41e6d05309..47f7715b0d50 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ControllerFromServicesTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ControllerFromServicesTests.cs @@ -3,17 +3,29 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ControllerFromServicesTest : IClassFixture> +public class ControllerFromServicesTest : LoggedTest { - public ControllerFromServicesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ControllersWithConstructorInjectionAreCreatedAndActivated() diff --git a/src/Mvc/test/Mvc.FunctionalTests/CorsEndpointRoutingTests.cs b/src/Mvc/test/Mvc.FunctionalTests/CorsEndpointRoutingTests.cs index acf56c146068..93f64494a796 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/CorsEndpointRoutingTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/CorsEndpointRoutingTests.cs @@ -5,8 +5,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class CorsEndpointRoutingTests : CorsTestsBase { - public CorsEndpointRoutingTests(MvcTestFixture fixture) - : base(fixture) - { - } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/CorsTests.cs b/src/Mvc/test/Mvc.FunctionalTests/CorsTests.cs index 86ed5169b54c..127edfa589e3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/CorsTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/CorsTests.cs @@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class CorsTests : CorsTestsBase { - public CorsTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task PreflightRequestOnNonCorsEnabledController_DoesNotMatchTheAction() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/CorsTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/CorsTestsBase.cs index 99fda0edb64d..fb603ebafaa1 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/CorsTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/CorsTestsBase.cs @@ -3,23 +3,35 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class CorsTestsBase : IClassFixture> where TStartup : class +public abstract class CorsTestsBase : LoggedTest where TStartup : class { - protected CorsTestsBase(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("GET")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/CustomValueProviderTest.cs b/src/Mvc/test/Mvc.FunctionalTests/CustomValueProviderTest.cs index c4fd51c23a6b..9c32a3e8f416 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/CustomValueProviderTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/CustomValueProviderTest.cs @@ -3,25 +3,37 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class CustomValueProviderTest : IClassFixture> +public class CustomValueProviderTest : LoggedTest { private IServiceCollection _serviceCollection; - public CustomValueProviderTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.UseStartup()) + .WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)); + Client = Factory.CreateDefaultClient(); + } - Client = factory.CreateDefaultClient(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CustomValueProvider_DisplayName() diff --git a/src/Mvc/test/Mvc.FunctionalTests/DataAnnotationTests.cs b/src/Mvc/test/Mvc.FunctionalTests/DataAnnotationTests.cs index 7f62af79673e..12f716d88e2b 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/DataAnnotationTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/DataAnnotationTests.cs @@ -1,26 +1,39 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using RazorWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class DataAnnotationTests : IClassFixture> +public class DataAnnotationTests : LoggedTest { - private HttpClient Client { get; set; } + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(builder => + { + builder.UseStartup(); + }); + Client = Factory.CreateDefaultClient(); + } - public DataAnnotationTests(MvcTestFixture fixture) + public override void Dispose() { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => - { - builder.UseStartup(); - }); - Client = factory.CreateDefaultClient(); + Factory.Dispose(); + base.Dispose(); } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } + private const string EnumUrl = "http://localhost/Enum/Enum"; [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs index b528c6a4c151..d6d33d15628a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class DefaultValuesTest : IClassFixture> +public class DefaultValuesTest : LoggedTest { - public DefaultValuesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Controller_WithDefaultValueAttribute_ReturnsDefault() diff --git a/src/Mvc/test/Mvc.FunctionalTests/DirectivesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/DirectivesTest.cs index e8e34ffddd41..3aa287a6976e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/DirectivesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/DirectivesTest.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class DirectivesTest : IClassFixture> +public class DirectivesTest : LoggedTest { - public DirectivesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ViewsInheritsUsingsAndInjectDirectivesFromViewStarts() diff --git a/src/Mvc/test/Mvc.FunctionalTests/DoNotRespectBrowserAcceptHeaderTests.cs b/src/Mvc/test/Mvc.FunctionalTests/DoNotRespectBrowserAcceptHeaderTests.cs index 8c09f1609117..07c47d51f76e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/DoNotRespectBrowserAcceptHeaderTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/DoNotRespectBrowserAcceptHeaderTests.cs @@ -6,20 +6,34 @@ using System.Text; using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; +using RazorWebSite; +using System.Reflection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; /// /// These tests are for scenarios when is False, which is the default. /// -public class DoNotRespectBrowserAcceptHeaderTests : IClassFixture> +public class DoNotRespectBrowserAcceptHeaderTests : LoggedTest { - public DoNotRespectBrowserAcceptHeaderTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("application/xml,*/*;q=0.2")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs index 0cad3e140d24..fd6c9f793e0a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ErrorPageTests.cs @@ -12,46 +12,44 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Xunit.Abstractions; +using System.Reflection; +using Microsoft.AspNetCore.Mvc.Testing; 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 : LoggedTest { private static readonly string PreserveCompilationContextMessage = HtmlEncoder.Default.Encode( "One or more compilation references may be missing. " + "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."); - private readonly AssemblyTestLog _assemblyTestLog; - private readonly MvcTestFixture _fixture; - - public ErrorPageTests( - MvcTestFixture fixture, - ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - _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(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.UseStartup()); + Client = Factory.CreateDefaultClient(); // These tests want to verify runtime compilation and formatting in the HTML of the error page Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); + } - _fixture = fixture; + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CompilationFailuresAreListedByErrorPageMiddleware() { // Arrange - var factory = _fixture.Factories.FirstOrDefault() ?? _fixture.WithWebHostBuilder(b => b.UseStartup()); + var factory = Factory.WithWebHostBuilder(b => b.UseStartup()); factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => serviceCollection.Configure(ConfigureRuntimeCompilationOptions))); var client = factory.CreateDefaultClient(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/FileResultTests.cs b/src/Mvc/test/Mvc.FunctionalTests/FileResultTests.cs index fc2901040e27..b23887892ae5 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/FileResultTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/FileResultTests.cs @@ -4,18 +4,31 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class FileResultTests : IClassFixture> +public class FileResultTests : LoggedTest { - public FileResultTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [ConditionalFact] // https://github.com/aspnet/Mvc/issues/2727 diff --git a/src/Mvc/test/Mvc.FunctionalTests/FiltersTest.cs b/src/Mvc/test/Mvc.FunctionalTests/FiltersTest.cs index ce5ee283df23..82ad4689d50f 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/FiltersTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/FiltersTest.cs @@ -3,19 +3,31 @@ using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class FiltersTest : IClassFixture> +public class FiltersTest : LoggedTest { - public FiltersTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); Client.DefaultRequestHeaders.Add("Authorization", "Bearer key"); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CanAuthorize_UsersByRole() diff --git a/src/Mvc/test/Mvc.FunctionalTests/FlushPointTest.cs b/src/Mvc/test/Mvc.FunctionalTests/FlushPointTest.cs index dce076bf744c..aec2a4ebed23 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/FlushPointTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/FlushPointTest.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class FlushPointTest : IClassFixture> +public class FlushPointTest : LoggedTest { - public FlushPointTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task FlushPointsAreExecutedForPagesWithLayouts() diff --git a/src/Mvc/test/Mvc.FunctionalTests/FormFileUploadTest.cs b/src/Mvc/test/Mvc.FunctionalTests/FormFileUploadTest.cs index a9824f4e5a8d..b6e9a70cb1bf 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/FormFileUploadTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/FormFileUploadTest.cs @@ -3,17 +3,29 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class FormFileUploadTest : IClassFixture> +public class FormFileUploadTest : LoggedTest { - public FormFileUploadTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CanUploadFileInFrom() diff --git a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterEndpointRoutingTest.cs index 733e4958c39c..a4f9f1036096 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterEndpointRoutingTest.cs @@ -6,16 +6,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class GlobalAuthorizationFilterEndpointRoutingTest : GlobalAuthorizationFilterTestBase, IClassFixture> +public class GlobalAuthorizationFilterEndpointRoutingTest : GlobalAuthorizationFilterTestBase { - public GlobalAuthorizationFilterEndpointRoutingTest(MvcTestFixture fixture) - { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = Factory.CreateDefaultClient(); - } - - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + public override void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - - public WebApplicationFactory Factory { get; } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterTestBase.cs index 3fe710ef10f1..4bc5a93fc712 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterTestBase.cs @@ -3,12 +3,33 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class GlobalAuthorizationFilterTestBase : IClassFixture> +public abstract class GlobalAuthorizationFilterTestBase : LoggedTest where TStartup : class { - public HttpClient Client { get; protected set; } + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } + + public virtual void ConfigureWebHostBuilder(IWebHostBuilder builder) { } [Fact] public virtual async Task DeniesAnonymousUsers_ByDefault() diff --git a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterUseMvcTest.cs b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterUseMvcTest.cs index e0aa75d67bd7..a7800689d56e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterUseMvcTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/GlobalAuthorizationFilterUseMvcTest.cs @@ -6,16 +6,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class GlobalAuthorizationFilterUseMvcTest : GlobalAuthorizationFilterTestBase, IClassFixture> +public class GlobalAuthorizationFilterUseMvcTest : GlobalAuthorizationFilterTestBase { - public GlobalAuthorizationFilterUseMvcTest(MvcTestFixture fixture) - { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = Factory.CreateDefaultClient(); - } - - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + public override void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - - public WebApplicationFactory Factory { get; } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationTest.cs b/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationTest.cs index a071f5309919..6e78f6e0a518 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationTest.cs @@ -10,34 +10,39 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class HtmlGenerationTest : - IClassFixture>, - IClassFixture> +public class HtmlGenerationTest : LoggedTest { private static readonly Assembly _resourcesAssembly = typeof(HtmlGenerationTest).GetTypeInfo().Assembly; - public HtmlGenerationTest( - MvcTestFixture fixture, - MvcEncodedTestFixture encodedFixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + EncodedFactory = new MvcEncodedTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + EncodedClient = EncodedFactory.CreateDefaultClient(); + } - Client = fixture.CreateDefaultClient(); - EncodedClient = encodedFixture.CreateDefaultClient(); + public override void Dispose() + { + Factory.Dispose(); + EncodedFactory.Dispose(); + base.Dispose(); } + public WebApplicationFactory Factory { get; private set; } + public WebApplicationFactory EncodedFactory { get; private set; } + public HttpClient Client { get; private set; } + public HttpClient EncodedClient { get; private set; } + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); - public HttpClient Client { get; } - - public HttpClient EncodedClient { get; } - - public WebApplicationFactory Factory { get; } - public static TheoryData WebPagesData { get diff --git a/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationWithCultureTest.cs b/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationWithCultureTest.cs index 8cef176a1549..c6cdf91ee2d9 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationWithCultureTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/HtmlGenerationWithCultureTest.cs @@ -14,22 +14,29 @@ using Microsoft.Extensions.DependencyInjection; using Xunit.Abstractions; using Xunit.Sdk; +using Microsoft.AspNetCore.Builder; +using System.Reflection; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class HtmlGenerationWithCultureTest : LoggedTest, IClassFixture> +public class HtmlGenerationWithCultureTest : LoggedTest { - public HtmlGenerationWithCultureTest( - ITestOutputHelper testOutputHelper, - MvcTestFixture fixture) : base(testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.WithWebHostBuilder(builder => builder.UseStartup()); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(builder => builder.UseStartup()); Client = Factory.CreateDefaultClient(); } - public WebApplicationFactory Factory { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/4907")] [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/HtmlHelperOptionsTest.cs b/src/Mvc/test/Mvc.FunctionalTests/HtmlHelperOptionsTest.cs index c7fa70a4a1a0..6bd04c8f9eb6 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/HtmlHelperOptionsTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/HtmlHelperOptionsTest.cs @@ -2,18 +2,32 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using Microsoft.AspNetCore.Builder; +using System.Reflection; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class HtmlHelperOptionsTest : IClassFixture> +public class HtmlHelperOptionsTest : LoggedTest { - public HtmlHelperOptionsTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AppWideDefaultsInViewAndPartialView() diff --git a/src/Mvc/test/Mvc.FunctionalTests/HttpActionResultTests.cs b/src/Mvc/test/Mvc.FunctionalTests/HttpActionResultTests.cs index 4314dd4060d5..a0b5563aa332 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/HttpActionResultTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/HttpActionResultTests.cs @@ -4,18 +4,30 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using BasicWebSite.Models; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class HttpActionResultTests : IClassFixture> +public class HttpActionResultTests : LoggedTest { - public HttpActionResultTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ActionCanReturnIResultWithContent() diff --git a/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcEncodedTestFixtureOfT.cs b/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcEncodedTestFixtureOfT.cs index 3247b47ae832..5f9a0054bf4e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcEncodedTestFixtureOfT.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcEncodedTestFixtureOfT.cs @@ -4,13 +4,17 @@ using System.Text.Encodings.Web; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.WebEncoders.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class MvcEncodedTestFixture : MvcTestFixture where TStartup : class { + public MvcEncodedTestFixture(ILoggerFactory outputHelper) : base(outputHelper) { } + protected override void ConfigureWebHost(IWebHostBuilder builder) { base.ConfigureWebHost(builder); diff --git a/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs b/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs index 5ded03158a7c..45c33dad7268 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs @@ -15,16 +15,28 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class MvcTestFixture : WebApplicationFactory where TStartup : class { + private ILoggerFactory _loggerFactory; + + public MvcTestFixture(ILoggerFactory loggerFactory) + { + _loggerFactory = loggerFactory; + } + protected override void ConfigureWebHost(IWebHostBuilder builder) { + ILoggerFactory loggerFactory = _loggerFactory; + var testSink = new TestSink(); + if (_loggerFactory is null) + { + loggerFactory = new TestLoggerFactory(testSink, enabled: true); + } + builder .UseRequestCulture("en-GB", "en-US") .UseEnvironment("Production") .ConfigureServices( services => { - var testSink = new TestSink(); - var loggerFactory = new TestLoggerFactory(testSink, enabled: true); services.AddSingleton(loggerFactory); services.AddSingleton(testSink); }); diff --git a/src/Mvc/test/Mvc.FunctionalTests/InputFormatterTests.cs b/src/Mvc/test/Mvc.FunctionalTests/InputFormatterTests.cs index bc40e1afa013..f6ec536880f1 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/InputFormatterTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/InputFormatterTests.cs @@ -5,22 +5,34 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using System.Text; using FormatterWebSite.Controllers; using FormatterWebSite.Models; +using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class InputFormatterTests : IClassFixture> +public class InputFormatterTests : LoggedTest { - public InputFormatterTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CheckIfXmlInputFormatterIsBeingCalled() diff --git a/src/Mvc/test/Mvc.FunctionalTests/InputObjectValidationTests.cs b/src/Mvc/test/Mvc.FunctionalTests/InputObjectValidationTests.cs index 13cda556bd14..aceacceb3060 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/InputObjectValidationTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/InputObjectValidationTests.cs @@ -3,22 +3,36 @@ using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using FormatterWebSite; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class InputObjectValidationTests : IClassFixture> +public class InputObjectValidationTests : LoggedTest { - public InputObjectValidationTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } // Parameters: Request Content, Expected status code, Expected model state error message public static IEnumerable SimpleTypePropertiesModelRequestData diff --git a/src/Mvc/test/Mvc.FunctionalTests/InputParentValidationTests.cs b/src/Mvc/test/Mvc.FunctionalTests/InputParentValidationTests.cs index d11f9856ad3e..b44e280cf152 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/InputParentValidationTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/InputParentValidationTests.cs @@ -2,11 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; using System.Text; using FormatterWebSite.Models; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; @@ -15,20 +19,26 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; /// public class InputParentValidationTests { - public abstract class BaseTests : IClassFixture> + public abstract class BaseTests : LoggedTest where TStartup : class { - protected BaseTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => - builder.UseStartup()); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(builder => builder.UseStartup()); + Client = Factory.CreateDefaultClient(); + } - Client = factory.CreateDefaultClient(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - protected abstract bool ShouldParentBeValidatedWhenChildIsInvalid { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } - private HttpClient Client { get; } + protected abstract bool ShouldParentBeValidatedWhenChildIsInvalid { get; } [Fact] public async Task ParentObjectValidation_RespectsMvcOptions_WhenChildIsInvalid() @@ -102,11 +112,6 @@ private IDictionary GetExpectedErrors(bool parentInvalid, bool /// public class ParentValidationScenarios : BaseTests { - public ParentValidationScenarios(MvcTestFixture fixture) - : base(fixture) - { - } - protected override bool ShouldParentBeValidatedWhenChildIsInvalid => true; } @@ -116,11 +121,6 @@ public ParentValidationScenarios(MvcTestFixture public class ParentNonValidationScenarios : BaseTests { - public ParentNonValidationScenarios(MvcTestFixture fixture) - : base(fixture) - { - } - protected override bool ShouldParentBeValidatedWhenChildIsInvalid => false; } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/InputValidationTests.cs b/src/Mvc/test/Mvc.FunctionalTests/InputValidationTests.cs index 380bc7ef4e74..a46ae079f788 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/InputValidationTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/InputValidationTests.cs @@ -1,21 +1,33 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class InputValidationTests : IClassFixture> +public class InputValidationTests : LoggedTest { - public InputValidationTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ValidRequest_IsAccepted() diff --git a/src/Mvc/test/Mvc.FunctionalTests/JsonInputFormatterTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/JsonInputFormatterTestBase.cs index e4ae77d43048..47292a453ef2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/JsonInputFormatterTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/JsonInputFormatterTestBase.cs @@ -5,24 +5,36 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using System.Text; using FormatterWebSite.Controllers; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class JsonInputFormatterTestBase : IClassFixture> where TStartup : class +public abstract class JsonInputFormatterTestBase : LoggedTest where TStartup : class { - protected JsonInputFormatterTestBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("application/json")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/JsonOutputFormatterTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/JsonOutputFormatterTestBase.cs index 2cb2a5b490d4..218bf5633d0a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/JsonOutputFormatterTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/JsonOutputFormatterTestBase.cs @@ -1,31 +1,41 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Text; using FormatterWebSite.Controllers; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class JsonOutputFormatterTestBase : IClassFixture> where TStartup : class +public abstract class JsonOutputFormatterTestBase : LoggedTest where TStartup : class { - protected JsonOutputFormatterTestBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public virtual async Task SerializableErrorIsReturnedInExpectedFormat() diff --git a/src/Mvc/test/Mvc.FunctionalTests/JsonPatchInputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/JsonPatchInputFormatterTest.cs index 572ad2902444..aed9ef7b838b 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/JsonPatchInputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/JsonPatchInputFormatterTest.cs @@ -1,22 +1,34 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using FormatterWebSite; +using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class JsonPatchSampleTest : IClassFixture> +public class JsonPatchSampleTest : LoggedTest { - public JsonPatchSampleTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AddOperation_Works() diff --git a/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithNewtonsoftJsonTest.cs b/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithNewtonsoftJsonTest.cs index 92fce9476146..a927c93d5f35 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithNewtonsoftJsonTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithNewtonsoftJsonTest.cs @@ -3,25 +3,37 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class JsonResultWithNewtonsoftJsonTest : IClassFixture> +public class JsonResultWithNewtonsoftJsonTest : LoggedTest { private IServiceCollection _serviceCollection; - public JsonResultWithNewtonsoftJsonTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)) + .WithWebHostBuilder(b => b.UseStartup()); + Client = Factory.CreateDefaultClient(); + } - Client = factory.CreateDefaultClient(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task JsonResult_UsesDefaultContentType() diff --git a/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithSystemTextJsonTest.cs b/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithSystemTextJsonTest.cs index 99fd8a61812a..4ea1bf228f61 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithSystemTextJsonTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/JsonResultWithSystemTextJsonTest.cs @@ -3,25 +3,37 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class JsonResultWithSystemTextJsonTest : IClassFixture> +public class JsonResultWithSystemTextJsonTest : LoggedTest { private IServiceCollection _serviceCollection; - public JsonResultWithSystemTextJsonTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)) + .WithWebHostBuilder(b => b.UseStartup()); + Client = Factory.CreateDefaultClient(); + } - Client = factory.CreateDefaultClient(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task JsonResult_UsesDefaultContentType() diff --git a/src/Mvc/test/Mvc.FunctionalTests/KeyedServicesTests.cs b/src/Mvc/test/Mvc.FunctionalTests/KeyedServicesTests.cs index 87f304163e7d..3cad946ba07d 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/KeyedServicesTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/KeyedServicesTests.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class KeyedServicesTests : IClassFixture> +public class KeyedServicesTests : LoggedTest { - public KeyedServicesTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ExplicitSingleFromKeyedServiceAttribute() diff --git a/src/Mvc/test/Mvc.FunctionalTests/LinkGenerationTests.cs b/src/Mvc/test/Mvc.FunctionalTests/LinkGenerationTests.cs index 5f1e96840156..52a6c68e1e91 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/LinkGenerationTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/LinkGenerationTests.cs @@ -5,11 +5,15 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class LinkGenerationTests : IClassFixture> +public class LinkGenerationTests : LoggedTest { // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -17,12 +21,21 @@ public class LinkGenerationTests : IClassFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } public static TheoryData RelativeLinksData { diff --git a/src/Mvc/test/Mvc.FunctionalTests/LinkGeneratorTest.cs b/src/Mvc/test/Mvc.FunctionalTests/LinkGeneratorTest.cs index a8b76a311a8d..cd5d7381c4ac 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/LinkGeneratorTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/LinkGeneratorTest.cs @@ -1,25 +1,38 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; // Functional tests for MVC's scenarios with LinkGenerator (2.2+ only) -public class LinkGeneratorTest : IClassFixture> +public class LinkGeneratorTest : LoggedTest { - public LinkGeneratorTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder) + .WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task GetPathByAction_CanGeneratePathToSelf() diff --git a/src/Mvc/test/Mvc.FunctionalTests/LinkParserTest.cs b/src/Mvc/test/Mvc.FunctionalTests/LinkParserTest.cs index aca7e51a6d89..73a9efa8dd04 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/LinkParserTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/LinkParserTest.cs @@ -1,26 +1,38 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json.Linq; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; // Functional tests for MVC's scenarios with LinkParser -public class LinkParserTest : IClassFixture> +public class LinkParserTest : LoggedTest { - public LinkParserTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ParsePathByEndpoint_CanParsedWithDefaultRoute() diff --git a/src/Mvc/test/Mvc.FunctionalTests/MvcSandboxTest.cs b/src/Mvc/test/Mvc.FunctionalTests/MvcSandboxTest.cs index d91faf0a618c..c118a944020f 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/MvcSandboxTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/MvcSandboxTest.cs @@ -3,17 +3,29 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class MvcSandboxTest : IClassFixture> +public class MvcSandboxTest : LoggedTest { - public MvcSandboxTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Home_Pages_ReturnSuccess() diff --git a/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonInputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonInputFormatterTest.cs index 9e8ed6e254d7..88b0b7548f6c 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonInputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonInputFormatterTest.cs @@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class NewtonsoftJsonInputFormatterTest : JsonInputFormatterTestBase { - public NewtonsoftJsonInputFormatterTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] // This test covers the 2.0 behavior. JSON.Net error messages are not preserved. public virtual async Task JsonInputFormatter_SuppliedJsonDeserializationErrorMessage() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonOutputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonOutputFormatterTest.cs index f8931ee5b957..a32599fc3759 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonOutputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/NewtonsoftJsonOutputFormatterTest.cs @@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class NewtonsoftJsonOutputFormatterTest : JsonOutputFormatterTestBase { - public NewtonsoftJsonOutputFormatterTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public async Task JsonOutputFormatter_ReturnsIndentedJson() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/NonNullableReferenceTypesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/NonNullableReferenceTypesTest.cs index f17a6b163acc..cec22f3d78f2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/NonNullableReferenceTypesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/NonNullableReferenceTypesTest.cs @@ -3,18 +3,30 @@ using System.Net; using System.Net.Http; +using System.Reflection; using AngleSharp.Parser.Html; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class NonNullableReferenceTypesTest : IClassFixture> +public class NonNullableReferenceTypesTest : LoggedTest { - public NonNullableReferenceTypesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - private HttpClient Client { get; set; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CanUseNonNullableReferenceType_WithController_OmitData_ValidationErrors() diff --git a/src/Mvc/test/Mvc.FunctionalTests/OutputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/OutputFormatterTest.cs index 29a5667d5ab7..2741e929f74d 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/OutputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/OutputFormatterTest.cs @@ -4,17 +4,29 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class OutputFormatterTest : IClassFixture> +public class OutputFormatterTest : LoggedTest { - public OutputFormatterTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("ReturnTaskOfString")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/PageAsyncDisposalTest.cs b/src/Mvc/test/Mvc.FunctionalTests/PageAsyncDisposalTest.cs index a2a5f880044e..1813be613c39 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/PageAsyncDisposalTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/PageAsyncDisposalTest.cs @@ -3,28 +3,37 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using RazorPagesWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class PageAsyncDisposalTest : IClassFixture> +public class PageAsyncDisposalTest : LoggedTest { - public PageAsyncDisposalTest(MvcTestFixture fixture) - { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = Factory.CreateDefaultClient(); - } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup() .ConfigureServices(s => s.AddSingleton()); - public WebApplicationFactory Factory { get; } + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CanDisposeAsyncPage() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorBuildTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorBuildTest.cs index ce32e882979f..e3a7bfdb7fe5 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorBuildTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorBuildTest.cs @@ -3,21 +3,30 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorBuildTest : IClassFixture> +// These tests test razor caching which is affected if the site is built by another test class +// Use a named Collection to avoid the test classes running in parallel +[Collection("RazorBuildWebSite")] +public class RazorBuildTest : LoggedTest { - public RazorBuildTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => serviceCollection.Configure(ConfigureRuntimeCompilationOptions))); - - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.UseStartup()) + .WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => serviceCollection.Configure(ConfigureRuntimeCompilationOptions))); static void ConfigureRuntimeCompilationOptions(MvcRazorRuntimeCompilationOptions options) { @@ -28,9 +37,17 @@ static void ConfigureRuntimeCompilationOptions(MvcRazorRuntimeCompilationOptions options.AdditionalReferencePaths.Add(path); } } + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Rzc_LocalPageWithDifferentContent_IsUsed() @@ -83,6 +100,8 @@ public async Task RzcViewsArePreferredToRuntimeViews() } [Fact] + [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/56553")] + [LogLevel(LogLevel.Trace)] public async Task RazorViews_AreUpdatedOnChange() { // Arrange @@ -120,6 +139,8 @@ public async Task RazorViews_AreUpdatedOnChange() } [Fact] + [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/56553")] + [LogLevel(LogLevel.Trace)] public async Task RazorPages_AreUpdatedOnChange() { // Arrange diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPageModelTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPageModelTest.cs index 73af9d332d7d..48e03282e365 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPageModelTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPageModelTest.cs @@ -1,24 +1,36 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPageModelTest : IClassFixture> +public class RazorPageModelTest : LoggedTest { - public RazorPageModelTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Page_TryUpdateModelAsync_Success() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesNamespaceTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesNamespaceTest.cs index 2e7e87267dac..2032b050256e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesNamespaceTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesNamespaceTest.cs @@ -1,23 +1,35 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPagesNamespaceTest : IClassFixture> +public class RazorPagesNamespaceTest : LoggedTest { - public RazorPagesNamespaceTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Page_DefaultNamespace_IfUnset() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesTest.cs index 9d222476a383..8fbcec28f8c4 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesTest.cs @@ -10,23 +10,34 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.InternalTesting; using Newtonsoft.Json.Linq; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPagesTest : IClassFixture> +public class RazorPagesTest : LoggedTest { private static readonly Assembly _resourcesAssembly = typeof(RazorPagesTest).GetTypeInfo().Assembly; - public RazorPagesTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Page_SimpleForms_RenderAntiforgery() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesViewSearchTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesViewSearchTest.cs index d1a3c3d383bd..20218ab1712f 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesViewSearchTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesViewSearchTest.cs @@ -1,23 +1,35 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPagesViewSearchTest : IClassFixture> +public class RazorPagesViewSearchTest : LoggedTest { - public RazorPagesViewSearchTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Page_CanFindPartial_InCurrentDirectory() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithBasePathTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithBasePathTest.cs index 6248530b9baa..aa2228c5d22a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithBasePathTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithBasePathTest.cs @@ -1,20 +1,32 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Globalization; using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPagesWithBasePathTest : IClassFixture> +public class RazorPagesWithBasePathTest : LoggedTest { - public RazorPagesWithBasePathTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task PageOutsideBasePath_IsNotRouteable() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithEndpointRoutingTest.cs index cff46de7852c..dd491175cad2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorPagesWithEndpointRoutingTest.cs @@ -1,19 +1,31 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorPagesWithEndpointRoutingTest : IClassFixture> +public class RazorPagesWithEndpointRoutingTest : LoggedTest { - public RazorPagesWithEndpointRoutingTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Authorize_AppliedUsingConvention_Works() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorRuntimeCompilationHostingStartupTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorRuntimeCompilationHostingStartupTest.cs index 3961eea10b53..8d2fa13ea0e1 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorRuntimeCompilationHostingStartupTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorRuntimeCompilationHostingStartupTest.cs @@ -2,21 +2,28 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorRuntimeCompilationHostingStartupTest : IClassFixture> +// These tests test razor caching which is affected if the site is built by another test class +// Use a named Collection to avoid the test classes running in parallel +[Collection("RazorBuildWebSite")] +public class RazorRuntimeCompilationHostingStartupTest : LoggedTest { - public RazorRuntimeCompilationHostingStartupTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => serviceCollection.Configure(ConfigureRuntimeCompilationOptions))); - - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory) + .WithWebHostBuilder(b => b.UseStartup()) + .WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => serviceCollection.Configure(ConfigureRuntimeCompilationOptions))); static void ConfigureRuntimeCompilationOptions(MvcRazorRuntimeCompilationOptions options) { @@ -27,9 +34,17 @@ static void ConfigureRuntimeCompilationOptions(MvcRazorRuntimeCompilationOptions options.AdditionalReferencePaths.Add(path); } } + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task RazorViews_CanBeServedAndUpdatedViaRuntimeCompilation() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs index 451e05e3a7a0..14fcbc034bf1 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RazorViewLocationSpecificationTest.cs @@ -3,19 +3,31 @@ using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RazorViewLocationSpecificationTest : IClassFixture> +public class RazorViewLocationSpecificationTest : LoggedTest { private const string BaseUrl = "http://localhost/ViewNameSpecification_Home/"; - public RazorViewLocationSpecificationTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("LayoutSpecifiedWithPartialPathInViewStart")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/ReadFromDisconnectedClientTest.cs b/src/Mvc/test/Mvc.FunctionalTests/ReadFromDisconnectedClientTest.cs index 36e5924de823..1c7dfc9163e8 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ReadFromDisconnectedClientTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ReadFromDisconnectedClientTest.cs @@ -4,24 +4,36 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; // These tests verify the behavior of MVC when responding to a client that simulates a disconnect. // See https://github.com/dotnet/aspnetcore/issues/13333 -public class ReadFromDisconnectedClientTest : IClassFixture> +public class ReadFromDisconnectedClientTest : LoggedTest { - public ReadFromDisconnectedClientTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ActionWithAntiforgery_Returns400_WhenReadingBodyThrows() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RemoteAttributeValidationTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RemoteAttributeValidationTest.cs index a80c4fdc7580..dcc59732bfdf 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RemoteAttributeValidationTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RemoteAttributeValidationTest.cs @@ -4,20 +4,31 @@ using System.Net; using System.Net.Http; using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RemoteAttributeValidationTest : IClassFixture> +public class RemoteAttributeValidationTest : LoggedTest { private static readonly Assembly _resourcesAssembly = typeof(RemoteAttributeValidationTest).GetTypeInfo().Assembly; - public RemoteAttributeValidationTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("Area1", "/Area1")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/RequestFormLimitsTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RequestFormLimitsTest.cs index 68896a3159ad..35bb229dd0e3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RequestFormLimitsTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RequestFormLimitsTest.cs @@ -3,22 +3,34 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RequestFormLimitsTest : IClassFixture> +public class RequestFormLimitsTest : LoggedTest { - public RequestFormLimitsTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task RequestFormLimitCheckHappens_WithAntiforgeryValidation() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesEndpointRoutingTest.cs index 7fd616c7f76f..b864db653fb7 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesEndpointRoutingTest.cs @@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RequestServicesEndpointRoutingTest : RequestServicesTestBase { - public RequestServicesEndpointRoutingTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTest.cs index 95bb5b847ca4..e6c7d94b9401 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTest.cs @@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RequestServicesTest : RequestServicesTestBase { - public RequestServicesTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTestBase.cs index 51dd3eee89e9..495d02e38870 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RequestServicesTestBase.cs @@ -3,25 +3,37 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Net.Http.Headers; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; // Each of these tests makes two requests, because we want each test to verify that the data is // PER-REQUEST and does not linger around to impact the next request. -public abstract class RequestServicesTestBase : IClassFixture> where TStartup : class +public abstract class RequestServicesTestBase : LoggedTest where TStartup : class { - protected RequestServicesTestBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public abstract Task HasEndpointMatch(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/RequestSizeLimitTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RequestSizeLimitTest.cs index 103273dad870..b39026f86675 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RequestSizeLimitTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RequestSizeLimitTest.cs @@ -1,25 +1,37 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RequestSizeLimitTest : IClassFixture> +public class RequestSizeLimitTest : LoggedTest { - public RequestSizeLimitTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task RequestSizeLimitCheckHappens_BeforeAntiforgeryTokenValidation() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs b/src/Mvc/test/Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs index 57d8b68fc6f3..5b5824f014a7 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RespectBrowserAcceptHeaderTests.cs @@ -1,27 +1,40 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using FormatterWebSite; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; /// /// These tests are for scenarios when is True(default is False). /// -public class RespectBrowserAcceptHeaderTests : IClassFixture> +public class RespectBrowserAcceptHeaderTests : LoggedTest { - public RespectBrowserAcceptHeaderTests(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ReturnStringFromAction_StringOutputFormatterDoesNotWriteTheResponse() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingAcrossPipelineBranchesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingAcrossPipelineBranchesTest.cs index 1c24d644df6a..127975092ed6 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingAcrossPipelineBranchesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingAcrossPipelineBranchesTest.cs @@ -4,23 +4,34 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingAcrossPipelineBranchesTests : IClassFixture> +public class RoutingAcrossPipelineBranchesTests : LoggedTest { - public RoutingAcrossPipelineBranchesTests(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/55933")] [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicOrderTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicOrderTest.cs index e6d40aa8c314..52b61ee7e1c3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicOrderTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicOrderTest.cs @@ -4,23 +4,32 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; +using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingDynamicOrderTest : IClassFixture> +public class RoutingDynamicOrderTest : LoggedTest { - public RoutingDynamicOrderTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } [Fact] public async Task PrefersAttributeRoutesOverDynamicControllerRoutes() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicTest.cs index 2903f93dc807..64d388dc4ae8 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingDynamicTest.cs @@ -3,24 +3,34 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingDynamicTest : IClassFixture> +public class RoutingDynamicTest : LoggedTest { - public RoutingDynamicTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task DynamicController_CanGet404ForMissingAction() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs index ed6bc854db55..5d44ded05a72 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs @@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RoutingEndpointRoutingTest : RoutingTestsBase { - public RoutingEndpointRoutingTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public async Task AttributeRoutedAction_ContainsPage_RouteMatched() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingWithoutRazorPagesTests.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingWithoutRazorPagesTests.cs index 22b91f183322..9a140a6aba68 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingWithoutRazorPagesTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingWithoutRazorPagesTests.cs @@ -5,8 +5,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RoutingEndpointRoutingWithoutRazorPagesTests : RoutingWithoutRazorPagesTestsBase { - public RoutingEndpointRoutingWithoutRazorPagesTests(MvcTestFixture fixture) - : base(fixture) - { - } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingFallbackTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingFallbackTest.cs index 17150746f341..64946603c62b 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingFallbackTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingFallbackTest.cs @@ -3,24 +3,35 @@ using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingFallbackTest : IClassFixture> +public class RoutingFallbackTest : LoggedTest { - public RoutingFallbackTest(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task Fallback_CanGet404ForMissingFile() diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs index 77cbbbc5d427..01176a8fa630 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsTest.cs @@ -4,25 +4,35 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; -using System.Text.Json; +using System.Reflection; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingGroupsTests : IClassFixture> +public class RoutingGroupsTests : LoggedTest { - public RoutingGroupsTests(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/55931")] [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsWithMetadataTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsWithMetadataTest.cs index 86a8596113ef..30788a036f4c 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsWithMetadataTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingGroupsWithMetadataTest.cs @@ -3,24 +3,33 @@ using System.Net; using System.Net.Http.Json; +using System.Reflection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using RoutingWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class RoutingGroupsWithMetadataTests : IClassFixture> +public class RoutingGroupsWithMetadataTests : LoggedTest { - public RoutingGroupsWithMetadataTests(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public WebApplicationFactory Factory { get; } + public WebApplicationFactory Factory { get; private set; } [QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/55927")] [Fact] diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingTests.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingTests.cs index 8b2bd1a77870..635af1d3866a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingTests.cs @@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RoutingTests : RoutingTestsBase { - public RoutingTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs index 9b50c6e3485a..f67c67f52aa4 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingTestsBase.cs @@ -3,23 +3,35 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class RoutingTestsBase : IClassFixture> where TStartup : class +public abstract class RoutingTestsBase : LoggedTest where TStartup : class { - protected RoutingTestsBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("http://localhost/Login/Index", "Login", "Index", "http://localhost/Login")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTests.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTests.cs index 5c07c980e49c..e1526b460ea0 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTests.cs @@ -5,8 +5,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class RoutingWithoutRazorPagesTests : RoutingWithoutRazorPagesTestsBase { - public RoutingWithoutRazorPagesTests(MvcTestFixture fixture) - : base(fixture) - { - } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTestsBase.cs index aa53e8b2014a..7f31453447fd 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingWithoutRazorPagesTestsBase.cs @@ -3,23 +3,35 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class RoutingWithoutRazorPagesTestsBase : IClassFixture> where TStartup : class +public abstract class RoutingWithoutRazorPagesTestsBase : LoggedTest where TStartup : class { - protected RoutingWithoutRazorPagesTestsBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task AttributeRoutedAction_ContainsPage_RouteMatched() diff --git a/src/Mvc/test/Mvc.FunctionalTests/SerializableErrorTests.cs b/src/Mvc/test/Mvc.FunctionalTests/SerializableErrorTests.cs index c283f0c86e45..4231ce8828da 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SerializableErrorTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SerializableErrorTests.cs @@ -4,19 +4,31 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Text; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Formatters.Xml; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class SerializableErrorTests : IClassFixture> +public class SerializableErrorTests : LoggedTest { - public SerializableErrorTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } public static TheoryData AcceptHeadersData { diff --git a/src/Mvc/test/Mvc.FunctionalTests/SimpleTests.cs b/src/Mvc/test/Mvc.FunctionalTests/SimpleTests.cs index 1f2addaf1ffa..d848b1c836f6 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SimpleTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SimpleTests.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class SimpleTests : IClassFixture> +public class SimpleTests : LoggedTest { - public SimpleTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task JsonSerializeFormatted() diff --git a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs index 6ffc8bcf31af..7af2ed72a884 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs @@ -1,21 +1,32 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; + namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class SimpleWithWebApplicationBuilderExceptionTests : IClassFixture> +public class SimpleWithWebApplicationBuilderExceptionTests : LoggedTest { - private readonly MvcTestFixture _fixture; + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + } - public SimpleWithWebApplicationBuilderExceptionTests(MvcTestFixture fixture) + public override void Dispose() { - _fixture = fixture; + Factory.Dispose(); + base.Dispose(); } + public MvcTestFixture Factory { get; private set; } + [Fact] public void ExceptionThrownFromApplicationCanBeObserved() { - var ex = Assert.Throws(() => _fixture.CreateClient()); + var ex = Assert.Throws(() => Factory.CreateClient()); Assert.Equal("This application failed to start", ex.Message); } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs index 62450dae7e96..bc179c812b0e 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderTests.cs @@ -4,38 +4,46 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class SimpleWithWebApplicationBuilderTests : IClassFixture> +public class SimpleWithWebApplicationBuilderTests : LoggedTest { - private readonly MvcTestFixture _fixture; + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); + } - public SimpleWithWebApplicationBuilderTests(MvcTestFixture fixture) + public override void Dispose() { - _fixture = fixture; - Client = _fixture.CreateDefaultClient(); + Factory.Dispose(); + base.Dispose(); } - public HttpClient Client { get; } + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task HelloWorld() { // Arrange var expected = "Hello World"; - using var client = _fixture.CreateDefaultClient(); // Act - var content = await client.GetStringAsync("http://localhost/"); + var content = await Client.GetStringAsync("http://localhost/"); // Assert Assert.Equal(expected, content); @@ -46,10 +54,9 @@ public async Task JsonResult_Works() { // Arrange var expected = "{\"name\":\"John\",\"age\":42}"; - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/json"); + var response = await Client.GetAsync("/json"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.OK); @@ -62,10 +69,9 @@ public async Task OkObjectResult_Works() { // Arrange var expected = "{\"name\":\"John\",\"age\":42}"; - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/ok-object"); + var response = await Client.GetAsync("/ok-object"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.OK); @@ -78,10 +84,9 @@ public async Task AcceptedObjectResult_Works() { // Arrange var expected = "{\"name\":\"John\",\"age\":42}"; - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/accepted-object"); + var response = await Client.GetAsync("/accepted-object"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.Accepted); @@ -94,10 +99,9 @@ public async Task AcceptedObjectResult_Works() public async Task ActionReturningMoreThanOneResult_NotFound() { // Arrange - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/many-results?id=-1"); + var response = await Client.GetAsync("/many-results?id=-1"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.NotFound); @@ -107,10 +111,9 @@ public async Task ActionReturningMoreThanOneResult_NotFound() public async Task ActionReturningMoreThanOneResult_Found() { // Arrange - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/many-results?id=7"); + var response = await Client.GetAsync("/many-results?id=7"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.MovedPermanently); @@ -121,10 +124,9 @@ public async Task ActionReturningMoreThanOneResult_Found() public async Task MvcControllerActionWorks() { // Arrange - using var client = _fixture.CreateDefaultClient(); // Act - var response = await client.GetAsync("/greet"); + var response = await Client.GetAsync("/greet"); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.OK); @@ -150,7 +152,7 @@ public async Task DefaultEnvironment_Is_Development() public async Task Configuration_Can_Be_Overridden() { // Arrange - var fixture = _fixture.WithWebHostBuilder(builder => + var fixture = Factory.WithWebHostBuilder(builder => { builder.ConfigureAppConfiguration(builder => { @@ -177,7 +179,7 @@ public async Task Configuration_Can_Be_Overridden() public async Task Environment_Can_Be_Overridden() { // Arrange - var fixture = _fixture.WithWebHostBuilder(builder => + var fixture = Factory.WithWebHostBuilder(builder => { builder.UseEnvironment(Environments.Staging); }); @@ -198,7 +200,7 @@ public async Task WebRoot_Can_Be_Overriden() var webRoot = "foo"; var expectedWebRoot = ""; // Arrange - var fixture = _fixture.WithWebHostBuilder(builder => + var fixture = Factory.WithWebHostBuilder(builder => { expectedWebRoot = Path.GetFullPath(Path.Combine(builder.GetSetting(WebHostDefaults.ContentRootKey), webRoot)); builder.UseSetting(WebHostDefaults.WebRootKey, webRoot); @@ -261,15 +263,14 @@ public async Task FileUpload_Works_WithAntiforgeryToken() var content = new MultipartFormDataContent(); content.Add(new StringContent(new string('a', 42)), "file", "file.txt"); - using var client = _fixture.CreateDefaultClient(); - var antiforgery = _fixture.Services.GetRequiredService(); - var antiforgeryOptions = _fixture.Services.GetRequiredService>(); + var antiforgery = Factory.Services.GetRequiredService(); + var antiforgeryOptions = Factory.Services.GetRequiredService>(); var tokens = antiforgery.GetAndStoreTokens(new DefaultHttpContext()); - client.DefaultRequestHeaders.Add("Cookie", new CookieHeaderValue(antiforgeryOptions.Value.Cookie.Name, tokens.CookieToken).ToString()); - client.DefaultRequestHeaders.Add(tokens.HeaderName, tokens.RequestToken); + Client.DefaultRequestHeaders.Add("Cookie", new CookieHeaderValue(antiforgeryOptions.Value.Cookie.Name, tokens.CookieToken).ToString()); + Client.DefaultRequestHeaders.Add(tokens.HeaderName, tokens.RequestToken); // Act - var response = await client.PostAsync("/fileupload", content); + var response = await Client.PostAsync("/fileupload", content); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.OK); @@ -284,10 +285,8 @@ public async Task FileUpload_Fails_WithoutAntiforgeryToken() var content = new MultipartFormDataContent(); content.Add(new StringContent(new string('a', 42)), "file", "file.txt"); - using var client = _fixture.CreateDefaultClient(); - // Act - var response = await client.PostAsync("/fileupload", content); + var response = await Client.PostAsync("/fileupload", content); // Assert await response.AssertStatusCodeAsync(HttpStatusCode.BadRequest); diff --git a/src/Mvc/test/Mvc.FunctionalTests/StreamOutputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/StreamOutputFormatterTest.cs index e29c965a66f2..733f90527283 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/StreamOutputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/StreamOutputFormatterTest.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class StreamOutputFormatterTest : IClassFixture> +public class StreamOutputFormatterTest : LoggedTest { - public StreamOutputFormatterTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("SimpleMemoryStream", null)] diff --git a/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.cs index cb89037bf131..2db7a9a8fe09 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonInputFormatterTest.cs @@ -5,11 +5,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class SystemTextJsonInputFormatterTest : JsonInputFormatterTestBase { - public SystemTextJsonInputFormatterTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact(Skip = "https://github.com/dotnet/runtime/issues/38539")] public override Task JsonInputFormatter_RoundtripsRecordType() => base.JsonInputFormatter_RoundtripsRecordType(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.cs index 2067351335cd..df54ab0d8cd9 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SystemTextJsonOutputFormatterTest.cs @@ -10,11 +10,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class SystemTextJsonOutputFormatterTest : JsonOutputFormatterTestBase { - public SystemTextJsonOutputFormatterTest(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override Task SerializableErrorIsReturnedInExpectedFormat() => base.SerializableErrorIsReturnedInExpectedFormat(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/TagHelperComponentTagHelperTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TagHelperComponentTagHelperTest.cs index f76045e6f925..b68fa3d9e995 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TagHelperComponentTagHelperTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TagHelperComponentTagHelperTest.cs @@ -4,19 +4,30 @@ using System.Net; using System.Net.Http; using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TagHelperComponentTagHelperTest : IClassFixture> +public class TagHelperComponentTagHelperTest : LoggedTest { private static readonly Assembly _resourcesAssembly = typeof(TagHelperComponentTagHelperTest).GetTypeInfo().Assembly; - public TagHelperComponentTagHelperTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task InjectsTestHeadTagHelperComponent() diff --git a/src/Mvc/test/Mvc.FunctionalTests/TagHelpersFromServicesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TagHelpersFromServicesTest.cs index e81fd78849c6..ee8b90ceccb2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TagHelpersFromServicesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TagHelpersFromServicesTest.cs @@ -2,17 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TagHelpersFromServicesTest : IClassFixture> +public class TagHelpersFromServicesTest : LoggedTest { - public TagHelpersFromServicesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task TagHelpersWithConstructorInjectionAreCreatedAndActivated() diff --git a/src/Mvc/test/Mvc.FunctionalTests/TagHelpersTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TagHelpersTest.cs index a2e5ef98f8db..c914b3500c95 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TagHelpersTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TagHelpersTest.cs @@ -6,12 +6,12 @@ using System.Net.Http.Headers; using System.Reflection; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TagHelpersTest : - IClassFixture>, - IClassFixture> +public class TagHelpersTest : LoggedTest { // Some tests require comparing the actual response body against an expected response baseline // so they require a reference to the assembly on which the resources are located, in order to @@ -19,17 +19,26 @@ public class TagHelpersTest : // use it on all the rest of the tests. private static readonly Assembly _resourcesAssembly = typeof(TagHelpersTest).GetTypeInfo().Assembly; - public TagHelpersTest( - MvcTestFixture fixture, - MvcEncodedTestFixture encodedFixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); - EncodedClient = encodedFixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + EncodedFactory = new MvcEncodedTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); + EncodedClient = EncodedFactory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public MvcEncodedTestFixture EncodedFactory { get; private set; } + public HttpClient Client { get; private set; } - public HttpClient EncodedClient { get; } + public HttpClient EncodedClient { get; private set; } [Theory] [InlineData("Index")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs index 372bc0e697e7..f25096cc9acc 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesTest.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Text; using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Infrastructure; @@ -14,20 +15,15 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TempDataInCookiesTest : TempDataTestBase, IClassFixture> +public class TempDataInCookiesTest : TempDataTestBase { private IServiceCollection _serviceCollection; - public TempDataInCookiesTest(MvcTestFixture fixture) + protected override void ConfigureWebHostBuilder(IWebHostBuilder builder) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(b => b.UseStartup()); - factory = factory.WithWebHostBuilder(b => b.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection)); - - Client = factory.CreateDefaultClient(); + builder.ConfigureTestServices(serviceCollection => _serviceCollection = serviceCollection); } - protected override HttpClient Client { get; } - [Fact] public void VerifyNewtonsoftJsonTempDataSerializer() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesUsingCookieConsentTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesUsingCookieConsentTest.cs index 68c719fe4461..627e78d28fe6 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesUsingCookieConsentTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInCookiesUsingCookieConsentTest.cs @@ -3,23 +3,33 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Net.Http.Headers; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TempDataInCookiesUsingCookieConsentTest - : IClassFixture> +public class TempDataInCookiesUsingCookieConsentTest : LoggedTest { - private readonly HttpClient _client; + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } - public TempDataInCookiesUsingCookieConsentTest( - MvcTestFixture fixture) + public override void Dispose() { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - _client = factory.CreateDefaultClient(); + Factory.Dispose(); + base.Dispose(); } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => builder.UseStartup(); @@ -33,16 +43,16 @@ public async Task CookieTempDataProviderCookie_SetInResponse_OnGrantingConsent() }; var content = new FormUrlEncodedContent(nameValueCollection); // This response would have the consent cookie which would be sent on rest of the requests here - var response = await _client.GetAsync("/TempData/GrantConsent"); + var response = await Client.GetAsync("/TempData/GrantConsent"); // Act 1 - response = await _client.SendAsync(GetPostRequest("/TempData/SetTempData", content, response)); + response = await Client.SendAsync(GetPostRequest("/TempData/SetTempData", content, response)); // Assert 1 Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Act 2 - response = await _client.SendAsync(GetRequest("/TempData/GetTempData", response)); + response = await Client.SendAsync(GetRequest("/TempData/GetTempData", response)); // Assert 2 Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -50,7 +60,7 @@ public async Task CookieTempDataProviderCookie_SetInResponse_OnGrantingConsent() Assert.Equal("Foo", body); // Act 3 - response = await _client.SendAsync(GetRequest("/TempData/GetTempData", response)); + response = await Client.SendAsync(GetRequest("/TempData/GetTempData", response)); // Assert 3 Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); @@ -67,13 +77,13 @@ public async Task CookieTempDataProviderCookie_NotSetInResponse_OnNoConsent() var content = new FormUrlEncodedContent(nameValueCollection); // Act 1 - var response = await _client.PostAsync("/TempData/SetTempData", content); + var response = await Client.PostAsync("/TempData/SetTempData", content); // Assert 1 Assert.Equal(HttpStatusCode.OK, response.StatusCode); // Act 2 - response = await _client.SendAsync(GetRequest("/TempData/GetTempData", response)); + response = await Client.SendAsync(GetRequest("/TempData/GetTempData", response)); // Assert 2 Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataInSessionTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataInSessionTest.cs index d7d5b4902da5..80d48cafb51f 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataInSessionTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataInSessionTest.cs @@ -5,12 +5,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TempDataInSessionTest : TempDataTestBase, IClassFixture> +public class TempDataInSessionTest : TempDataTestBase { - public TempDataInSessionTest(MvcTestFixture fixture) - { - Client = fixture.CreateDefaultClient(); - } - - protected override HttpClient Client { get; } } diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataPropertyTest.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataPropertyTest.cs index f019555bba72..c86191791948 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataPropertyTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataPropertyTest.cs @@ -1,21 +1,33 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.Net.Http.Headers; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class TempDataPropertyTest : IClassFixture> +public class TempDataPropertyTest : LoggedTest { - protected HttpClient Client { get; } + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); + } - public TempDataPropertyTest(MvcTestFixture fixture) + public override void Dispose() { - Client = fixture.CreateDefaultClient(); + Factory.Dispose(); + base.Dispose(); } + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } + [Fact] public async Task TempDataPropertyAttribute_RetainsTempDataWithView() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/TempDataTestBase.cs b/src/Mvc/test/Mvc.FunctionalTests/TempDataTestBase.cs index 9b39742d1319..2b982c237281 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/TempDataTestBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/TempDataTestBase.cs @@ -1,15 +1,36 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net; using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Net.Http.Headers; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class TempDataTestBase +public abstract class TempDataTestBase : LoggedTest where TStartup : class { - protected abstract HttpClient Client { get; } + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + { + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); + } + + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } + + protected virtual void ConfigureWebHostBuilder(IWebHostBuilder builder) { } [Fact] public async Task PersistsJustForNextRequest() diff --git a/src/Mvc/test/Mvc.FunctionalTests/UrlResolutionTest.cs b/src/Mvc/test/Mvc.FunctionalTests/UrlResolutionTest.cs index 9934fd438843..af802baf278a 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/UrlResolutionTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/UrlResolutionTest.cs @@ -3,26 +3,37 @@ using System.Net.Http; using System.Reflection; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class UrlResolutionTest : - IClassFixture>, - IClassFixture> +public class UrlResolutionTest : LoggedTest { private static readonly Assembly _resourcesAssembly = typeof(UrlResolutionTest).GetTypeInfo().Assembly; - public UrlResolutionTest( - MvcTestFixture fixture, - MvcEncodedTestFixture encodedFixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); - EncodedClient = encodedFixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + EncodedFactory = new MvcEncodedTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); + EncodedClient = EncodedFactory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + EncodedFactory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public MvcEncodedTestFixture EncodedFactory { get; private set; } + public HttpClient Client { get; private set; } - public HttpClient EncodedClient { get; } + public HttpClient EncodedClient { get; private set; } [Fact] public async Task AppRelativeUrlsAreResolvedCorrectly() diff --git a/src/Mvc/test/Mvc.FunctionalTests/VersioningEndpointRoutingTests.cs b/src/Mvc/test/Mvc.FunctionalTests/VersioningEndpointRoutingTests.cs index 107579fac361..907cac369899 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/VersioningEndpointRoutingTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/VersioningEndpointRoutingTests.cs @@ -9,11 +9,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class VersioningEndpointRoutingTests : VersioningTestsBase { - public VersioningEndpointRoutingTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/VersioningTests.cs b/src/Mvc/test/Mvc.FunctionalTests/VersioningTests.cs index 09e916db782c..871e1959ed54 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/VersioningTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/VersioningTests.cs @@ -8,11 +8,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests; public class VersioningTests : VersioningTestsBase { - public VersioningTests(MvcTestFixture fixture) - : base(fixture) - { - } - [Fact] public override async Task HasEndpointMatch() { diff --git a/src/Mvc/test/Mvc.FunctionalTests/VersioningTestsBase.cs b/src/Mvc/test/Mvc.FunctionalTests/VersioningTestsBase.cs index 16c1953d446a..2bdd56adff02 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/VersioningTestsBase.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/VersioningTestsBase.cs @@ -3,23 +3,35 @@ using System.Net; using System.Net.Http; +using System.Reflection; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; +using Microsoft.AspNetCore.Mvc.Testing; using Newtonsoft.Json; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public abstract class VersioningTestsBase : IClassFixture> where TStartup : class +public abstract class VersioningTestsBase : LoggedTest where TStartup : class { - protected VersioningTestsBase(MvcTestFixture fixture) + private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => + builder.UseStartup(); + + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - var factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(ConfigureWebHostBuilder); - Client = factory.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory).WithWebHostBuilder(ConfigureWebHostBuilder); + Client = Factory.CreateDefaultClient(); } - private static void ConfigureWebHostBuilder(IWebHostBuilder builder) => - builder.UseStartup(); + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } - public HttpClient Client { get; } + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public abstract Task HasEndpointMatch(); diff --git a/src/Mvc/test/Mvc.FunctionalTests/ViewComponentFromServicesTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ViewComponentFromServicesTests.cs index 48f3e1d920a7..9e04ff1bc567 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ViewComponentFromServicesTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ViewComponentFromServicesTests.cs @@ -2,17 +2,30 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.InternalTesting; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ViewComponentFromServicesTest : IClassFixture> +public class ViewComponentFromServicesTest : LoggedTest { - public ViewComponentFromServicesTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task ViewComponentsWithConstructorInjectionAreCreatedAndActivated() diff --git a/src/Mvc/test/Mvc.FunctionalTests/ViewEngineTests.cs b/src/Mvc/test/Mvc.FunctionalTests/ViewEngineTests.cs index 335b3a44b116..6a4deae7ab38 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/ViewEngineTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/ViewEngineTests.cs @@ -7,19 +7,30 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.InternalTesting; using Microsoft.Net.Http.Headers; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class ViewEngineTests : IClassFixture> +public class ViewEngineTests : LoggedTest { private static readonly Assembly _assembly = typeof(ViewEngineTests).GetTypeInfo().Assembly; - public ViewEngineTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } public static IEnumerable RazorView_ExecutesPageAndLayoutData { diff --git a/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs index 892670ddd182..0c99845b9c51 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerFormattersWrappingTest.cs @@ -10,19 +10,28 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.InternalTesting; using XmlFormattersWebSite; +using System.Reflection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class XmlDataContractSerializerFormattersWrappingTest : IClassFixture> +public class XmlDataContractSerializerFormattersWrappingTest : LoggedTest { - public XmlDataContractSerializerFormattersWrappingTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup()); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } - public WebApplicationFactory Factory { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public HttpClient Client { get; private set; } + public WebApplicationFactory Factory { get; private set; } [ConditionalTheory] // Mono issue - https://github.com/aspnet/External/issues/18 diff --git a/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs b/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs index 56ca2990c1d4..bff567a47a24 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/XmlDataContractSerializerInputFormatterTest.cs @@ -4,20 +4,33 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Runtime.Serialization; using System.Text; +using Microsoft.AspNetCore.InternalTesting; using XmlFormattersWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class XmlDataContractSerializerInputFormatterTest : IClassFixture> +public class XmlDataContractSerializerInputFormatterTest : LoggedTest { - public XmlDataContractSerializerInputFormatterTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public HttpClient Client { get; private set; } + + public MvcTestFixture Factory { get; private set; } [Fact] public async Task ThrowsOnInvalidInput_AndAddsToModelState() diff --git a/src/Mvc/test/Mvc.FunctionalTests/XmlOutputFormatterTests.cs b/src/Mvc/test/Mvc.FunctionalTests/XmlOutputFormatterTests.cs index 886574b5a9c3..31367b6e4fe3 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/XmlOutputFormatterTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/XmlOutputFormatterTests.cs @@ -6,17 +6,30 @@ using System.Net.Http.Headers; using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.Extensions.Logging; +using System.Reflection; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class XmlOutputFormatterTests : IClassFixture> +public class XmlOutputFormatterTests : LoggedTest { - public XmlOutputFormatterTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public HttpClient Client { get; private set; } + + public MvcTestFixture Factory { get; private set; } [ConditionalFact] // Mono.Xml2.XmlTextReader.ReadText is unable to read the XML. This is fixed in mono 4.3.0. diff --git a/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs index b8f1f1578c49..f85d681eb6b6 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerFormattersWrappingTest.cs @@ -5,24 +5,34 @@ using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Xml.Linq; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.InternalTesting; using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.Mvc.Testing; using XmlFormattersWebSite; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class XmlSerializerFormattersWrappingTest : IClassFixture> +public class XmlSerializerFormattersWrappingTest : LoggedTest { - public XmlSerializerFormattersWrappingTest(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup()); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); Client = Factory.CreateDefaultClient(); } - public WebApplicationFactory Factory { get; } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public WebApplicationFactory Factory { get; private set; } + public HttpClient Client { get; private set; } [Theory] [InlineData("http://localhost/IEnumerable/ValueTypes")] diff --git a/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs b/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs index c69db507661a..728a7332b5f4 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs @@ -4,19 +4,31 @@ using System.Globalization; using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using Microsoft.AspNetCore.InternalTesting; +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests; -public class XmlSerializerInputFormatterTests : IClassFixture> +public class XmlSerializerInputFormatterTests : LoggedTest { - public XmlSerializerInputFormatterTests(MvcTestFixture fixture) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { - Client = fixture.CreateDefaultClient(); + base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); + Factory = new MvcTestFixture(LoggerFactory); + Client = Factory.CreateDefaultClient(); } - public HttpClient Client { get; } + public override void Dispose() + { + Factory.Dispose(); + base.Dispose(); + } + + public MvcTestFixture Factory { get; private set; } + public HttpClient Client { get; private set; } [Fact] public async Task CheckIfXmlSerializerInputFormatterIsCalled() diff --git a/src/Mvc/test/Mvc.FunctionalTests/xunit.runner.json b/src/Mvc/test/Mvc.FunctionalTests/xunit.runner.json index 1c72a421ad32..c72abd7754f7 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/xunit.runner.json +++ b/src/Mvc/test/Mvc.FunctionalTests/xunit.runner.json @@ -1,3 +1,6 @@ { + "longRunningTestSeconds": 30, + "diagnosticMessages": true, + "maxParallelThreads": -1, "shadowCopy": false } diff --git a/src/Mvc/test/WebSites/ApiExplorerWebSite/Startup.cs b/src/Mvc/test/WebSites/ApiExplorerWebSite/Startup.cs index f13a31df7560..c2bfec25d45e 100644 --- a/src/Mvc/test/WebSites/ApiExplorerWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/ApiExplorerWebSite/Startup.cs @@ -12,8 +12,6 @@ public class Startup // Set up application services public void ConfigureServices(IServiceCollection services) { - services.AddTransient(); - var wellKnownChangeToken = new WellKnownChangeToken(); services.AddControllers(options => { diff --git a/src/Mvc/test/WebSites/RazorBuildWebSite/UpdateableFileProvider.cs b/src/Mvc/test/WebSites/RazorBuildWebSite/UpdateableFileProvider.cs index b717657e2bc4..596e62a1bbab 100644 --- a/src/Mvc/test/WebSites/RazorBuildWebSite/UpdateableFileProvider.cs +++ b/src/Mvc/test/WebSites/RazorBuildWebSite/UpdateableFileProvider.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/FixtureLoggedTest.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/FixtureLoggedTest.cs index e51c8515c2c5..57b78e68d1dd 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/FixtureLoggedTest.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/Infrastructure/FixtureLoggedTest.cs @@ -17,7 +17,7 @@ public FixtureLoggedTest(IISTestSiteFixture fixture) Fixture = fixture; } - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); Fixture.Attach(this); diff --git a/src/Servers/Kestrel/Core/test/Http1/Http1ConnectionTestsBase.cs b/src/Servers/Kestrel/Core/test/Http1/Http1ConnectionTestsBase.cs index ba86cff87fb6..c4008d7b2208 100644 --- a/src/Servers/Kestrel/Core/test/Http1/Http1ConnectionTestsBase.cs +++ b/src/Servers/Kestrel/Core/test/Http1/Http1ConnectionTestsBase.cs @@ -27,7 +27,7 @@ public class Http1ConnectionTestsBase : LoggedTest, IDisposable internal SequencePosition _examined; internal Mock _timeoutControl; - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); diff --git a/src/Servers/Kestrel/shared/test/TestApplicationErrorLoggerLoggedTest.cs b/src/Servers/Kestrel/shared/test/TestApplicationErrorLoggerLoggedTest.cs index 8b4a8dd776d1..f8bab65d13fb 100644 --- a/src/Servers/Kestrel/shared/test/TestApplicationErrorLoggerLoggedTest.cs +++ b/src/Servers/Kestrel/shared/test/TestApplicationErrorLoggerLoggedTest.cs @@ -34,7 +34,7 @@ public bool ThrowOnUngracefulShutdown public Task WaitForLogMessage(Func messageFilter) => TestApplicationErrorLogger.WaitForMessage(messageFilter); - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs index c334ee588dab..546d1337cade 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2TestBase.cs @@ -384,7 +384,7 @@ public Http2TestBase() }; } - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs index 373a453214a6..a7ed4cba8849 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs @@ -114,7 +114,7 @@ public Http3TestBase() }; } - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); diff --git a/src/Testing/src/LoggedTest/LoggedTest.cs b/src/Testing/src/LoggedTest/LoggedTest.cs index 9c6d87582060..0030f37e6428 100644 --- a/src/Testing/src/LoggedTest/LoggedTest.cs +++ b/src/Testing/src/LoggedTest/LoggedTest.cs @@ -14,7 +14,7 @@ public LoggedTest(ITestOutputHelper output = null) : base(output) { } public ITestSink TestSink { get; set; } - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper); diff --git a/src/Testing/src/LoggedTest/LoggedTestBase.cs b/src/Testing/src/LoggedTest/LoggedTestBase.cs index 51188982c04a..a361ad0d528b 100644 --- a/src/Testing/src/LoggedTest/LoggedTestBase.cs +++ b/src/Testing/src/LoggedTest/LoggedTestBase.cs @@ -55,7 +55,7 @@ public IDisposable StartLog(out ILoggerFactory loggerFactory, LogLevel minLogLev return AssemblyTestLog.ForAssembly(GetType().GetTypeInfo().Assembly).StartTestLog(TestOutputHelper, GetType().FullName, out loggerFactory, minLogLevel, testName); } - public virtual void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected virtual void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { try { diff --git a/src/Testing/test/LoggedTestXunitTests.cs b/src/Testing/test/LoggedTestXunitTests.cs index 1dbf854b9881..7d1b7dc87620 100644 --- a/src/Testing/test/LoggedTestXunitTests.cs +++ b/src/Testing/test/LoggedTestXunitTests.cs @@ -177,7 +177,7 @@ public class TestLoggedTest : LoggedTest public bool SetupInvoked { get; private set; } = false; public bool ITestOutputHelperIsInitialized { get; private set; } = false; - public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) + protected override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper) { base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper);