Esempio n. 1
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. 2
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. 3
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. 6
0
            public void Should_throw_if_controllerName_is_null()
            {
                IControllerFactory controllerFactory = new IoCControllerFactory(_dependencyResolver);

                controllerFactory.CreateController(null, null);
            }