Stubbing your way to automated end to end testing in an API first world

Building high quality end to end acceptance tests suites is hard, and creating API stubs (aka mock servers) can be surprisingly time consuming. WireMock.net can help speed this up. E2E testing is hard End to end testing is hard for many reasons, but I think one of the most common is that the developers under estimate how much time to allow for it and then rush the job. Most E2E test harnesess I have worked on, (including several I wrote myself!...

December 4, 2017 · 7 min · 1476 words · Alastair Crabtree

Choose the right return type for WebApi controllers

WebApi controller actions can return a variety of response types: HttpResponseMessage, IHttpActionResult, CLR objects and then the Task based variety of each for async actions. But which one is best? And how do we unit test them? Lets look at each in turn and examine why IHttpActionResult is usually the right choice. Synchronous controllers returning objects The simplest web api controller can directly return the object in question. Say you have a ProductController that is concerned with CRUD operations on Products, it might have a method like the below:...

May 30, 2016 · 4 min · 661 words · Alastair Crabtree

Encrypting configuration files in asp.net during deployment

Assuming you are running your asp.net website on windows and IIS it is possible to encrypt your web.config file with a little bit of scripting during your website deployment. However I would always ask why do you want to do this? IIS will not serve this file by default and if you are sensible your production websites file system should be well secured already. But assuming you have a good reason, here is how....

December 14, 2015 · 2 min · 383 words · Alastair Crabtree