Demonstrates how to run integration tests with one API calling another API.
The main magic, and purpose of this repository, is in running the tests.
dotnet test
Output should be along these lines:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Test Run Successful.
Total tests: 2
Passed: 2
Total time: 2,0962 Seconds
This is magical because it:
- Spins up an in-memory
BarApi
server - Spins up an in-memory
FooApi
server - Overwrites the "typed HttpClient"
BarService
DI registration forFooApi
(with a specialHttpClient
injected that "secretly" routes HTTP to the in-memoryBarApi
) - Runs a test that calls
FooApi
, which calls theBarApi
via aHttpClient
towards the second in-memory API
This is in contrast with FooApi
calling a running BarApi
.
The APIs mimick a "real" setup. You can also test this real setup by:
dotnet run -p SampleDuoApis.BarApi/SampleDuoApis.BarApi.csproj
dotnet run -p SampleDuoApis.FooApi/SampleDuoApis.FooApi.csproj
- Then
curl http://localhost:5002
This calls the running FooApi
(at port 5002
), which in turn calls BarApi
(at port 5000
).
In short: Foo
is a "facade" for Bar
.