public void Init()
		{
			mocks = new MockRepository();

			MockServices services = new MockServices();
			services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views");
			services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

			viewComponentFactory = new DefaultViewComponentFactory();
			viewComponentFactory.Initialize();
			services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
			services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

			controller = mocks.DynamicMock<IController>();
			engineContext = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
			controllerContext = new ControllerContext();

			factory = new SparkViewFactory();
			factory.Service(services);

			engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
			engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

			manager = new DefaultViewEngineManager();
			manager.RegisterEngineForExtesionLookup(factory);
			manager.RegisterEngineForView(factory);

		}
예제 #2
0
        public void Init()
        {
            mocks = new MockRepository();

            MockServices services = new MockServices();

            services.ViewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

            viewComponentFactory = new DefaultViewComponentFactory();
            viewComponentFactory.Initialize();
            services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            controller        = mocks.DynamicMock <IController>();
            engineContext     = new MockEngineContext(new UrlInfo("", "Home", "Index", "/", "castle"));
            controllerContext = new ControllerContext();

            factory = new SparkViewFactory();
            factory.Service(services);

            engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
예제 #3
0
        protected void InitUrlInfo(string areaName, string controllerName, string actionName)
        {
            var urlInfo = new UrlInfo(areaName, controllerName, actionName, "/", "castle");

            engineContext = new StubEngineContext();
            engineContext.AddService(typeof(IUrlBuilder), serviceProvider.UrlBuilder);
            engineContext.CurrentController          = controller;
            engineContext.CurrentControllerContext   = controllerContext;
            engineContext.Services.ViewEngineManager = serviceProvider.ViewEngineManager;
            output = (StringWriter)engineContext.Response.Output;

            var routeMatch = new RouteMatch();

            controllerContext.RouteMatch = routeMatch;
        }
예제 #4
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));
        }
예제 #5
0
        protected void InitUrlInfo(string areaName, string controllerName, string actionName)
        {
            var urlInfo = new UrlInfo(areaName, controllerName, actionName, "/", "castle");

            engineContext = new StubEngineContext();
            engineContext.AddService(typeof(IUrlBuilder), serviceProvider.UrlBuilder);
            engineContext.CurrentController = controller;
            engineContext.CurrentControllerContext = controllerContext;
            engineContext.Services.ViewEngineManager = serviceProvider.ViewEngineManager;
            output = (StringWriter) engineContext.Response.Output;

            var routeMatch = new RouteMatch();
            controllerContext.RouteMatch = routeMatch;
        }