-
Notifications
You must be signed in to change notification settings - Fork 191
Make DefaultHttpContext more testable #91
Comments
I'd like @pranavkm @halter73@rynowak @harshgMSFT to chime in here since they have been writing unit tests agains the new HttpAbstractions. The goal here is the make it easy across the board so that frameworks like Mvc and SignalR can do it as well as end users wanting to test their controllers/hubs etc. |
cc @rynowak |
In order of importance:
Looking though a lot of our test code we could swap out the mocks now that we have a no-arg constructor. If we have those things I don't think there are major barriers. The other really common things that are painful are mocking options and service container, but those aren't super related. |
I think we also need an easy way to mock the query string and form collections. There doesn't seem to be a standard implementation of ReadableStringCollection back by a dictionary that we can use. |
|
@rynowak Here's the existing CreateContext from that test:
Here's another way of doing that (today, without any changes):
If this looks useful then we could make TestFormFeature available somewhere, or we could augment the normal FormFeature to support this directly. |
TestFormFeature sounds like a better way to go about it. It might be useful to additionally have properties \ methods on it be virtual so they can be mocked. |
If we went up having a The |
Lets hold off on the 'where do we put it' discussion until we've decided if it's useful. The normal FormFeature implementation reads from the request body, which I was told you explicitly did not want to do in unit tests. For reference, here's the existing FormFeature: The QueryFeature is very similar: I don't think any of the other current features fall into this pattern, but in the future we may have other such features for reading the request body in a certain way. |
There's also good potential here to just merge the constructors that I'm asking if there will be more stuff, because if we end up with more things like this, we might be so inclined to just create a 'TestHttpContext that instantiates and uses 'new' to expose all of the 'test' versions of various data. |
If we did any Test* types, I'd put it over in Microsoft.AspNet.Testing for folks to share. I'll play around with putting it into the core library first. |
How about this?
Or do I need to simplify that down one more layer to:
No extra types required, just a new constructor or two. |
BTW, QueryFeature would be exactly the same. |
Looks good to me. |
Any other test scenarios you want to investigate, or should we call this one done for now? |
Today you have to pass in a feature collection. There should be a default ctor that allows getting and setting all of the properties.
The text was updated successfully, but these errors were encountered: