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();
33 loader
.ViewRootDir
= Path
.GetFullPath(System
.Configuration
.ConfigurationManager
.AppSettings
["tests.src"]);
34 loader
.Service(new TestServiceContainer());
38 public void LoadFromFileSystem()
40 Assert
.IsFalse(loader
.HasTemplate("contentinfs2.vm"));
41 Assert
.IsTrue(loader
.HasTemplate("contentinfs.vm"));
42 Assert
.IsNotNull(loader
.GetViewSource("contentinfs.vm"));
46 public void LoadFromAssembly()
48 loader
.AddAssemblySource(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
50 Assert
.IsFalse(loader
.HasTemplate("Content/contentinassembly2.vm"));
51 Assert
.IsTrue(loader
.HasTemplate("Content/contentinassembly.vm"));
52 Assert
.IsNotNull(loader
.GetViewSource("Content/contentinassembly.vm"));
54 Assert
.IsFalse(loader
.HasTemplate("Content\\contentinassembly2.vm"));
55 Assert
.IsTrue(loader
.HasTemplate("Content\\contentinassembly.vm"));
56 Assert
.IsNotNull(loader
.GetViewSource("Content\\contentinassembly.vm"));
60 public void ListViews()
62 loader
.AddAssemblySource(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
64 string[] views
= loader
.ListViews("Content");
66 Assert
.IsNotNull(views
);
67 Assert
.AreEqual(3, views
.Length
);
68 Assert
.AreEqual(@"Content" + Path
.DirectorySeparatorChar
+ "contentinassembly.vm", views
[0]);
69 Assert
.AreEqual(@"Content" + Path
.DirectorySeparatorChar
+ "notinassembly.vm", views
[1]);
70 Assert
.AreEqual(@"content.contentinassembly.vm", views
[2]);
72 foreach(string view
in views
)
74 Assert
.IsTrue(loader
.HasTemplate(view
));
75 Assert
.IsNotNull(loader
.GetViewSource(view
));
81 public class FileAssemblyViewSourceLoaderWithoutViewDirectoryTestCase
83 private FileAssemblyViewSourceLoader loader
;
88 loader
= new FileAssemblyViewSourceLoader();
89 loader
.ViewRootDir
= Path
.GetFullPath(@"c:\idontexist");
90 loader
.Service(new TestServiceContainer());
94 public void DoesNotThrowException_IfSubscribingToViewSourceChangedEvent_AndViewFolderIsMissing()
96 loader
.ViewChanged
+= delegate
103 public void LoadFromAssembly()
105 loader
.AddAssemblySource(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
107 Assert
.IsFalse(loader
.HasTemplate("Content/contentinassembly2.vm"));
108 Assert
.IsTrue(loader
.HasTemplate("Content/contentinassembly.vm"));
109 Assert
.IsNotNull(loader
.GetViewSource("Content/contentinassembly.vm"));
111 Assert
.IsFalse(loader
.HasTemplate("Content\\contentinassembly2.vm"));
112 Assert
.IsTrue(loader
.HasTemplate("Content\\contentinassembly.vm"));
113 Assert
.IsNotNull(loader
.GetViewSource("Content\\contentinassembly.vm"));
117 public void ListViews()
119 loader
.AddAssemblySource(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests"));
121 string[] views
= loader
.ListViews("Content");
123 Assert
.IsNotNull(views
);
124 Assert
.AreEqual(1, views
.Length
);
125 //Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[0]);
126 //Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "notinassembly.vm", views[1]);
127 Assert
.AreEqual(@"content.contentinassembly.vm", views
[0]);
129 foreach (string view
in views
)
131 Assert
.IsTrue(loader
.HasTemplate(view
));
132 Assert
.IsNotNull(loader
.GetViewSource(view
));
137 internal class TestServiceContainer
: AbstractServiceContainer
139 public TestServiceContainer()
141 AddService(typeof(IControllerTree
), new DefaultControllerTree());
142 AddService(typeof(IResourceDescriptorProvider
), new DefaultResourceDescriptorProvider());
143 AddService(typeof(IRescueDescriptorProvider
), new DefaultRescueDescriptorProvider());
144 AddService(typeof(ILayoutDescriptorProvider
), new DefaultLayoutDescriptorProvider());
145 AddService(typeof(IHelperDescriptorProvider
), new DefaultHelperDescriptorProvider());
146 AddService(typeof(IFilterDescriptorProvider
), new DefaultFilterDescriptorProvider());
147 AddService(typeof(ITransformFilterDescriptorProvider
), new DefaultTransformFilterDescriptorProvider());