restsharp / restsharp/RestSharp
move "async Task<RestResponse<T>> ExecuteAsync<T>" from Extension to IRestClient
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 9.8k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
The extension-method
async Task<RestResponse<T>> ExecuteAsync<T>
Is the "natural" way to do a Request: everyting is TypeSave. But If you try to Mock IRestClient, you can only mock the Non-Typed Request-Reponse method.
In a Test-Scenario, we have to add the Serializers and use compute to Serialize & Deserialize, there is no full control on the response - the deserializers try to do the work - and an easy workaround with own serializer/deserialiser is not easy.
I had a long look at the sources, but using a custom Serializer did not worked out well. So I ended up with this Blog-Post unittest-with-restsharp
Yes, this works but is not intuitive.
Describe the solution you'd like
Having Task<RestResponse<T>> ExecuteAsync<T> in IRestClient would enable us to simple Mock the call. No additional Setup, No Serialization during the Test.
As far as I see, the ExtensionMethod can be moved to the RestClient-Implementation without breaking anything. All other ExtensionMethods will work, IRestClient-Implementation / Mocks will work.
You could move the method to the IRestClient Implementaion, extend the interface and remove the ExtensionMethod- without any side effects.
Describe alternatives you've considered
Considered? Mocking the Tests is complex. I considered to remove RestSharp - but my time is limited ;-) I did a complex initialization and hope my (future) colleagues will understand this in 2 years...
If I was unclear / any questions - may need some days for me to answer, but I'm here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the ExecuteAsync extension method and the IRestClient interface and implementation in the repository. Review existing calls and tests around typed requests, then determine how the interface change affects mocking and existing extension-method consumers. Done means typed execution is available through IRestClient and the relevant tests cover mocked responses without serializer setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100