GetHttpHandler() public method

public GetHttpHandler ( System.Web.Routing.RequestContext requestContext ) : IHttpHandler
requestContext System.Web.Routing.RequestContext
return IHttpHandler
Exemplo n.º 1
0
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        IRouteHandler handler = new MvcRouteHandler();
        var           vals    = requestContext.RouteData.Values;

        if (vals["language"] == null)
        {
            vals["language"] = "pt";
        }
        return(handler.GetHttpHandler(requestContext));
    }
Exemplo n.º 2
0
 public IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
     IRouteHandler handler = new MvcRouteHandler();
     var vals = requestContext.RouteData.Values;
     if(String.IsNullOrEmpty(vals["controller"])
     {
        // fetch action and controller from database
        vals["controller"] = dbcontroller;
        vals["action"] = dbaction
     } 
     return handler.GetHttpHandler(requestContext);
 }
Exemplo n.º 3
0
        public void GetHttpHandlerThrowsIfTheRouteValuesDoesNotIncludeAControllerName()
        {
            // Arrange
            var           httpContext    = new Mock <HttpContextBase>();
            var           routeData      = new RouteData();
            var           requestContext = new RequestContext(httpContext.Object, routeData);
            IRouteHandler routeHandler   = new MvcRouteHandler();

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => routeHandler.GetHttpHandler(requestContext),
                "The matched route does not include a 'controller' route value, which is required."
                );
        }
        public void GetHttpHandlerReturnsMvcHandlerWithRouteData()
        {
            // Arrange
            RequestContext context = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData());
            IRouteHandler  rh      = new MvcRouteHandler();

            // Act
            IHttpHandler httpHandler = rh.GetHttpHandler(context);

            // Assert
            MvcHandler h = httpHandler as MvcHandler;

            Assert.IsNotNull(h, "The handler should be a valid MvcHandler instance");
            Assert.AreEqual <RequestContext>(context, h.RequestContext);
        }
Exemplo n.º 5
0
        public void GetHttpHandlerAsksControllerFactoryForSessionBehaviorOfController()
        {
            // Arrange
            var httpContext = new Mock <HttpContextBase>();
            var routeData   = new RouteData();

            routeData.Values["controller"] = "controllerName";
            var requestContext    = new RequestContext(httpContext.Object, routeData);
            var controllerFactory = new Mock <IControllerFactory>();

            controllerFactory.Setup(f => f.GetControllerSessionBehavior(requestContext, "controllerName"))
            .Returns(SessionStateBehavior.ReadOnly)
            .Verifiable();
            IRouteHandler routeHandler = new MvcRouteHandler(controllerFactory.Object);

            // Act
            routeHandler.GetHttpHandler(requestContext);

            // Assert
            controllerFactory.Verify();
            httpContext.Verify(c => c.SetSessionStateBehavior(SessionStateBehavior.ReadOnly));
        }
Exemplo n.º 6
0
        public void GetHttpHandlerReturnsMvcHandlerWithRouteData()
        {
            // Arrange
            var routeData = new RouteData();

            routeData.Values["controller"] = "controllerName";
            var context           = new RequestContext(new Mock <HttpContextBase>().Object, routeData);
            var controllerFactory = new Mock <IControllerFactory>();

            controllerFactory.Setup(f => f.GetControllerSessionBehavior(context, "controllerName"))
            .Returns(SessionStateBehavior.Default)
            .Verifiable();
            IRouteHandler rh = new MvcRouteHandler(controllerFactory.Object);

            // Act
            IHttpHandler httpHandler = rh.GetHttpHandler(context);

            // Assert
            MvcHandler h = httpHandler as MvcHandler;

            Assert.NotNull(h);
            Assert.Equal(context, h.RequestContext);
        }