Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Created October 7, 2012 20:43
Show Gist options
  • Save wadewegner/3849535 to your computer and use it in GitHub Desktop.
Save wadewegner/3849535 to your computer and use it in GitHub Desktop.
This is a short test that will ensure that controller dependencies are bound appropriately for Ninject. For this to work, you either have to make the bootstrapper public or mark it internal and add the InternalsVisibleTo attribute to the assembly.
[Test]
public void ensure_controller_dependencies_are_bound()
{
var assemblyName = "MvcApplication4";
var assembly = Assembly.Load(assemblyName);
var parameters = (from type in assembly.GetTypes().Where(
t => t.IsAbstract == false && typeof (Controller).IsAssignableFrom(t))
from constructor in type.GetConstructors()
from parameter in constructor.GetParameters()
select parameter).ToList();
NinjectWebCommon.Start();
foreach (var bindings in parameters.Select(
parameter => NinjectWebCommon.bootstrapper.Kernel.GetBindings(parameter.ParameterType)))
{
Assert.IsTrue(bindings.Count().Equals(1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment