Simon Harriyott

Ninject Controller Testing

I've been converting an old, large project to use NInject to inject services and repositories into my controllers, removing the base controller's code that newed them up. I wrote a handy unit test to make sure all the bindings worked for the controllers' constructors, which caught a few missing bindings before it passed.

public void Can_create_controllers()
    var kernel = new StandardKernel();

        .Where(t => typeof(Controller).IsAssignableFrom(t))
        .ForEach(c => kernel.Get(c));

24 October 2013