The title pretty much says it all, there is no way to open an MVC2 project within Visual Studio 2012, there is no “auto-upgrade” path either! If you attempt to convert a solution containing an MVC2 project you will probably see the following error message: Subtype: ‘{F85E285D-A4E0-4152-9332-AB1D724D3325}’ is unsupported by this installation. If you do, then the only real solution appears to be graft the existing MVC2 project into an empty MVC3 or MVC4 project . . .
I’ve just installed MVC3.0 on a fresh PC using the new web installer application and was surprised at how long it seemed to be taking. Digging around a bit deeper I remembered that in the options I’d selected to use IIS rather than IIS Express and taking a quick look at the service panel highlighted that IIS was currently stopped. I restarted IIS and the MVC3.0 installation finished in seconds! So if you’re having problems . . .
I recently asked this question on Stack Overflow. I was using reflection and MethodInfo to confirm that a controller contained an action with the required method parameters. If one was found, this would then allow my code to unit test that the correct Action Filter Attributes were being assigned to the controller action (so a particular action could only respond to an HTTP GET or POST as an example). This was all working fantastically well . . .
It is a shame that when the ASP.NET MVC framework was released they did not think to build IoC support into the infrastructure. All the major components of the MVC engine appear to magically inherit instances of HttpContext and it’s related objects – which can cause no end of problems if you are trying to utilise Unit Testing and IoC. Reading around various articles on the subject just to get around this one problem requires . . .
The code below defines an object that holds an instance of the Castle Windsor container and sets it up to handle all requests to resolve ASP.NET MVC Controllers. It also includes code to inject instances of HttpRequest and HttpContextBase. This means that you can define injected objects that contain references to HttpContextBase in their constructors (which can be your MVC controllers) and they will receive populated instances of these objects. It is worth noting that . . .
As I’ve previously mentioned anyone starting out with IoC and ASP.NET MVC quickly encounters problems injecting HttpContext and related classes into controllers, etc. A similar issue surrounds Action Filter Attributes but is not limited to just HttpContext as objects inheriting from ActionFilterAttribute must contain a “parameterless” default constructor. Without a “parameterless” constructor these objects can not be created when used to decorate a class or action declaration. Also, the MVC engine is responsible for the . . .
Having recently taken a look at NServiceBus, the first obstacle that I encountered was that it was not compatible with the version of Castle Windsor which we were using. Luckily due to the design of NServiceBus adding a new version of an IoC framework is relatively painless if you follow a couple of basic steps and follow the format laid out by the existing framework. Whilst the NServiceBus documentation say what you need to do, . . .
To fully test an MVC web site it is important to test (in isolation) the following: The behaviour of controller actions The behaviour of any custom action filters. The decoration of action filter attributes on controller actions. To test the 3rd point, you must use reflection to select the desired action from the controller. The following method takes an action name and a Tuple array of “Type” and “String”. Used together this combination should be . . .