-
Notifications
You must be signed in to change notification settings - Fork 10.5k
CreateServer with TestServerOptions in WebApplicationFactory #64803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your PR, @@manandre. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a regression where TestServerOptions configured via UseTestServer were not being applied when creating a TestServer in WebApplicationFactory. The fix ensures that when a TestServer is created from an IServiceProvider, any configured IOptions<TestServerOptions> are properly retrieved and passed to the TestServer constructor.
Key Changes
- Modified
CreateServer(IServiceProvider)to retrieve and useIOptions<TestServerOptions>when available - Added a comprehensive integration test to verify the fix works correctly
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs | Updated CreateServer method to retrieve and apply TestServerOptions from the service provider, falling back to the parameterless constructor when options are not configured |
| src/Mvc/test/Mvc.FunctionalTests/TestServerWithCustomConfigurationIntegrationTests.cs | Added integration test with custom WebApplicationFactory to verify that TestServerOptions configured via UseTestServer are correctly applied to the created TestServer |
| protected virtual TestServer CreateServer(IServiceProvider serviceProvider) => new(serviceProvider); | ||
| protected virtual TestServer CreateServer(IServiceProvider serviceProvider) | ||
| { | ||
| var options = serviceProvider.GetService<IOptions<TestServerOptions>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should instead change the TestServer ctor to try getting the options?
| : this(services, featureCollection, Options.Create(new TestServerOptions())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wondered also myself but I assume there was a good reason to not do it initially and now it could be considered as a breaking change, no?
CreateServer with TestServerOptions in WebApplicationFactory
Description
Applies the configured
TestServerOptionswhen creating aTestServerin aWebApplicationFactory.It addresses a regression introduced in c80f3e5#diff-c70063a52c125c1f25ca65f24827d42e1385d34eac3b567d180b5eb9cd53e696R341
Fixes #64593