Repository: dotnet/aspnetcore
File: src/Mvc/test/Mvc.FunctionalTests/TestingInfrastructureInheritanceTests.cs (C#)

Code before:
    [Fact]
    public void TestingInfrastructure_GenericHost_HostDispose()
    {
        // Arrange
        using var factory = new CustomizedFactory<GenericHostWebSite.Startup>().WithWebHostBuilder(ConfigureWebHostBuilder);
        using var scope = factory.Services.CreateScope();
        var sink = scope.ServiceProvider.GetRequiredService<DisposableService>();

        // Act
        scope.Dispose();

        // Assert
        Assert.True(sink._asyncDisposed);
    }

    private static void ConfigureWebHostBuilder(IWebHostBuilder builder) =>
        builder.UseStartup<GenericHostWebSite.Startup>()
        .ConfigureServices(s => s.AddScoped<DisposableService>());

    private class DisposableService : IAsyncDisposable, IDisposable
    {
        public bool _asyncDisposed = false;
        public ValueTask DisposeAsync()
        {
            _asyncDisposed = true;
            return ValueTask.CompletedTask;
        }
        public void Dispose()
        {
            _asyncDisposed = true;
        }
    }

    private class CustomizedFactory<TEntryPoint> : WebApplicationFactory<TEntryPoint> where TEntryPoint : class
    {
        public bool GetTestAssembliesCalled { get; private set; }
        public bool CreateWebHostBuilderCalled { get; private set; }
        public bool CreateHostBuilderCalled { get; private set; }
        public bool CreateServerCalled { get; private set; }
        public bool CreateHostCalled { get; private set; }
        public IList<string> ConfigureWebHostCalled { get; private set; } = new List<string>();

        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            ConfigureWebHostCalled.Add("ConfigureWebHost");
            base.ConfigureWebHost(builder);
        }

        protected override TestServer CreateServer(IWebHostBuilder builder)
        {
            CreateServerCalled = true;

Review comment (suggestion):
[nitpick] Use collection expression syntax consistently. The array literal syntax `["ConfigureWebHost"]` is being used here, but line 27 uses `new[] { ... }`. Consider using the newer collection expression syntax throughout for consistency.

Code after:
    }

    [Fact]
    public void TestingInfrastructure_GenericHost_HostDispose()
    {
        // Arrange
        using var factory = new CustomizedFactory<GenericHostWebSite.Startup>().WithWebHostBuilder(ConfigureWebHostBuilder);
        using var scope = factory.Services.CreateScope();
        var sink = scope.ServiceProvider.GetRequiredService<DisposableService>();

        // Act
        scope.Dispose();

        // Assert
        Assert.True(sink._asyncDisposed);
    }

    [Fact]
    public void TestingInfrastructure_WebApplicationBuilder_RespectsCustomizations()
    {
        // Arrange
        using var factory = new CustomizedFactory<SimpleWebSiteWithWebApplicationBuilder.Program>();
        factory.StartServer();

        // Assert
        Assert.Equal(["ConfigureWebHost"], factory.ConfigureWebHostCalled.ToArray());
        Assert.False(factory.GetTestAssembliesCalled);
        Assert.True(factory.CreateHostBuilderCalled);
        Assert.True(factory.CreateHostCalled);
        Assert.False(factory.CreateServerIWebHostBuilderCalled);
        Assert.True(factory.CreateServerWithServiceProviderCalled);
        Assert.True(factory.CreateWebHostBuilderCalled);
    }

    private static void ConfigureWebHostBuilder(IWebHostBuilder builder) =>
        builder.UseStartup<GenericHostWebSite.Startup>()
        .ConfigureServices(s => s.AddScoped<DisposableService>());

    private class DisposableService : IAsyncDisposable, IDisposable
    {
        public bool _asyncDisposed = false;
        public ValueTask DisposeAsync()
        {
            _asyncDisposed = true;
            return ValueTask.CompletedTask;
        }
        public void Dispose()
        {
            _asyncDisposed = true;
        }
    }