Skip to content

An example project structure for testing an in-memory ASP.NET Core 2.1 server with WireMock.

Notifications You must be signed in to change notification settings

callumsteele4/WireMockInMemTestExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In-Memory Testing ASP.NET Core 2.1 with WireMock

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.

InMemTest

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.

Api.Test

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.

WireMock.Net

See here.

About

An example project structure for testing an in-memory ASP.NET Core 2.1 server with WireMock.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages