コード例 #1
0
        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);
        }
コード例 #2
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."
                );
        }
コード例 #3
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.IsNotNull(h, "The handler should be a valid MvcHandler instance");
            Assert.AreEqual<RequestContext>(context, h.RequestContext);
        }
コード例 #4
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));
        }