Skip to content
Hugo Biarge edited this page Feb 3, 2019 · 2 revisions

Acheve.TestHost

This library try to solve some common issues when doing integration tests with AspNetCore.TestHost

Security

Most Http API's are protected with some authentication scheme that ensures only authenticated users can send requests to the API. In many cases they are protected by JWT tokens that some server should issue.

Acheve.TestHost implements an authentication middleware and several extension methods to easily indicate the claims for authenticated calls to the API, so it becomes very easy to test scenarios related to authentication and authorization.

Routing

Other important aspect in integration tests is maintain the URI endpoints you want to test. Usually you end with code like this:

var request = _server.CreateRequest("api/values/public");
var response = await request.GetAsync();

where you write the endpoint hardcoded in the test or in a static class that maintain all the URI's in the same class.

This has several problems:

  1. If any route convention is changed all integration test will fail
  2. If you refactor any parameter order the integration test will fail
  3. It is difficult to navigate to the action method that manages the request

With Acheve.TestHost you can create the URI dynamically using the attribute routing directly from your controllers.

var request = _server.CreateHttpApiRequest<ValuesController>(controller=>controller.PublicValues());
var response = await request.GetAsync();
You can’t perform that action at this time.