private static void TestGetResourceStream()
        {
            ResourceManager resources = new ResourceManager(new NullLogWriter());

            resources.LoadResources("/", resources.GetType().Assembly, "HttpServer.Rendering");
            Assert.NotNull(resources.GetResourceStream("resourcetest.haml"));
            Assert.NotNull(resources.GetResourceStream("\\resourcetest.haml"));
        }
        private static void TestContainsResource()
        {
            ResourceManager resourceManager = new ResourceManager(new NullLogWriter());

            resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.True(resourceManager.ContainsResource("/test/resourcetest.xml"));
            Assert.True(resourceManager.ContainsResource("/test/resourcetest.haml"));
            Assert.True(resourceManager.ContainsResource("/test/resourcetest.*"));
            Assert.True(resourceManager.ContainsResource("/test/haml/resourcetest2.*"));
            Assert.True(resourceManager.ContainsResource("/test/haml/resourcetest2.haml"));

            Assert.False(resourceManager.ContainsResource("/test/resourcetest"));
            Assert.False(resourceManager.ContainsResource("/test/rwerourcetest.xml"));
            Assert.False(resourceManager.ContainsResource("/test/resourcetest.qaml"));
            Assert.False(resourceManager.ContainsResource("/wrong/rwerourcetest.xml"));
            Assert.False(resourceManager.ContainsResource("/test/haml/resourcetest2.xml"));

            resourceManager._loadedResources.Clear();
            resourceManager.LoadResources("/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.True(resourceManager.ContainsResource("/resourcetest.*"));
            Assert.True(resourceManager.ContainsResource("resourcetest.haml"));
        }
        private static void TestLoadTemplates()
        {
            LogManager.SetProvider(new NullLogProvider());

            ResourceManager resourceManager = new ResourceManager(new NullLogWriter());

            resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.NotNull(resourceManager._loadedResources["test/resourcetest"]);
            Assert.Equal("haml", resourceManager._loadedResources["test/resourcetest"][0].Extension);
            Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["test/resourcetest"][0].Name);

            resourceManager._loadedResources.Clear();
            resourceManager.LoadResources("/user", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["user/resourcetest"][0].Name);

            resourceManager._loadedResources.Clear();
            resourceManager.LoadResources("/user/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["user/test/resourcetest"][0].Name);

            resourceManager._loadedResources.Clear();
            resourceManager.LoadResources("/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["resourcetest"][0].Name);
        }
        private static void TestGetFiles()
        {
            ResourceManager resourceManager = new ResourceManager(new NullLogWriter());

            resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
            string[] files = resourceManager.GetFiles("/test/", "resourcetest.xml");
            Assert.Equal(1, files.Length);
            Assert.Equal("test/resourcetest.xml", files[0]);

            files = resourceManager.GetFiles("/test/", "resourcetest.*");
            Assert.Equal(2, files.Length);

            files = resourceManager.GetFiles("/test/haml/", "resourcetest2.haml");
            Assert.Equal(1, files.Length);

            files = resourceManager.GetFiles("/test/haml/resourcetest2.haml");
            Assert.Equal(1, files.Length);

            files = resourceManager.GetFiles("/test/resourcetest.*");
            Assert.Equal(2, files.Length);
        }
		private static void TestContainsResource()
		{
			ResourceManager resourceManager = new ResourceManager();
			resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.True(resourceManager.ContainsResource("/test/resourcetest.xml"));
			Assert.True(resourceManager.ContainsResource("/test/resourcetest.haml"));
			Assert.True(resourceManager.ContainsResource("/test/resourcetest.*"));
			Assert.True(resourceManager.ContainsResource("/test/haml/resourcetest2.*"));
			Assert.True(resourceManager.ContainsResource("/test/haml/resourcetest2.haml"));

			Assert.False(resourceManager.ContainsResource("/test/resourcetest"));
			Assert.False(resourceManager.ContainsResource("/test/rwerourcetest.xml"));
			Assert.False(resourceManager.ContainsResource("/test/resourcetest.qaml"));
			Assert.False(resourceManager.ContainsResource("/wrong/rwerourcetest.xml"));
			Assert.False(resourceManager.ContainsResource("/test/haml/resourcetest2.xml"));

			resourceManager._loadedResources.Clear();
			resourceManager.LoadResources("/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.True(resourceManager.ContainsResource("/resourcetest.*"));
			Assert.True(resourceManager.ContainsResource("resourcetest.haml"));
		}
		private static void TestGetFiles()
		{
			ResourceManager resourceManager = new ResourceManager();
			resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			string[] files = resourceManager.GetFiles("/test/", "resourcetest.xml");
			Assert.Equal(1, files.Length);
			Assert.Equal("test/resourcetest.xml", files[0]);

			files = resourceManager.GetFiles("/test/", "resourcetest.*");
			Assert.Equal(2, files.Length);

			files = resourceManager.GetFiles("/test/haml/", "resourcetest2.haml");
			Assert.Equal(1, files.Length);

			files = resourceManager.GetFiles("/test/haml/resourcetest2.haml");
			Assert.Equal(1, files.Length);

			files = resourceManager.GetFiles("/test/resourcetest.*");
			Assert.Equal(2, files.Length);
		}
		private static void TestGetResourceStream()
		{
			ResourceManager resources = new ResourceManager();
			resources.LoadResources("/", resources.GetType().Assembly, "HttpServer.Rendering");
			Assert.NotNull(resources.GetResourceStream("resourcetest.haml"));
			Assert.NotNull(resources.GetResourceStream("\\resourcetest.haml"));
		}
		private static void TestLoadTemplates()
		{
			LogManager.SetProvider(new NullLogProvider());

			ResourceManager resourceManager = new ResourceManager();
			resourceManager.LoadResources("/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.NotNull(resourceManager._loadedResources["test/resourcetest"]);
			Assert.Equal("haml", resourceManager._loadedResources["test/resourcetest"][0].Extension);
			Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["test/resourcetest"][0].Name);

			resourceManager._loadedResources.Clear();
			resourceManager.LoadResources("/user", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["user/resourcetest"][0].Name);

			resourceManager._loadedResources.Clear();
			resourceManager.LoadResources("/user/test/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["user/test/resourcetest"][0].Name);

			resourceManager._loadedResources.Clear();
			resourceManager.LoadResources("/", resourceManager.GetType().Assembly, resourceManager.GetType().Namespace);
			Assert.Equal(resourceManager.GetType().Namespace + ".resourcetest.haml", resourceManager._loadedResources["resourcetest"][0].Name);
		}
Exemple #9
0
 /// <summary>
 /// Loads templates from a namespace in the given assembly to an uri
 /// </summary>
 /// <param name="toUri">The uri to map the resources to</param>
 /// <param name="fromAssembly">The assembly in which the resources reside</param>
 /// <param name="fromNamespace">The namespace from which to load the resources</param>
 /// <usage>
 /// resourceLoader.LoadResources("/user/", typeof(User).Assembly, "MyLib.Models.User.Views");
 ///
 /// will make ie the resource MyLib.Models.User.Views.list.Haml accessible via /user/list.haml or /user/list/
 /// </usage>
 public void LoadTemplates(string toUri, Assembly fromAssembly, string fromNamespace)
 {
     _resourceManager.LoadResources(toUri, fromAssembly, fromNamespace);
 }