Integration Testing with a Refit Client and ASP.NET Core #1998
Unanswered
perchbirdd
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Trying to get an integration test (almost an E2E test) going that ensures that my application performs properly and the generated refit client can communicate with the API as expected.
The recommended method of integration testing, mentioned literally everywhere, for ASP.NET generally follows this pattern:
What this does is provide the developer with an in-memory version of their application. The HttpClient returned by CreateClient is special and connects to this in-memory application without the application listening on any ports or running Kestrel. It seems there is no way around this - you have to do this if you are doing any kind of mocking or custom setup in an integration test (which, if not, you could just run your application as-is).
On the Refit side, my API calls are defined like so:
If I wanted this to work properly, I would have to do the following to the refit client in my integration test:
But
AuthorizationHeaderValueGetter
does not work if you provide your ownHttpClient
.So, it is either-or: either you use the in-memory test server and provide the
HttpClient
to Refit and you cannot use the Authorization attribute, OR you specify it in the interface method signatures?Beta Was this translation helpful? Give feedback.
All reactions