Skip to content

Commit ac756ff

Browse files
Style and analyzer fixes (#33891)
Miscellaneous style and code analyzer fixes from things Visual Studio was complaining to me about while I was working on #33890.
1 parent 689a08f commit ac756ff

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

src/Mvc/Mvc.Testing/src/DeferredHostBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
14
using System;
25
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Microsoft.Extensions.Configuration;

src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Microsoft.AspNetCore.Hosting;
1414
using Microsoft.AspNetCore.Hosting.Server;
1515
using Microsoft.AspNetCore.TestHost;
16-
using Microsoft.Extensions.Configuration;
1716
using Microsoft.Extensions.DependencyInjection;
1817
using Microsoft.Extensions.DependencyModel;
1918
using Microsoft.Extensions.Hosting;
@@ -32,8 +31,8 @@ public class WebApplicationFactory<TEntryPoint> : IDisposable, IAsyncDisposable
3231
private TestServer? _server;
3332
private IHost? _host;
3433
private Action<IWebHostBuilder> _configuration;
35-
private List<HttpClient> _clients = new();
36-
private List<WebApplicationFactory<TEntryPoint>> _derivedFactories = new();
34+
private readonly List<HttpClient> _clients = new();
35+
private readonly List<WebApplicationFactory<TEntryPoint>> _derivedFactories = new();
3736

3837
/// <summary>
3938
/// <para>
@@ -226,7 +225,7 @@ private void SetContentRoot(IWebHostBuilder builder)
226225
}
227226
}
228227

229-
private string GetContentRootFromFile(string file)
228+
private static string GetContentRootFromFile(string file)
230229
{
231230
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(File.ReadAllBytes(file))!;
232231
var key = typeof(TEntryPoint).Assembly.GetName().FullName;
@@ -350,7 +349,7 @@ protected virtual IEnumerable<Assembly> GetTestAssemblies()
350349
return Array.Empty<Assembly>();
351350
}
352351

353-
private void EnsureDepsFile()
352+
private static void EnsureDepsFile()
354353
{
355354
if (typeof(TEntryPoint).Assembly.EntryPoint == null)
356355
{
@@ -413,7 +412,7 @@ private void EnsureDepsFile()
413412
/// <param name="builder">The <see cref="IWebHostBuilder"/> used to
414413
/// create the server.</param>
415414
/// <returns>The <see cref="TestServer"/> with the bootstrapped application.</returns>
416-
protected virtual TestServer CreateServer(IWebHostBuilder builder) => new TestServer(builder);
415+
protected virtual TestServer CreateServer(IWebHostBuilder builder) => new(builder);
417416

418417
/// <summary>
419418
/// Creates the <see cref="IHost"/> with the bootstrapped application in <paramref name="builder"/>.
@@ -478,7 +477,7 @@ public HttpClient CreateDefaultClient(params DelegatingHandler[] handlers)
478477
}
479478

480479
var serverHandler = _server.CreateHandler();
481-
handlers[handlers.Length - 1].InnerHandler = serverHandler;
480+
handlers[^1].InnerHandler = serverHandler;
482481

483482
client = new HttpClient(handlers[0]);
484483
}
@@ -524,6 +523,7 @@ public HttpClient CreateDefaultClient(Uri baseAddress, params DelegatingHandler[
524523
public void Dispose()
525524
{
526525
Dispose(true);
526+
GC.SuppressFinalize(this);
527527
}
528528

529529
/// <summary>
@@ -589,6 +589,8 @@ public virtual async ValueTask DisposeAsync()
589589
_disposedAsync = true;
590590

591591
Dispose(disposing: true);
592+
593+
GC.SuppressFinalize(this);
592594
}
593595

594596
private class DelegatedWebApplicationFactory : WebApplicationFactory<TEntryPoint>

src/Mvc/test/Mvc.FunctionalTests/RoutingEndpointRoutingTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public async Task AttributeRoutedAction_ParameterTransformer_LinkToConventionalC
204204
}
205205

206206
[Fact]
207-
public async override Task HasEndpointMatch()
207+
public override async Task HasEndpointMatch()
208208
{
209209
// Arrange & Act
210210
var response = await Client.GetAsync("http://localhost/Routing/HasEndpointMatch");
@@ -219,7 +219,7 @@ public async override Task HasEndpointMatch()
219219
}
220220

221221
[Fact]
222-
public async override Task RouteData_Routers_ConventionalRoute()
222+
public override async Task RouteData_Routers_ConventionalRoute()
223223
{
224224
// Arrange & Act
225225
var response = await Client.GetAsync("http://localhost/RouteData/Conventional");
@@ -236,7 +236,7 @@ public async override Task RouteData_Routers_ConventionalRoute()
236236
}
237237

238238
[Fact]
239-
public async override Task RouteData_Routers_AttributeRoute()
239+
public override async Task RouteData_Routers_AttributeRoute()
240240
{
241241
// Arrange & Act
242242
var response = await Client.GetAsync("http://localhost/RouteData/Attribute");

src/Mvc/test/Mvc.FunctionalTests/SimpleWithWebApplicationBuilderExceptionTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Net;
6-
using System.Net.Http;
7-
using System.Threading.Tasks;
85
using Xunit;
96

107
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
118
{
129
public class SimpleWithWebApplicationBuilderExceptionTests : IClassFixture<MvcTestFixture<SimpleWebSiteWithWebApplicationBuilderException.FakeStartup>>
1310
{
14-
private MvcTestFixture<SimpleWebSiteWithWebApplicationBuilderException.FakeStartup> _fixture;
11+
private readonly MvcTestFixture<SimpleWebSiteWithWebApplicationBuilderException.FakeStartup> _fixture;
1512

1613
public SimpleWithWebApplicationBuilderExceptionTests(MvcTestFixture<SimpleWebSiteWithWebApplicationBuilderException.FakeStartup> fixture)
1714
{

src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilder/FakeEntryPoint.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
53

64
/// <summary>
75
/// This is a class we use to reference this assembly statically from tests

src/Mvc/test/WebSites/SimpleWebSiteWithWebApplicationBuilderException/FakeEntryPoint.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
53

64
/// <summary>
75
/// This is a class we use to reference this assembly statically from tests

0 commit comments

Comments
 (0)