This folder contains a sample ASP.NET Core application that uses the JustEat.HttpClientInterception
NuGet package for testing its dependencies on other APIs.
The application (/samples/SampleApp
) exposes a single HTTP resource at GET api/repos
.
This resource consumes the GitHub v3 API and returns the names of the public repositories belonging to the configured user/organisation as a JSON array of strings. For example:
[
"JustBehave",
"JustSaying",
"JustEat.RecruitmentTest"
]
To enable use of JustEat.HttpClientInterception
for testing, the application has a small number of minor changes:
- An extension method that registers
HttpClient
as a transient dependency using any registeredDelegatingHandler
implementations. HttpClient
is registered in theStartupBase
class.HttpClient
is injected into the constructor ofReposController
The tests (/samples/SampleApp.Tests
) self-host the application using Kestrel so that the application can be tested in a black-box manner by performing HTTP requests against the API's GET
resource.
This is enabled by:
- An xunit collection fixture that self-hosts the server at
http://localhost:5050
. - Creates a shared
HttpClientInterceptorOptions
instance which is registered to provide aDelegatingHandler
implementation for use with Dependency Injection. - Using
JustEat.HttpClientInterception
to intercept HTTP calls to the GitHub API to test the API resource.