http://boos.audioboo.fm/swf/fullsize_player.swf
Loading video …
I was lucky enough to be interviewed by @robwilmot on his Entrepreneur Show yesterday. It was a great opportunity to share my views on how Nottingham is going to harness some of the current successes in the creative and technology scene to really cement is position as a leading centre for the UK.
Thanks to @pcmcreative for live streaming my talk at Nott Tuesday last night.
I needed to reference some user context variables from within my site master page that had some logic behind their retrieval.
In this example I need to choose the display language for a user.
The pattern I’ve ended up using is to implement a base view model from which all my specific view models inherit as follows:
public class BaseViewModel { public string UserLanguage { get { return HttpContext.Current.Request.Cookies["language"] != null ? HttpContext.Current.Request.Cookies["language"].Value : CultureInfo.CurrentCulture.TwoLetterISOLanguageName; } } }
I then use the generic class for the master page
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<BaseViewModel>" %>
Which then allows me to reference the model in the master page and keep the logic for deciding the language to display centralised.
Not sure I’m wholly happy with the inheritance as it adds a level of dependencies which smells a bit off but in the small application I’m working in it was easy to implement and does what I need.
This was to be my first foray into UI integration testing. I’ve always been a sceptic, scare by the brittleness of any kind of recorded UI test. Luckily Gemma and Jonathan in the dev team persisted and showed me Selenium RC and WatiN. Both these solutions allow you to write the integration tests in code, a critical requirement for me.
Also key for me was this had to work in Hudson, my chosen Continuous Integration server, so simple deployment and management was key. I love being able to check everything I need into source control and have it ‘miraculously’ run on the CI server with little or no config.
The first thing I needed was a deployable web server I could, ideally, run in process. Enter CassiniDev and specifically the CassiniDev4-Lib.dll. Now this was really tricky to get going
.
1. Add reference to CassiniDev4-Lib.dll
2. Put following code in my TestFixtureSetup
_hostServer = new CassiniDevServer(); _hostServer.StartServer(@"..\..\..\clubrd.web");
Selenium wasn’t quite so simple.
It failed the simple deploy requirement because you have to run the Selenium Server and then use the RC libraries to interact with it and send commands to then run on browsers.
It also has/d a bug where it sends a HEAD before it sends a GET which breaks if your MVC Controller Action as an HttpGet attribute. It sends a 404 because HEAD isn’t acceptable.
Sky from the CassiniDev team was über-helpful finding this out for me http://cassinidev.codeplex.com/Thread/View.aspx?ThreadId=227174.
WatiN was a different story though. Very simple to use and all run in process. There were a couple of gotcha’s though.
I had to make sure NUnit was properly running .net 4, stackoverflow helped me there http://stackoverflow.com/questions/2635794/nunit-fail-with-system-argumentexception-the-net-4-0-framework-is-not-available
And I got a rather gruesome COM exception when I pushed it all up to my CI server.
NSystem.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess) at WatiN.Core.IE..ctor(String url)
Luckily I found this post that talks through setting the COM permissions correctly for this kind of issue. Specifically giving the correct permissions to the user account used by the Hudson server. http://www.stuffthatjustworks.com/How+To+Fix+UnauthorizedAccessException+Retrieving+The+COM+Class+Factory+For+Component+With+CLSID.aspx
Early days, but I now have a green build that includes actually navigating to one of my forms and entering text within an integration test.
Selenium seemed to be the obvious choice for UI testing. I read somewhere that Google is throwing loads of effort into developing it so it would be a good horse to back. However, when I look at my requirements I don’t need what Selenium offers.
Multi, cross-browser testing is nice but I’m just looking to confirm stories are operational and routes through my application are valid. The simplicity of WatiN seems to satisfy that nicely.