Esempio n. 1
0
        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);
        }
Esempio n. 2
0
            public void And_default_resolver_is_null_then_ReleaseImplementation_should_not_be_called_on_the_default_resolver()
            {
                DependencyResolver.InitializeWith(null);
                var controller = new IocTestController();

                IControllerFactory factory = new IoCControllerFactory();

                factory.ReleaseController(controller);
            }
Esempio n. 3
0
            public void And_controller_implements_IDisposable_then_dispose_should_be_called()
            {
                var controller = new DisposableIocTestController();

                IControllerFactory factory = new IoCControllerFactory(_dependencyResolver);

                factory.ReleaseController(controller);

                Assert.IsTrue(controller.IsDisposed);
            }
Esempio n. 4
0
            public void Then_ReleaseImplementation_should_be_called_on_the_specified_resolver()
            {
                var controller = new IocTestController();

                _dependencyResolver.Expect(r => r.DisposeImplementation(controller));

                IControllerFactory factory = new IoCControllerFactory(_dependencyResolver);

                factory.ReleaseController(controller);
            }
Esempio n. 5
0
        static 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);

            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(_CurrentContainer);
        }
Esempio n. 6
0
            public void Then_ReleaseImplementation_should_be_called_on_the_default_resolver()
            {
                DependencyResolver.InitializeWith(_dependencyResolver);
                var controller = new IocTestController();

                _dependencyResolver.Expect(r => r.DisposeImplementation(controller));

                IControllerFactory factory = new IoCControllerFactory();

                factory.ReleaseController(controller);
            }
Esempio n. 7
0
            public void Should_throw_if_controller_type_cannot_be_resolved()
            {
                var requestContext = new RequestContext(MvcMockHelpers.DynamicHttpContextBase(), new RouteData());

                //HttpException(0x194,
                IControllerFactory controllerFactory = new IoCControllerFactory(_dependencyResolver);

                controllerFactory.InitializeWithControllerTypes(typeof(IocTestController));

                controllerFactory.CreateController(requestContext, "DoesNotExist");
            }
Esempio n. 8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AutoMapperConfig.RegisterMapping();
            var controllerFactory = new IoCControllerFactory(DependencyConfig.RegisterTypes());

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
        }
Esempio n. 9
0
            public void Should_call_into_the_static_resolver_to_create_a_controller()
            {
                var requestContext = new RequestContext(MvcMockHelpers.DynamicHttpContextBase(), new RouteData());

                IControllerFactory controllerFactory = new IoCControllerFactory();

                controllerFactory.InitializeWithControllerTypes(typeof(IocTestController));

                IController controller = controllerFactory.CreateController(requestContext, "IocTest");

                Assert.That(controller, Is.TypeOf(typeof(IocTestController)));
            }
Esempio n. 10
0
            public void Should_call_into_the_resolver_to_create_a_controller()
            {
                var requestContext = new RequestContext(MvcMockHelpers.DynamicHttpContextBase(), new RouteData());

                _dependencyResolver.Expect(r => r.GetImplementationOf <IController>(typeof(IocTestController)))
                .Return(new IocTestController());

                _dependencyResolver.Replay();

                IControllerFactory controllerFactory = new IoCControllerFactory(_dependencyResolver);

                controllerFactory.InitializeWithControllerTypes(typeof(IocTestController));

                IController controller = controllerFactory.CreateController(requestContext, "IocTest");

                Assert.That(controller, Is.TypeOf(typeof(IocTestController)));
                _dependencyResolver.VerifyAllExpectations();
            }
        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);
        }
Esempio n. 13
0
            public void Should_throw_if_controllerName_is_null()
            {
                IControllerFactory controllerFactory = new IoCControllerFactory(_dependencyResolver);

                controllerFactory.CreateController(null, null);
            }
Esempio n. 14
0
 public void Should_throw_an_argument_null_exception_when_the_resolver_is_null()
 {
     IControllerFactory controllerFactory = new IoCControllerFactory(null);
 }