diff --git a/src/Mvc/Mvc.Testing/src/DeferredHostBuilder.cs b/src/Mvc/Mvc.Testing/src/DeferredHostBuilder.cs index 1a9fea4d99eb..8fca3c7c2d51 100644 --- a/src/Mvc/Mvc.Testing/src/DeferredHostBuilder.cs +++ b/src/Mvc/Mvc.Testing/src/DeferredHostBuilder.cs @@ -1,7 +1,8 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; diff --git a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs index 3e3e4df1e056..c00809c9ea90 100644 --- a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs +++ b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.Hosting; @@ -32,8 +31,8 @@ public class WebApplicationFactory : IDisposable, IAsyncDisposable private TestServer? _server; private IHost? _host; private Action _configuration; - private List _clients = new(); - private List> _derivedFactories = new(); + private readonly List _clients = new(); + private readonly List> _derivedFactories = new(); /// /// @@ -226,7 +225,7 @@ private void SetContentRoot(IWebHostBuilder builder) } } - private string GetContentRootFromFile(string file) + private static string GetContentRootFromFile(string file) { var data = JsonSerializer.Deserialize>(File.ReadAllBytes(file))!; var key = typeof(TEntryPoint).Assembly.GetName().FullName; @@ -350,7 +349,7 @@ protected virtual IEnumerable GetTestAssemblies() return Array.Empty(); } - private void EnsureDepsFile() + private static void EnsureDepsFile() { if (typeof(TEntryPoint).Assembly.EntryPoint == null) { @@ -413,7 +412,7 @@ private void EnsureDepsFile() /// The used to /// create the server. /// The with the bootstrapped application. - protected virtual TestServer CreateServer(IWebHostBuilder builder) => new TestServer(builder); + protected virtual TestServer CreateServer(IWebHostBuilder builder) => new(builder); /// /// Creates the with the bootstrapped application in . @@ -478,7 +477,7 @@ public HttpClient CreateDefaultClient(params DelegatingHandler[] handlers) } var serverHandler = _server.CreateHandler(); - handlers[handlers.Length - 1].InnerHandler = serverHandler; + handlers[^1].InnerHandler = serverHandler; client = new HttpClient(handlers[0]); } @@ -524,6 +523,7 @@ public HttpClient CreateDefaultClient(Uri baseAddress, params DelegatingHandler[ public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// @@ -589,6 +589,8 @@ public virtual async ValueTask DisposeAsync() _disposedAsync = true; Dispose(disposing: true); + + GC.SuppressFinalize(this); } private class DelegatedWebApplicationFactory : WebApplicationFactory diff --git a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs index 553af527507e..81f91a0779db 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs @@ -204,7 +204,7 @@ public async Task AttributeRoutedAction_ParameterTransformer_LinkToConventionalC } [Fact] - public async override Task HasEndpointMatch() + public override async Task HasEndpointMatch() { // Arrange & Act var response = await Client.GetAsync("http://localhost/Routing/HasEndpointMatch"); @@ -219,7 +219,7 @@ public async override Task HasEndpointMatch() } [Fact] - public async override Task RouteData_Routers_ConventionalRoute() + public override async Task RouteData_Routers_ConventionalRoute() { // Arrange & Act var response = await Client.GetAsync("http://localhost/RouteData/Conventional"); @@ -236,7 +236,7 @@ public async override Task RouteData_Routers_ConventionalRoute() } [Fact] - public async override Task RouteData_Routers_AttributeRoute() + public override async Task RouteData_Routers_AttributeRoute() { // Arrange & Act var response = await Client.GetAsync("http://localhost/RouteData/Attribute"); diff --git a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs index baca3e522ad9..2e1a501e5ce2 100644 --- a/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs +++ b/src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs @@ -2,16 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; using Xunit; namespace Microsoft.AspNetCore.Mvc.FunctionalTests { public class SimpleWithWebApplicationBuilderExceptionTests : IClassFixture> { - private MvcTestFixture _fixture; + private readonly MvcTestFixture _fixture; public SimpleWithWebApplicationBuilderExceptionTests(MvcTestFixture fixture) { diff --git a/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/FakeEntryPoint.cs b/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/FakeEntryPoint.cs index 13b9625cdc17..d15ecd83ca01 100644 --- a/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/FakeEntryPoint.cs +++ b/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/FakeEntryPoint.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. /// /// This is a class we use to reference this assembly statically from tests diff --git a/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilderException/FakeEntryPoint.cs b/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilderException/FakeEntryPoint.cs index 94550b75cd98..addbac61c829 100644 --- a/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilderException/FakeEntryPoint.cs +++ b/src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilderException/FakeEntryPoint.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. /// /// This is a class we use to reference this assembly statically from tests