Accessing the request-and-response object with the JsonServiceClient
ServiceStack provides many tools that allow a developer to access REST
services. These tools can be very useful in building automated tests that can increase developer confidence with the solution being developed.
From time to time, you might need to test for the presence of a specific header in a response or to simulate a client that provides a specific header in a request. JsonServiceClient
allows you to customize a request header before sending it and to access the raw response object as it is received in order to make assertions about the status of the request and response.
Getting ready
While this technique is easy once you know the trick, it can take a bit of hunting around. We can show the power of request and response filters in a simple testing scenario. We'll start off with a JsonServiceClient
object like in the following code:
var client = new JsonServiceClient("http://localhost:28192");