Skip to content

Clearing up confusion when using WebApplicationFactory and TestServer #60492

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

Open
1 task done
aetos382 opened this issue Feb 19, 2025 · 3 comments
Open
1 task done

Clearing up confusion when using WebApplicationFactory and TestServer #60492

aetos382 opened this issue Feb 19, 2025 · 3 comments
Labels
area-hosting Includes Hosting feature-mvc-testing MVC testing package
Milestone

Comments

@aetos382
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

There are two ways to send HTTP requests to WebApplicationFactory.

One is to use WebApplicationFactory.CreateClient to obtain an HttpClient, which will result in an HttpClient that reflects the configuration by ConfigureClient.

The other is to use Server to obtain a TestServer, and then use TestServer.CreateClient to obtain an HttpClient. This method has high-level functions such as RequestBuilder, but does not reflect the configuration by WebApplicationFactory.ConfigureClient.

I was using ConfigureClient to configure the client, but when I switched to using RequestBuilder, I was confused because that configuration did not work.

Also, TestServer has CreateWebSocketClient, but WebApplicationFactory does not.
Thus, since WebApplicationFactory exposes only a portion of TestServer's functionality, developers may need to use TestServer directly.

Describe the solution you'd like

I don't have a clear idea of what exactly should be done.
Maybe functions such as RequestBuilder or WebSocketClient should be exposed through WebApplicationFactory, so that their configuration by ConfigureClient is reflected.
Also, there could be documentation or an analyzer that warns against using ConfigureClient and TestServer together.

I am aware that the WebApplicationFactory is currently being refactored.
I would appreciate it if you would also consider a fix to clarify this type of confusion.

Additional context

No response

@ghost ghost added the area-hosting Includes Hosting label Feb 19, 2025
@mkArtakMSFT mkArtakMSFT added the feature-mvc-testing MVC testing package label Feb 19, 2025
@MackinnonBuck
Copy link
Member

cc @mkArtakMSFT, since you're working on WebApplicationFactory. What do you think about the solutions suggested by @aetos382?

Maybe functions such as RequestBuilder or WebSocketClient should be exposed through WebApplicationFactory, so that their configuration by ConfigureClient is reflected.
Also, there could be documentation or an analyzer that warns against using ConfigureClient and TestServer together.

@MackinnonBuck
Copy link
Member

@mkArtakMSFT, do you have any thoughts about this?

@MackinnonBuck
Copy link
Member

@javiercn, is it by-design that using RequestBuilder causes the configuration specified via ConfigureClient to be ignored?

@MackinnonBuck MackinnonBuck added this to the Backlog milestone May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting feature-mvc-testing MVC testing package
Projects
None yet
Development

No branches or pull requests

3 participants