This is an example project structure for testing an in-memory ASP.NET Core 2.1 server with WireMock.
Testing with an in-memory server and WireMock allows you to ensure that you are testing only your application, and not also the web APIs the application depends on.
This is the ASP.NET Core 2.1 API which we will be testing.
It contains two controllers, UsersController.cs and PostsController.cs, which expose simple actions to retrieve either a User or a Post.
These controllers call clients, registered in the Startup.cs, which take their configuration from appsettings.json.
These clients are pointing at JSONPlaceholder which provides some dummy user and post data.
This is the test project, through which we are testing the controllers.
Each controller has a respective test class, see UsersControllerTests.cs and PostsControllerTests.cs respectively.
These test classes share a Collection Fixture, which allows them to share a common context.
The context in this case is held in WireMockFixture, which contains a reference to a HttpClient with which to call our in-memory server, as well as the two WireMock servers we are using.
To ensure that http calls will go to our WireMock servers, as opposed to JSONPlaceholder, the configuration for our in-memory server is modified in WireMockWebApplicationFactory.cs. Here we provide alternative base addresses for the users and posts clients.
See here.