1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Tests
18 using Castle
.MonoRail
.Framework
.Internal
;
19 using Castle
.MonoRail
.Framework
.Services
;
21 using NUnit
.Framework
;
25 public class FileAssemblyViewSourceLoaderTestCase
27 private FileAssemblyViewSourceLoader loader
;
32 loader
= new FileAssemblyViewSourceLoader();
34 loader
.ViewRootDir
= Path
.GetFullPath(System
.Configuration
.ConfigurationManager
.AppSettings
["tests.src"]);
36 loader
.ViewRootDir
= Path
.GetFullPath(System
.Configuration
.ConfigurationSettings
.AppSettings
["tests.src"]);
38 loader
.Service(new TestServiceContainer());
42 public void LoadFromFileSystem()
44 Assert
.IsFalse(loader
.HasTemplate("contentinfs2.vm"));
45 Assert
.IsTrue(loader
.HasTemplate("contentinfs.vm"));
46 Assert
.IsNotNull(loader
.GetViewSource("contentinfs.vm"));
50 public void LoadFromAssembly()
52 loader
.AdditionalSources
.Add(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
54 Assert
.IsFalse(loader
.HasTemplate("Content/contentinassembly2.vm"));
55 Assert
.IsTrue(loader
.HasTemplate("Content/contentinassembly.vm"));
56 Assert
.IsNotNull(loader
.GetViewSource("Content/contentinassembly.vm"));
58 Assert
.IsFalse(loader
.HasTemplate("Content\\contentinassembly2.vm"));
59 Assert
.IsTrue(loader
.HasTemplate("Content\\contentinassembly.vm"));
60 Assert
.IsNotNull(loader
.GetViewSource("Content\\contentinassembly.vm"));
64 public void ListViews()
66 loader
.AdditionalSources
.Add(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
68 string[] views
= loader
.ListViews("Content");
70 Assert
.IsNotNull(views
);
71 Assert
.AreEqual(3, views
.Length
);
72 Assert
.AreEqual(@"Content" + Path
.DirectorySeparatorChar
+ "contentinassembly.vm", views
[0]);
73 Assert
.AreEqual(@"Content" + Path
.DirectorySeparatorChar
+ "notinassembly.vm", views
[1]);
74 Assert
.AreEqual(@"content.contentinassembly.vm", views
[2]);
76 foreach(string view
in views
)
78 Assert
.IsTrue(loader
.HasTemplate(view
));
79 Assert
.IsNotNull(loader
.GetViewSource(view
));
84 internal class TestServiceContainer
: AbstractServiceContainer
86 public TestServiceContainer()
88 AddService(typeof(IControllerTree
), new DefaultControllerTree());
89 AddService(typeof(IResourceDescriptorProvider
), new DefaultResourceDescriptorProvider());
90 AddService(typeof(IRescueDescriptorProvider
), new DefaultRescueDescriptorProvider());
91 AddService(typeof(ILayoutDescriptorProvider
), new DefaultLayoutDescriptorProvider());
92 AddService(typeof(IHelperDescriptorProvider
), new DefaultHelperDescriptorProvider());
93 AddService(typeof(IFilterDescriptorProvider
), new DefaultFilterDescriptorProvider());
94 AddService(typeof(ITransformFilterDescriptorProvider
), new DefaultTransformFilterDescriptorProvider());