Skip to content

jeroenheijmans/sample-asp-net-core-integration-tests-for-duo-apis

Repository files navigation

Sample Duo APIs with Integration Tests

Demonstrates how to run integration tests with one API calling another API.

Tests

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:

  1. Spins up an in-memory BarApi server
  2. Spins up an in-memory FooApi server
  3. Overwrites the "typed HttpClient" BarService DI registration for FooApi (with a special HttpClient injected that "secretly" routes HTTP to the in-memory BarApi)
  4. Runs a test that calls FooApi, which calls the BarApi via a HttpClient towards the second in-memory API

This is in contrast with FooApi calling a running BarApi.

Running

The APIs mimick a "real" setup. You can also test this real setup by:

  1. dotnet run -p SampleDuoApis.BarApi/SampleDuoApis.BarApi.csproj
  2. dotnet run -p SampleDuoApis.FooApi/SampleDuoApis.FooApi.csproj
  3. 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.

About

Integration tests for two APIs calling eachother

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages