Skip to content

Instantly share code, notes, and snippets.

@ianfnelson
Created September 18, 2014 12:14
Show Gist options
  • Save ianfnelson/287b94e1e565e3ee7137 to your computer and use it in GitHub Desktop.
Save ianfnelson/287b94e1e565e3ee7137 to your computer and use it in GitHub Desktop.
Snippets for 2010 blog post "Testing IoC Registrations"
AutoMapper.Mapper.AssertConfigurationIsValid();
[ClassInitialize]
public static void MyClassInitialize(TestContext testContext)
{
var guyWire = new GeneralGuyWire();
guyWire.Wire();
}
/// <summary>
/// Tests that the IoC container can resolve instances of each Controller.
///
/// Assuming that constructor DI is used throughout the system, this will
/// indirectly test that all dependencies have been correctly registered.
/// </summary>
[TestMethod]
public void Wire_CanResolveAllControllers()
{
Assembly
.GetAssembly(typeof(HomeController))
.GetExportedTypes()
.Where(t => MvcContrib.ControllerExtensions.IsController(t))
.ForEach(c => Assert.IsNotNull(ServiceLocator.Current.GetInstance(c)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment