コード例 #1
0
        protected internal virtual void ProcessRequest(HttpContextBase httpContext)
        {
            AddVersionHeader(httpContext);

            // Get the controller type
            string controllerName = RequestContext.RouteData.GetRequiredString("controller");

            // Instantiate the controller and call Execute
            IControllerFactory factory    = ControllerBuilder.GetControllerFactory();
            IController        controller = factory.CreateController(RequestContext, controllerName);

            if (controller == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              MvcResources.ControllerBuilder_FactoryReturnedNull,
                              factory.GetType(),
                              controllerName));
            }
            try {
                controller.Execute(RequestContext);
            }
            finally {
                factory.ReleaseController(controller);
            }
        }
コード例 #2
0
        private void ProcessRequestInit(HttpContextBase httpContext, out IController controller, out IControllerFactory factory)
        {
            // If request validation has already been enabled, make it lazy. This allows attributes like [HttpPost] (which looks
            // at Request.Form) to work correctly without triggering full validation.
            // Tolerate null HttpContext for testing.
            HttpContext currentContext = HttpContext.Current;

            if (currentContext != null)
            {
                bool?isRequestValidationEnabled = ValidationUtility.IsValidationEnabled(currentContext);
                if (isRequestValidationEnabled == true)
                {
                    ValidationUtility.EnableDynamicValidation(currentContext);
                }
            }

            AddVersionHeader(httpContext);
            RemoveOptionalRoutingParameters();

            // Get the controller type
            string controllerName = RequestContext.RouteData.GetRequiredString("controller");

            // Instantiate the controller and call Execute
            factory    = ControllerBuilder.GetControllerFactory();
            controller = factory.CreateController(RequestContext, controllerName);
            if (controller == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              MvcResources.ControllerBuilder_FactoryReturnedNull,
                              factory.GetType(),
                              controllerName));
            }
        }
コード例 #3
0
        public void Should_be_able_to_register_controller_factory()
        {
            var builder = new ControllerBuilder();

            new RegisterControllerFactory(adapter.Object, builder).Execute();

            Assert.Same(controllerFactory.Object, builder.GetControllerFactory());
        }
コード例 #4
0
        public void ControllerBuilderReturnsDefaultControllerBuilderByDefault() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.IsInstanceOfType(cf, typeof(DefaultControllerFactory));
        }
コード例 #5
0
        public void Should_not_register_controller_factory_when_excluded()
        {
            RegisterControllerFactory.Excluded = true;
            DependencyResolver.SetResolver(null);

            var builder = new ControllerBuilder();

            new RegisterControllerFactory(adapter.Object, builder).Execute();

            Assert.NotSame(controllerFactory.Object, builder.GetControllerFactory());
        }
コード例 #6
0
ファイル: MvcHandler.cs プロジェクト: consumentor/Server
        private void ProcessRequestInit(HttpContextBase httpContext, out IController controller, out IControllerFactory factory)
        {
            AddVersionHeader(httpContext);
            RemoveOptionalRoutingParameters();

            // Get the controller type
            string controllerName = RequestContext.RouteData.GetRequiredString("controller");

            // Instantiate the controller and call Execute
            factory    = ControllerBuilder.GetControllerFactory();
            controller = factory.CreateController(RequestContext, controllerName);
            if (controller == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              MvcResources.ControllerBuilder_FactoryReturnedNull,
                              factory.GetType(),
                              controllerName));
            }
        }
コード例 #7
0
        public void CreateControllerWithFactoryTypeReturnsValidType() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(MockControllerFactory));

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.IsInstanceOfType(cf, typeof(MockControllerFactory));
        }
コード例 #8
0
        public void CreateControllerWithFactoryInstanceReturnsInstance() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            DefaultControllerFactory factory = new DefaultControllerFactory();
            cb.SetControllerFactory(factory);

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.AreSame(factory, cf);
        }
コード例 #9
0
        public void ControllerBuilderGetControllerFactoryDelegatesToResolver() {
            //Arrange
            Mock<IControllerFactory> factory = new Mock<IControllerFactory>();
            Resolver<IControllerFactory> resolver = new Resolver<IControllerFactory> { Current = factory.Object };
            ControllerBuilder builder = new ControllerBuilder(resolver);

            //Act
            IControllerFactory result = builder.GetControllerFactory();

            //Assert
            Assert.AreSame(factory.Object, result);

        }
コード例 #10
0
        public void SettingControllerFactoryReturnsSetFactory() {
            // Arrange
            ControllerBuilder builder = new ControllerBuilder();
            Mock<IControllerFactory> setFactory = new Mock<IControllerFactory>();

            // Act
            builder.SetControllerFactory(setFactory.Object);

            // Assert
            Assert.AreSame(setFactory.Object, builder.GetControllerFactory());
        }
コード例 #11
0
        public void DefaultControllerFactoryIsDefaultControllerFactory() {
            // Arrange
            ControllerBuilder builder = new ControllerBuilder();

            // Act
            IControllerFactory returnedControllerFactory = builder.GetControllerFactory();

            //Assert
            Assert.AreEqual(typeof(DefaultControllerFactory), returnedControllerFactory.GetType());
        }