Created
October 7, 2012 20:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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