Skip to content

TestServerOptions not applied anymore by WebApplicationFactory #64593

@manandre

Description

@manandre

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Since version 10.0.0 of Microsoft.AspNetCore.Mvc.Testing, the TestServerOptions passed to the UseTestServer extension method for the IWebHostBuilder interface are not applied when you create a TestServer instance via a (custom) WebApplicationFactory.
The issue has been discovered via the AllowSynchronousIO field but it should apply to other options, as the configureOptions delegate is not called at server creation time.

Expected Behavior

The TestServerOptions passed to the UseTestServer extension method must be applied to TestServer instances created by a WebApplicationFactory, as it is correctly working in version 9.0.11 of Microsoft.AspNetCore.Mvc.Testing.

Steps To Reproduce

public class CustomWebApplicationFactory<T>
    : WebApplicationFactory<T> where T : class
{
    protected override void ConfigureWebHost(IWebHostBuilder builder)
    {
        builder.UseTestServer(o => o.AllowSynchronousIO = true);
    }
}

public class CustomTests(CustomWebApplicationFactory<Program> factory)
    : IClassFixture<CustomWebApplicationFactory<Program>>
{
    [Fact]
    public void Settings_AllowSynchronousIo_Set()
    {
        Assert.True(factory.Server.AllowSynchronousIO);
    }
}

The unit test fails on net10.0 TFM, using version 10.0.0 of Microsoft.AspNetCore.Mvc.Testing.
While the same unit test succeeds on net9.0 TFM, using version 9.0.11 of Microsoft.AspNetCore.Mvc.Testing

Exceptions (if any)

No response

.NET Version

10.0.100

Anything else?

I may be linked to the documented breaking change around WebHostBuilder but it does not explain the regression here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-mvc-testingMVC testing package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions