Coding and Dismantling Stuff

Don't thank me, it's what I do.

About the author

Russell is a .Net developer based in Lancashire in the UK.  His day job is as a C# developer for the UK's largest online white-goods retailer, DRL Limited.

His weekend job entails alternately demolishing and constructing various bits of his home, much to the distress of his fiance Kelly, 3-year-old daughter Amelie, and menagerie of pets.

TextBox

  1. Fix dodgy keywords Google is scraping from my blog
  2. Complete migration of NHaml from Google Code to GitHub
  3. ReTelnet Mock Telnet Server à la Jetty
  4. Learn to use Git
  5. Complete beta release FHEMDotNet
  6. Publish FHEMDotNet on Google Code
  7. Learn NancyFX library
  8. Pull RussPAll/NHaml into NHaml/NHaml
  9. Open Source Blackberry Twitter app
  10. Other stuff

How To Test Your MVC3 Model Validation and Controller Logic

Hi all,

Today, I've come across some code that's testing an MVC controller to ensure that the controller responds correctly if the model passed in is invalid. This sounds a good plan - except that you need to be mindful that your controller doesn't validate your model! Your view model is validated by a separate class, the ModelBinder, that fires up just before your controller is executed. This ModelBinder is built into the MVC engine, you can bet that it's been tested a zillion times by a zillion other devs, so you definitely don't want to find some way to test this ModelBinder directly.

So what to do? Let's take a look at the original test, exactly what code we've written, and so what we want to test.

More...


Permalink | Comments (1)