-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Expose TestServer as public property on RequestBuilder #10396
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
Expose TestServer as public property on RequestBuilder #10396
Conversation
The code seems fine, but there's a problem with the intent. You did this so you could get access to the IWebHost and IServiceCollection. However, when we refactored TestServer for generic host it no longer holds a reference to either of those. You might need to re-think the larger design here. |
Thanks @huysentruitw for picking up this issue! @Tratcher, I'm not sure I follow your comment. When I look at the changeset you linked to, I see that there's still an With this changeset, this should complete the chain from |
New 3.0 apps don't use IWebHost anymore, they've moved to IHost instead (which doesn't have a property on TestServer due to the redesign). The new 3.0 templates: |
Are the current v3.0 preview integration docs reflective of how we should be writing integration tests using the Assuming my above reading is correct, is there some benefit to using |
The WebApplicationFactory has been updated to work with either IHost or IWebHost. It's useful for testing larger components, especially full MVC apps. TestServer is designed for unit testing individual middleware.
HttpClient has an ecosystem of libraries built around it for crafting requests and reading responses. That can be helpful for some scenarios. RequestBuilder is more helpful when you need to seed some of the server side structures directly. When what you're really after here is the services, we should revisit making those available directly on TestServer and RequestBuilder. We don't need the IHost to do that, we could inject the IServiceCollection into the TestServer constructor. |
7fb3c26
to
c94358b
Compare
Anyone fancy to review my updates from 24 days ago? 😁 |
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.
Sorry, hadn't noticed the updates. Looks better this time.
src/Hosting/TestHost/ref/Microsoft.AspNetCore.TestHost.netcoreapp3.0.cs
Outdated
Show resolved
Hide resolved
@huysentruitw were you going to be able to finish this up? |
@Tratcher I have a problem with this test when removing the parameter-less constructor for Now I need to pass a I think we need to remove this test as it probably demonstrates a usage we don't want to support. Or we could change the
What do you think? |
@huysentruitw Replace the UseServer call with |
c94358b
to
b4a836d
Compare
src/Hosting/TestHost/ref/Microsoft.AspNetCore.TestHost.netcoreapp3.0.cs
Outdated
Show resolved
Hide resolved
Co-Authored-By: Chris Ross <[email protected]>
Thanks |
No, thank YOU. This is a wonderful addition to I'm looking even more forward to ASP.NET Core v3! |
Expose TestServer as public property on RequestBuilder.
Addresses #5947