Commands, queries and testing

Also read: Self-contained commands with dependencies Separating command data from logic and sending it on a bus We need abstraction, but the amount of abstraction we really need depends, and should be assessed on a case-by-case basis. It seems advisable to grow abstractions, and to introduce them gradually. That being said, in this post I want to talk about an architecture that tries to limit abstractions to solely commands and queries. ...

October 14, 2012 · 5 min · Jef Claes

Supporting the OPTIONS verb in ASP.NET Web API

ASP.NET Web API controllers support only four HTTP verbs by convention: GET, PUT, POST and DELETE. The full list of existing HTTP verbs is more extensive though. One of those unsupported verbs which can be particularly useful for API discovery and documentation is the OPTIONS verb. The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval. ...

September 2, 2012 · 3 min · Jef Claes

Should I unit- or integration test my ASP.NET Web API services?

Over the last two weeks, preparing for a talk, I have been doing some research on ASP.NET Web API. After working my way through the API, and the implementation of certain features, I looked at testing. Similar to ASP.NET MVC, Web API allows you to create relatively small building blocks, which can replace parts of, or be added to an existing default global setup. This makes it possible for us to test each component in isolation: controllers, dependency resolvers, filters, serialization, type formatters, messagehandlers and routing. ...

July 15, 2012 · 4 min · Jef Claes

HtmlHelper to generate a top-level menu for areas

Last week, we had to set up a new ASP.NET MVC web application, using a somewhat customized Twitter Bootstrap build. Because the application has multiple functional contexts, we divided it in multiple parts using areas. Since these areas were a one-to-one mapping with the top-level menu items, we tried abstracting the creation of the menu items, ánd the management of setting the active item, into an HtmlHelper. Let’s say, for this example, that we have six areas: Images, Maps, Play, Search, Video and Blog, and we want to render a list item for each one of them. ...

July 8, 2012 · 3 min · Jef Claes

Persisting model state when using PRG

I’ve been working on an ASP.NET MVC application in which we frequently apply the Post/Redirect/Get pattern. One of the direct consequences of applying this pattern is that you often want to persist the model state across redirects, so that you don’t lose validation errors, or the values of input fields. To persist the model state across redirects, we can put TempData to work. The sole purpose of TempData is exactly this; persisting state until the next request. ...

June 17, 2012 · 2 min · Jef Claes

Making my first NancyFx test pass

Like I already said last week, I have been dabbling a bit with NancyFx lately. This week I took a serious look at testing Nancy modules and Razor views. Due to Nancy’s defaults and conventions, it takes a little while to set up Nancy in a test context. Then again, Nancy’s granularity makes it simple enough to set up a solid test infrastructure by replacing some of its building blocks. Like always, I had to go through several iterations to get it right. ...

June 11, 2012 · 4 min · Jef Claes

Painless database logging with mongoDB

While browsing the source code of the ELMAH mongoDB provider, I learned about a special type of collections: capped collections. From the mongoDB documentation: Capped collections are fixed sized collections that have a very high performance auto-FIFO age-out feature (age out is based on insertion order). In addition, capped collections automatically, with high performance, maintain insertion order for the documents in the collection; this is very powerful for certain use cases such as logging. ...

May 20, 2012 · 2 min · Jef Claes

Some Servicelocator pattern stinks

I have been working on a somewhat legacy codebase which makes use of the Servicelocator pattern. Although I always thought of Dependecy Injection to be the superior pattern, I was pleased to find some Inversion of Control implementation in there. Working with the codebase, I discovered first hand how easily, when used without caution and discipline, the Servicelocator pattern can introduce code rot. I will walk you through some of the issues I have with the Servicelocator pattern, mostly looking at it from a test perspective. It’s interesting how you can often quickly discover friction in a codebase by just looking at, or writing, tests. ...

April 17, 2012 · 4 min · Jef Claes

Visualizing the offline application cache update progress

I wrote about using the HTML5 application cache earlier, mostly focusing on generating and serving the manifest file using ASP.NET MVC. I also bitched about how not one browser I know of gives an indication of the application cache update progress. Today I wanted to write something about how you can visualize the application cache update progress yourself. The applicationCache API has several useful and rather straightforward events we can handle to inform the user of the update progress. ...

April 11, 2012 · 3 min · Jef Claes

Check for local file browsing with JavaScript

Because I do most of my research while commuting by train, I often pull entire websites offline using httrack. While browsing the [jQuery Mobile documentation](http://jquerymobile.com/demos/1.1.0-rc.1/ locally this morning, I stumbled upon following gem. I was curious to see how they determine whether a page is browsed locally or not. Looking into the source, I was a bit dissapointed to find nothing but plain common sense. The trick is comparing the protocol of the current location with known local protocols. ...

April 2, 2012 · 1 min · Jef Claes