HowToTestYourCsharpWebApi icon indicating copy to clipboard operation
HowToTestYourCsharpWebApi copied to clipboard

unit testing for external API

Open kiquenet opened this issue 2 years ago • 2 comments

How-to do unit testing for external API (like Fake API ) api.chucknorris.io ?

simple-example-of-calling-rest-api-with-httpclient-in-net5.0

kiquenet avatar Aug 31 '22 07:08 kiquenet

Hi, could you elaborate what/why you want to test an external api?

timdeschryver avatar Aug 31 '22 16:08 timdeschryver

2 scenarios:

  1. Test any exteranl REST API Client (ApiClient), for example, or using any REST API of another departaments (Sales, Purchasing, Accounts, Finance , Human Resources, ...), we haven't source code but we need test "API client".

  2. Test our internal REST API (webapplicationfactory)

useful references:

Integration-tests-with-webapplicationfactory https://andrewlock.net/exploring-dotnet-6-part-6-supporting-integration-tests-with-webapplicationfactory-in-dotnet-6/

HttpClient and testing https://adamstorr.azurewebsites.net/blog/test-your-dotnet-httpclient-based-strongly-typed-clients-like-a-boss

IHttpClientFactory vs HttpClient https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests

YOU'RE USING HTTPCLIENT WRONG AND IT IS DESTABILIZING YOUR SOFTWARE

kiquenet avatar Sep 01 '22 06:09 kiquenet