Skip to main content

Posts

Showing posts from August, 2015

Code As Data With Reflection

Other than occasional use, working with reflection using C# isn't something I've had that much need to do. Recently though I was working on an additional feature for the Umbraco package The Dashboard . It provides a nice first screen for editors, showing their recent edits and other work carried out on the site content. The idea for the new feature was to create a developer version of this, that displayed various details about the code that had been implemented on the project. The use case being in the case of inheriting or coming back to a site, being able to have a quick overview of the techniques that have been used for route hijacking, surface controllers, application events and the like. In order to implement this it was going to be necessary to make quite heavy use of reflection and this post highlights a few of the methods used. Getting instances of types In the case of Umbraco route hijacking using custom controllers it's necessary to implement an MVC con

(Yet) Another Look at Unit Testing Umbraco Surface Controllers

A quick recap A little while back now I spent a bit of time investigating how one might go about unit testing Umbraco surface controllers . With the help of information posted by some others that had similarly looked into it I found there was a method that worked, but it wasn't ideal for a number of reasons. Firstly there was a need to utilise an Umbraco test helpers dll , that contained implementations of various base classes that could be used to support testing. No great hardship to use that but it did mean you had to compile the source to get it and it led to some other restrictions on your tests. One of those being you had to use NUnit . Again, a perfectly decent test runner but if you generally used MSTest or something else you had to make a switch. And lastly in order to create various surface controller dependencies, you had to use some rather impenetrable looking reflection code to get around the fact that certain classes and methods were marked as internal rat