コード例 #1
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);

		}
コード例 #2
0
        protected override void Configure()
        {
            var settings = new SparkSettings();
            settings.SetNullBehaviour(NullBehaviour.Strict);
            var sparkViewEngine = new SparkViewEngine(settings);
            serviceProvider.AddService(typeof(ISparkViewEngine), sparkViewEngine);

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

            manager = new DefaultViewEngineManager();
            manager.Service(serviceProvider);
            serviceProvider.ViewEngineManager = manager;
            serviceProvider.AddService(typeof(IViewEngineManager), manager);

            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
            factory.Service(serviceProvider);
        }
コード例 #3
0
		protected string ProcessViewJS(string templatePath)
		{
			StringWriter sw = new StringWriter();
			ControllerContext.LayoutNames = Layouts;
			StubEngineContext.CurrentControllerContext = ControllerContext;
			DefaultViewEngineManager engineManager = new DefaultViewEngineManager();
			engineManager.RegisterEngineForView(BooViewEngine);
			engineManager.RegisterEngineForExtesionLookup((BooViewEngine));
			JSCodeGenerator codeGenerator =
				  new JSCodeGenerator(StubEngineContext.Server,
					  engineManager,
					  StubEngineContext, null, ControllerContext, StubEngineContext.Services.UrlBuilder);

			IJSGenerator jsGen = new PrototypeGenerator(codeGenerator);

			codeGenerator.JSGenerator = jsGen;

			JSCodeGeneratorInfo info = new JSCodeGeneratorInfo(codeGenerator, jsGen,
				new object[] { new ScriptaculousExtension(codeGenerator) },
				new object[] { new ScriptaculousExtension(codeGenerator) });

			BooViewEngine.GenerateJS(templatePath, sw, info, StubEngineContext, null, ControllerContext);
			lastOutput = sw.ToString();
			return lastOutput;
		}
コード例 #4
0
ファイル: SparkViewFactoryTests.cs プロジェクト: bbarry/spark
        protected override void Configure()
        {
            factory = new SparkViewFactory();
            factory.Service(serviceProvider);

            manager = new DefaultViewEngineManager();
            manager.Service(serviceProvider);
            serviceProvider.ViewEngineManager = manager;
            serviceProvider.AddService(typeof(IViewEngineManager), manager);

            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
コード例 #5
0
        public void Init()
        {
            mocks = new MockRepository();
            factory = new SparkViewFactory();
            engineContext = mocks.CreateMock<IEngineContext>();
            server = new MockServerUtility();
            request = mocks.CreateMock<IRequest>();
            response = mocks.CreateMock<IResponse>();

            controller = mocks.CreateMock<IController>();
            controllerContext = mocks.CreateMock<IControllerContext>();
            routingEngine = mocks.CreateMock<IRoutingEngine>();
            output = new StringWriter();
            helpers = new HelperDictionary();

            propertyBag = new Dictionary<string, object>();
            flash = new Flash();
            session = new Dictionary<string, object>();
            requestParams = new NameValueCollection();
            contextItems = new Dictionary<string, object>();


            SetupResult.For(engineContext.Server).Return(server);
            SetupResult.For(engineContext.Request).Return(request);
            SetupResult.For(engineContext.Response).Return(response);
            SetupResult.For(engineContext.CurrentController).Return(controller);
            SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext);
            SetupResult.For(engineContext.Flash).Return(flash);
            SetupResult.For(engineContext.Session).Return(session);
            SetupResult.For(engineContext.Items).Return(contextItems);

            SetupResult.For(request.Params).Return(requestParams);

            SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" });
            SetupResult.For(controllerContext.Helpers).Return(helpers);
            SetupResult.For(controllerContext.PropertyBag).Return(propertyBag);

            SetupResult.For(routingEngine.IsEmpty).Return(true);

            var urlBuilder = new DefaultUrlBuilder(server, routingEngine);

            var serviceProvider = mocks.CreateMock<IServiceProvider>();
            var viewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader);
            SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory());
            SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null);
            SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder);
            SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null);
            mocks.Replay(serviceProvider);

            SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do(
                new Func<Type, object>(serviceProvider.GetService));

            factory.Service(serviceProvider);


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