Thursday 11 October 2012

Unit tests that rely on URLHelper

This looks like it will be useful. http://weblogs.asp.net/cibrax/archive/2012/10/10/unit-testing-asp-net-web-api-controllers-that-rely-on-the-urlhelper.aspx

Tuesday 25 September 2012

Get the value of an adjacent cell with jQuery

   1:   var row = $(this).closest('tr');
   2:   var description = row.find('td:eq(1)').text();
   3:   var code = row.find('td:eq(0)').text();

Thursday 16 August 2012

Using IMappingEngine with Castle Windsor

I must remember this

container.Register(Component.For<IMappingEngine>().UsingFactoryMethod(()=> Mapper.Engine));


From http://stackoverflow.com/questions/1719725/inject-automapper

Saturday 14 July 2012

Stop EF looking for migration tables

I keep forgetting how to do this should I’ll post it here.

Database.SetInitializer<DataContext>(null);

Thursday 1 March 2012

Localisation of built in MVC validation messages

While working on web site for a client in Belgium I was wondering why the Required attribute error message wasn’t being localised based on the CurrentUICulture of the thread.

This was bugging me, so I downloaded the MVC 3 source code from CodePlex and found the Required attribute unit test.  Even after changing the thread to use Flemish the below test still passed.

image 

After talking to Damian we found that there are Language Packs for .NET 4.  These can be obtained from http://www.microsoft.com/download/en/details.aspx?id=3324

These packs will install the required resources in you .Net 4 framework directory.
image

As soon as I installed the Dutch language pack the above test failed as expected.

image

I still need to test what gets stored in the logs when these packs are installed and an exception is thrown.  It won’t help us much if errors in the logs start getting stored in the language of the user that is logged in.

Friday 13 January 2012

Dynamically add required attribute for MVC3 jQuery unobtrusive

 

While you can add the data-val attributes for MVC client side validation by default MVC unobtrusive validation won’t process them.

What you have to do is remove the validators and re-add them.

   1:  $("#Password").attr("data-val-required", "Password is required");
   2:  $("form").removeData("validator");
   3:  $("form").removeData("unobtrusiveValidation");
   4:  $.validator.unobtrusive.parse("form");