Skip to content

minimum requirements to mock HttpContext.GetRequestedApiVersion() #981

Discussion options

You must be logged in to vote

I'm glad you found the tests. That is the documentation. 😉

Setting up and parsing from the HttpContext is irrelevant and unnecessary. The specific tests you mention exercise that path for coverage, but it is unnecessary. I wouldn't recommend you re-test that behavior. If all you want to do is test the behavior for a specific ApiVersion, you can explicitly set it in the feature, which it seems you've figured out.

You've missed just one very small, but important piece. Wait for it.... Warning: You are going to kick yourself... 2 ... 3:

public static HttpContext CreateVersionedHttpContext(int version) {
    var context = new DefaultHttpContext();
    IApiVersionVersioningFeature feature = new 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@steveoh
Comment options

Answer selected by steveoh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants