I ran into the same problem and ended up writing my tests as integration tests at a much higher level, actually making real REST / HTTP calls through a simple HttpWebRequest client. This allowed me to check the headers / status codes of the HTTP response and double check the serialization of JSON / XML from the client's point of view, which was as important as successful operations.
I started by returning OperationResult from all of my handlers and used them to wrap strongly typed objects. My handlers all inherit from the base class with a few helper methods that make it easy to return a custom error with a convenient error message. The more I encoded this, the more my handlers resembled an ASP.NET MVC controller. eg:.
public OperationResult GetById(int id) { try { // do stuff here return OKResult( // some strongly-typed resource ); } catch(SomeException ex) { return BadRequestResult(SomeErrorCode, ex.Message); } }
Then, in the test client, it is quite simple to check the HTTP status code. Obviously, this doesnβt really help make fun. I'm not sure what the best solution is, in fact, I preferred this question in the hope that someone will answer it better than I can, but it has worked for me so far.
source share