restsharp / restsharp/RestSharp

move "async Task<RestResponse<T>> ExecuteAsync<T>" from Extension to IRestClient

Open
#2,384 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting-feedback feature-request
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.