title: MVC 4 Unity Container and NUnit Test
body: <p>I need some help setting up an NUnit test for a ASP.net MVC 4 application using Unity Container.</p>
  
  <p>I am using a bootstrapper class file to create the Unity Container.  </p>
  
  <p>Bootstrapper class:</p>
  
  <pre><code>public static class Bootstrapper
    {
      public static IUnityContainer Initialise()
      {
        var container = BuildUnityContainer();
  
        DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  
        return container;
      }
  
   private static IUnityContainer BuildUnityContainer()
      {
        // Create a new Unity dependency injection container
        var container = new UnityContainer();
  
        // register all your components with the container here                
        container.RegisterType&lt;ICustomerRepository, CustomerRepository&gt;();
        RegisterTypes(container);
  
        return container;
      }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public class CustomerController : Controller
      {
  
          readonly ICustomerRepository repository;
  
          public CustomerController (ICustomerRepository repository)
          {
              this.repository = repository;
          }
  
          public ViewResultIndex()
          {
  
              var data = repository.GetAll();
              return View(data);
          }
  
      }
  </code></pre>
  
  <p>NUnit Test Project :</p>
  
  <pre><code>[TestFixture]
      class CustomerUnitTests
      {
  
  
          [Test]
          public void Customer_Index_Returns_ViewResult()
          {
              //Arrange 
              CustomerController controller = new CustomerController();
  
              //ACT 
              var actual = controller.Index();
  
              //Assert 
              Assert.IsInstanceOf&lt;ViewResult&gt;(actual);
          }
  
      }
  </code></pre>
  
  <p>I am uncertain how to pass in the ICustomerRepository to the CustomerController constructor in the NUnit test project.  </p>
  
  <p>Thanks in advance!!</p>