Testing Strategies – Opinionated Advice

As developers we routinely work with code that is not our own, commonly in the form of third party APIs and application frameworks. This post discusses the scenario that almost every developer is likely to encounter at some stage in their career, namely what to do when you have to work with an API or framework dependency that makes unit testing seem impossible.

Faced with the prospect of developing code against a framework that doesn’t easily lend itself to unit testing you generally have a number of options.

The first and obvious choice for some is to abandon the idea of unit testing for part or all of the code that you have written. The reasoning here is, why the hell should I bother to test my code if the framework code lacks the same rigour. After all it’s not your fault, you can always blame the framework developers for painting you into this corner. This attitude is not exactly going to guarantee you a place amongst the great and good of Software Craftsmanship. The facts are that you, as a software professional, are responsible for verifying the code that you write. It is you who will ultimately have to support the code you write when it gets to production, giving you a great motivation to ensure that it functions correctly. Continue reading

MVC Areas in Sitecore

Areas have been a part of ASP.NET MVC since ASP.NET MVC 2 shipped in 2010. This walkthrough article from MSDN sums up why areas are useful in MVC web applications. A brief extract follows:

To accommodate large projects, ASP.NET MVC lets you partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas).

For example, a single large e-commerce application might be divided into areas that represent the storefront, product reviews, user account administration, and the purchasing system. Each area represents a separate function of the overall application.

The release of Sitecore 6.6 saw the introduction of support for MVC and the Razor view engine within the Sitecore CMS. It wasn’t long before a question popped up on stackoverflow asking how to wire up a Sitecore Controller Rendering to a controller located within a MVC Area.

Hopefully this article will provide some answers for those wanting to use MVC Areas with Sitecore and highlight a few of the subtleties that currently may not be so well documented.

Doing the Simplest Thing

Continue reading

Setting Up a Local NuGet Gallery

For a while now I’ve been wanting to hook up our continuous integration process with a local NuGet gallery. The basic idea is for the build process to produce NuGet packages containing components that are used across a number of internal developments. These packaged up components would then be published to a local NuGet gallery where the packages could be located by internal developers and pulled down into projects in Visual Studio that have a dependency on those components. Jetbrains announcement of native support for NuGet within their TeamCity application made this integration even more attractive.

At the time of writing the NuGet documentation on setting up a local gallery server is a little out of date, referring to an older version of the gallery. What follows is a simple set of instructions on getting a local gallery setup. Continue reading

ICO advice available on EU’s Cookie Legislation

The Information Commissioner’s Office (ICO) has issued it’s advice on the EU’s Privacy and Electronic Communications Directive that comes into effect on 26th May 2011.

Under the new regulations web sites will not be able to simply rely on the do-not-track browser settings present in Firefox and IE9 in order to comply with the new law, the ICO has said.

The full report can be found on the ICO’s website.

The ICO has yet to publish it’s guidance on how the new regulations are to be enforced, but states:

The key point is that you cannot ignore these rules.

 

Don’t Give Me No Blue Sky Rubbish

I’ve read a fair number of books on software development over the years but the one that has made the most difference to me was I. M. Wright’s ‘Hard Code’. Amazon’s summary states ‘Get the brutal truth about coding, testing, and project management—from a Microsoft insider who tells it like it is’. Fair comment.

Back in the day we had Ed Yourdon telling us all about  Death March  projects and Steve McConnell‘s Code Complete as a self defense guide to how to avoid getting stuck on one.


These days I’ve got Eric Brechner’s blog to provide me with an up-to-date insight into the software development process and it’s incumbant pitfalls. Eric’s hard bitten perspective and practical advice ought to provide enough ammunition for even the most jaded Dilbert devotee to start sorting out their:

  • Career
  • Project
  • Manager [sic]
  • Department / Company

IMHO if ‘Hard Code’ doesn’t speak to you, you’re most likely in the wrong industry.

One final cautionary note, the ‘Hard Code’ blog doesn’t deal in ‘Blue Sky Thinking’ and offers little to those looking to ‘Land their Vision’, those individuals best look elsewhere for what they seek.

ReSharper friendly Visual Studio colour scheme

Looking for a dark visual studio style that’s not high contrast, easy on the eye for all day use and best of all ReSharper friendly then take a peek at Selenitic created by Tim G. Thomas.

Selenitic colour scheme screenshot 

This is just one of many Visual Studio styles available for download at http://studiostyl.es/ a great community site for creating and sharing Visual Studio colour schemes.

Sitecore content tree indexed by Search Engines

Have you noticed that your Sitecore content tree may be indexed by search engines?

Try searching for “/sitecore/content/” in your favourite search engine. When I entered this into Bing the third link that I was shown was:

www.rfu.com

http://www.rfu.com/sitecore/content.aspx

Clicking on the link takes you to a Page Error message on the RFU site as there’s no layout associated with the content item. The url shown in the browser address bar is:

http://www.rfu.com/error?item=%2fsitecore%2fcontent&layout=%7b00000000-0000-0000-0000-000000000000%7d&device=Default

Presumably having content indexed by search engines under two separate url’s on a site isn’t going to be too good for your SEO rankings unless appropriate action is taken.

One way that I found of successfully dealing with this problem was to add the following to the sites robots.txt file:

User-agent: *
Disallow: /Sitecore/

Can anyone offer a good explanation of what is allowing the structure of the Sitecore CMS’s content tree to be indexed by the search engines?

HTTP 304 response handling in Sitecore MediaRequestHandler

Whilst testing a Sitecore 6.1 site due for release Firebug highlighted some unexpected behaviour from the Sitecore Media Request Handler which takes care of responding to requests for items held in the Sitecore Media Library. Media library items were being returned in full every time that they were requested, each returning a HTTP 200 response status code.

Further digging with Lutz Roeder’s excellent Reflector tool showed that the If-Modified-Since request header field was not being responded to correctly by the MediaRequestHandler. The If-Modified-Since request header is a HTTP-date value whose time component is in the format HH:MM:SS (i.e. no milliseconds). This header field value is used by the Modified method within the MediaRequestHandler to compare to the System.DateTime value that the media library item was last updated. As a System.DateTime value includes a milliseconds component the equality check fails for the majority of media library requests and as a result the item is downloaded to the browser in full.

Sitecore have confirmed that this is a known issue and something that will be fixed in a forthcoming release. In the meantime it’s not difficult to patch in a modified HTTP handler to respond to media library requests and implement HTTP 304 response handling appropriately. Alex de Groot has a good article on his blog that explains how Sitecore interacts with HTTP handlers for media handling.