Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / FileAssemblyViewSourceLoaderTestCase.cs
blobe3fc7580ca927608b0f8e01b7b635ad3847b1701
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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
17 using System.IO;
18 using Castle.MonoRail.Framework.Internal;
19 using Castle.MonoRail.Framework.Services;
21 using NUnit.Framework;
24 [TestFixture]
25 public class FileAssemblyViewSourceLoaderTestCase
27 private FileAssemblyViewSourceLoader loader;
29 [SetUp]
30 public void SetUp()
32 loader = new FileAssemblyViewSourceLoader();
33 loader.ViewRootDir = Path.GetFullPath(System.Configuration.ConfigurationManager.AppSettings["tests.src"]);
34 loader.Service(new TestServiceContainer());
37 [Test]
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"));
45 [Test]
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"));
59 [Test]
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));
80 [TestFixture]
81 public class FileAssemblyViewSourceLoaderWithoutViewDirectoryTestCase
83 private FileAssemblyViewSourceLoader loader;
85 [SetUp]
86 public void SetUp()
88 loader = new FileAssemblyViewSourceLoader();
89 loader.ViewRootDir = Path.GetFullPath(@"c:\idontexist");
90 loader.Service(new TestServiceContainer());
93 [Test]
94 public void DoesNotThrowException_IfSubscribingToViewSourceChangedEvent_AndViewFolderIsMissing()
96 loader.ViewChanged += delegate
98 //do nothing
102 [Test]
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"));
116 [Test]
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());