private void TestMultipleLoaders()
        {
            const string resource = "rendering\\resourcetest.*";

            Add("haml", new HamlGenerator());
            Add("tiny", new Tiny.TinyGenerator());
            if (_templateLoaders.Count == 0)
            {
                _templateLoaders.Add(new FileTemplateLoader());
            }
            ResourceTemplateLoader loader = new ResourceTemplateLoader();

            loader.LoadTemplates("rendering/", loader.GetType().Assembly, "HttpServer.Rendering");
            _templateLoaders.Add(loader);
            string result = Render(resource, null);

            Assert.NotNull(result);
            Assert.True(result.StartsWith("This file is used to test the resource template loader"));

            ((FileTemplateLoader)_templateLoaders[0]).PathPrefix = "..\\..\\";
            result = Render(resource, null);

            Assert.NotNull(result);
            Assert.True(result.StartsWith("This file is used to test the resource template loader"));
        }
Exemple #2
0
        public void StartTutorial()
        {
            // load language from a YAML file.
            new YamlWatcher(_language, "..\\..\\tutorial5\\language.yaml"); // "..\\..\\" since we run the tutorial in vstudio
            Validator.Language = _language.GetChild("Validator") ?? LanguageNode.Empty;
            
            // since we do not use files on disk, we'll just add the resource template loader.
            ResourceTemplateLoader templateLoader = new ResourceTemplateLoader();
            templateLoader.LoadTemplates("/", Assembly.GetExecutingAssembly(), "Tutorial.Tutorial5.views");
            TemplateManager templateManager = new TemplateManager(templateLoader);
            templateManager.AddType(typeof (WebHelper));
            templateManager.Add("haml", new HttpServer.Rendering.Haml.HamlGenerator());
            
            // we've just one controller. Add it.
            ControllerModule controllerModule = new ControllerModule();
            controllerModule.Add(new UserController(templateManager, _language));
            _server.Add(controllerModule);

            // add file module, to be able to handle files
            ResourceFileModule fileModule = new ResourceFileModule();
            fileModule.AddResources("/", Assembly.GetExecutingAssembly(), "Tutorial.Tutorial5.public");
            _server.Add(fileModule);

            // ok. We should be done. Start the server.
            _server.Start(IPAddress.Any, 8081);

            Console.WriteLine("Tutorial 5 is running. Go to http://localhost:8081/user/");
            Console.WriteLine("Try to add '?lcid=1053' and '?lcid=1033' to address to switch language (i.e: http://localhost:8081/user/?lcid=1053).");
        }
		private static void TestLoadTemplate()
		{
			ResourceTemplateLoader loader = new ResourceTemplateLoader();
			loader.LoadTemplates("/test/", loader.GetType().Assembly, loader.GetType().Namespace);
			TextReader reader = loader.LoadTemplate("test\\resourcetest.haml");
			Assert.NotNull(reader);
			reader.Dispose();
		}
Exemple #4
0
        private static void TestLoadTemplate()
        {
            ResourceTemplateLoader loader = new ResourceTemplateLoader();

            loader.LoadTemplates("/test/", loader.GetType().Assembly, loader.GetType().Namespace);
            TextReader reader = loader.LoadTemplate("test\\resourcetest.haml");

            Assert.NotNull(reader);
            reader.Dispose();
        }
        private void TestGetGeneratorForWildCard()
        {
            string resource = "rendering\\resourcetest.*";

            Add("haml", new HamlGenerator());
            Add("tiny", new Tiny.TinyGenerator());
            _templateLoaders.Clear();
            ResourceTemplateLoader loader = new ResourceTemplateLoader();

            loader.LoadTemplates("rendering/", loader.GetType().Assembly, "HttpServer.Rendering");
            _templateLoaders.Add(loader);
            ITemplateGenerator gen = GetGeneratorForWildCard(ref resource);

            Assert.NotNull(gen);
            Assert.IsType(typeof(HamlGenerator), gen);
        }
		private void TestMultipleLoaders()
		{
			const string resource = "rendering\\resourcetest.*";
			Add("haml", new HamlGenerator());
			Add("tiny", new Tiny.TinyGenerator());
			if (_templateLoaders.Count == 0)
				_templateLoaders.Add(new FileTemplateLoader());
			ResourceTemplateLoader loader = new ResourceTemplateLoader();
			loader.LoadTemplates("rendering/", loader.GetType().Assembly, "HttpServer.Rendering");
			_templateLoaders.Add(loader);
			string result = Render(resource, null);
			
			Assert.NotNull(result);
			Assert.True(result.StartsWith("This file is used to test the resource template loader"));

			((FileTemplateLoader)_templateLoaders[0]).PathPrefix = "..\\..\\";
			result = Render(resource, null);

			Assert.NotNull(result);
			Assert.True(result.StartsWith("This file is used to test the resource template loader"));
		}
        private void TestGetGeneratorForWildCard()
        {
            string resource = "rendering\\resourcetest.*";
            Add("haml", new HamlGenerator());
            Add("tiny", new Tiny.TinyGenerator());
			_templateLoaders.Clear();
        	ResourceTemplateLoader loader = new ResourceTemplateLoader();
			loader.LoadTemplates("rendering/", loader.GetType().Assembly, "HttpServer.Rendering");
            _templateLoaders.Add(loader);
            ITemplateGenerator gen = GetGeneratorForWildCard(ref resource);
            Assert.NotNull(gen);
            Assert.IsType(typeof (HamlGenerator), gen);
        }