private void RegisterFactories()
        {
            //Create a custom controller factory to resolve controllers with IoC container
            IControllerFactory factory = new IoCControllerFactory(_CurrentContainer);

            //Set new controller factory in ASP.MVC Controller builder
            ControllerBuilder.Current.SetControllerFactory(factory);
        }
 public void Get_Controller_Instance_Throws_Null_Reference_Exception_When_The_Controller_Type_Is_Null()
 {
     //Arrange
     SIContainer serviceFactory = new SIContainer();
     HomeController controller = new HomeController();
     serviceFactory.ResolveType = x => controller;
     
     
     IoCControllerFactory controllerFactory = new IoCControllerFactory(serviceFactory);
     
     MDefaultControllerFactory baseMole = new MDefaultControllerFactory(controllerFactory);
     
     IoCControllerFactory_Accessor factoryAccessor = new IoCControllerFactory_Accessor(new PrivateObject(controllerFactory));
     baseMole.CreateControllerRequestContextString = (context, name) => factoryAccessor.GetControllerInstance(context, null);
     
     //Act
     HomeController resolvedController = controllerFactory.CreateController(null, "Home") as HomeController;
 }
        public void Get_Controller_Instance_Returns_The_Right_Controller()
        {
            //Arrange
            SIContainer container = new SIContainer();
            
            HomeController controller = new HomeController();
            
            container.ResolveType = x =>controller;
            
            IoCControllerFactory controllerFactory = new IoCControllerFactory(container);
            
            MDefaultControllerFactory baseMole = new MDefaultControllerFactory(controllerFactory);
            //Create a MSTest accessor to access GetControllerInstance

            IoCControllerFactory_Accessor factoryAccessor = new IoCControllerFactory_Accessor(new PrivateObject(controllerFactory));
            
            baseMole.CreateControllerRequestContextString = (context, name) => factoryAccessor.GetControllerInstance(context,typeof(HomeController));
            
            //Act
            HomeController resolvedController = controllerFactory.CreateController(null, "Home") as HomeController;

            //Assert
            Assert.AreSame(controller, resolvedController);
        }