コード例 #1
0
        public void Request_CreatesSessionfulHandler()
        {
            StringWriter writer = new StringWriter();

            HttpResponse res = new HttpResponse(writer);
            HttpRequest  req = new HttpRequest(Path.Combine(
                                                   AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"),
                                               "http://localhost:1333/home/something", "");
            RouteMatch  routeMatch = new RouteMatch();
            HttpContext httpCtx    = new HttpContext(req, res);

            httpCtx.Items[RouteMatch.RouteMatchKey] = routeMatch;

            using (_MockRepository.Record())
            {
                ControllerMetaDescriptor controllerDesc = new ControllerMetaDescriptor();
                controllerDesc.ControllerDescriptor = new ControllerDescriptor(typeof(Controller), "home", "", false);

                Expect.Call(_ControllerFactoryMock.CreateController("", "home")).IgnoreArguments().Return(_ControllerMock);
                Expect.Call(_ControllerDescriptorProviderMock.BuildDescriptor(_ControllerMock)).Return(controllerDesc);
                Expect.Call(_ControllerContextFactoryMock.Create("", "home", "something", controllerDesc, routeMatch)).
                Return(new ControllerContext());
            }

            using (_MockRepository.Playback())
            {
                IHttpHandler handler = _HandlerFactory.GetHandler(httpCtx, "GET", "", "");

                Assert.IsNotNull(handler);
                Assert.IsInstanceOfType(typeof(MonoRailHttpHandler), handler);
            }
        }
コード例 #2
0
        public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IController controller;

            PerformOneTimeInitializationIfNecessary(context);
            EnsureServices();

            HttpRequest request    = context.Request;
            RouteMatch  routeMatch = (( RouteMatch )context.Items[RouteMatch.RouteMatchKey]) ?? new RouteMatch();

            UrlInfo urlInfo = UrlTokenizer.TokenizeUrl(
                request.FilePath,
                request.PathInfo,
                request.Url,
                request.IsLocal,
                request.ApplicationPath);

            if (urlInfo.Area.Equals("MonoRail", StringComparison.CurrentCultureIgnoreCase) &&
                urlInfo.Controller.Equals("Files", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new ResourceFileHandler(urlInfo, new DefaultStaticResourceRegistry()));
            }

            if (urlInfo.Area.Equals("MonoRail", StringComparison.CurrentCultureIgnoreCase) &&
                urlInfo.Controller.Equals("Resources", StringComparison.CurrentCultureIgnoreCase))
            {
                return(new ResourceFileHandlerEx(urlInfo, new DefaultStaticResourceRegistryEx()));
            }

            IEngineContext serviceInstance = _EngineContextFactory.Create(
                _MonoRailContainer,
                urlInfo,
                context,
                routeMatch);

            serviceInstance.AddService(typeof(IEngineContext), serviceInstance);

            try
            {
                controller = _ControllerFactory.CreateController(urlInfo.Area, urlInfo.Controller);
            }
            catch (ControllerNotFoundException)
            {
                return(new MonoRailHttpHandlerFactory.NotFoundHandler(
                           urlInfo.Area,
                           urlInfo.Controller,
                           serviceInstance));
            }

            ControllerMetaDescriptor metaDescriptor = _MonoRailContainer.ControllerDescriptorProvider.BuildDescriptor(controller);

            IControllerContext context3 = _ControllerContextFactory.Create(
                urlInfo.Area,
                urlInfo.Controller,
                urlInfo.Action,
                metaDescriptor,
                routeMatch);

            serviceInstance.CurrentController          = controller;
            serviceInstance.CurrentControllerContext   = context3;
            context.Items[CurrentEngineContextKey]     = serviceInstance;
            context.Items[CurrentControllerKey]        = controller;
            context.Items[CurrentControllerContextKey] = context3;

            if (IgnoresSession(metaDescriptor.ControllerDescriptor))
            {
                return(new SessionlessMonoRailHttpHandler(serviceInstance, controller, context3));
            }

            return(new MonoRailHttpHandler(serviceInstance, controller, context3));
        }