On Thu, 29 Jun 2017 08:54:02 GMT, Trezker wrote:

I have googled and tried for some time now but can't figure out how to test my HTTP request handlers.

I found the functions createTestHTTPServerRequest and createTestHTTPServerResponse, so I can make a call to the handler.

But I have not been able to figure out how to send the post content with the request or how to get the response content out for verification.

I'm surprised I have not been able to find examples of this. Isn't anyone testing their handlers? Or is my google foo that bad?

Current architecture is not testable and filled with black magic. Trying to make it more or less appropriate, I had to drop almost all services and magic methods and implement my own, usable for modular and testable architecture. So for the current moment, my web interfaces are just gates to my own components, like this:

...
void getChanneldown(HTTPServerRequest request, HTTPServerResponse response)
{
	import vcm.page.channeldown;
	auto page = scoped!ChanneldownPage(PageContext(&request, &response));
	page.render; 
}

void getRegister(HTTPServerRequest request, HTTPServerResponse response)
{    	
	auto page = scoped!(PublicPage!"registerForm.dt")(PageContext(&request, &response));
	page.render; 
}
...

So you can do the same: make handlers as separate objects called with explicit parameters and test it.