Fix the build.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / ViewEngineBaseTestCase.cs
blobc387ac3aae9645c3a57d05d7490be89e8c34de33
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 #pragma warning disable 67
17 namespace Castle.MonoRail.Framework.Tests
19 using System;
20 using System.Collections;
21 using System.IO;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ViewEngineBaseTestCase
27 [Test]
28 public void IsTemplateForJSGeneration_ShouldReturnFalseForTemplateWithAnotherExtension()
30 const string templateName = "view.test";
31 TestableViewEngineBase engine = new TestableViewEngineBase();
32 engine.Service(new TestServiceProvider(new TestViewSourceLoader(templateName)));
33 Assert.IsFalse(engine.IsTemplateForJSGeneration(templateName),
34 "This is a template typed by extension as not for JSGen and should not have been accepted");
37 [Test]
38 public void IsTemplateForJSGeneration_ShouldReturnFalseForNonExistentTemplateWithNoExtension()
40 TestableViewEngineBase engine = new TestableViewEngineBase();
41 engine.Service(new TestServiceProvider(new TestViewSourceLoader()));
42 Assert.IsFalse(engine.IsTemplateForJSGeneration("view.testjs"),
43 "This template does not 'exist' so it should have failed");
46 [Test]
47 public void IsTemplateForJSGeneration_ShouldReturnTrueForExistingTemplateWithCorrectExtension()
49 const string templateName = "fakeview.testjs";
50 TestableViewEngineBase engine = new TestableViewEngineBase();
51 engine.Service(new TestServiceProvider(new TestViewSourceLoader(templateName)));
52 Assert.IsTrue(engine.IsTemplateForJSGeneration(templateName),
53 "Should have been accepted and found with correct extension");
56 [Test]
57 public void IsTemplateForJSGeneration_ShouldReturnTrueForExistingTemplateWithoutExtension()
59 TestableViewEngineBase engine = new TestableViewEngineBase();
60 engine.Service(new TestServiceProvider(new TestViewSourceLoader("fakeview.testjs")));
61 Assert.IsTrue(engine.IsTemplateForJSGeneration("fakeview"),
62 "Should have been accepted and found without extension");
66 public class TestViewSourceLoader : IViewSourceLoader
68 private readonly string[] views;
70 public TestViewSourceLoader(params string[] views)
72 this.views = views;
75 #region IViewSourceLoader Members
77 /// <summary>
78 /// Evaluates whether the specified template exists.
79 /// </summary>
80 /// <param name="templateName">The template name</param>
81 /// <returns><c>true</c> if it exists</returns>
82 public bool HasTemplate(string templateName)
84 foreach (string view in views)
85 if (view.Equals(templateName, StringComparison.InvariantCultureIgnoreCase))
86 return true;
87 return false;
90 /// <summary>
91 /// Builds and returns a representation of a view template
92 /// </summary>
93 /// <param name="templateName">The template name</param>
94 /// <returns></returns>
95 public IViewSource GetViewSource(string templateName)
97 throw new NotImplementedException();
100 /// <summary>
101 /// Gets a list of views on the specified directory
102 /// </summary>
103 /// <param name="dirName">Directory name</param>
104 /// <returns></returns>
105 public string[] ListViews(string dirName)
107 throw new NotImplementedException();
110 /// <summary>
111 /// Gets/sets the root directory of views, obtained from the configuration.
112 /// </summary>
113 public string ViewRootDir
115 get { throw new NotImplementedException(); }
116 set { throw new NotImplementedException(); }
119 /// <summary>
120 /// Gets or sets whether the instance should use cache
121 /// </summary>
122 public bool EnableCache
124 get { throw new NotImplementedException(); }
125 set { throw new NotImplementedException(); }
128 /// <summary>
129 /// Gets a list of assembly sources
130 /// </summary>
131 public IList AssemblySources
133 get { throw new NotImplementedException(); }
136 /// <summary>
137 /// Adds the assembly source.
138 /// </summary>
139 /// <param name="assemblySourceInfo">The assembly source info.</param>
140 public void AddAssemblySource(AssemblySourceInfo assemblySourceInfo)
142 throw new NotImplementedException();
145 /// <summary>
146 /// Raised when the view is changed.
147 /// </summary>
148 public event FileSystemEventHandler ViewChanged;
150 #endregion
153 public class TestServiceProvider : IServiceProvider
155 private readonly IViewSourceLoader viewsourceloader;
157 public TestServiceProvider(IViewSourceLoader viewsourceloader)
159 this.viewsourceloader = viewsourceloader;
162 #region IServiceProvider Members
164 ///<summary>
165 ///Gets the service object of the specified type.
166 ///</summary>
168 ///<returns>
169 ///A service object of type serviceType.-or- null if there is no service object of type serviceType.
170 ///</returns>
172 ///<param name="serviceType">An object that specifies the type of service object to get. </param><filterpriority>2</filterpriority>
173 public object GetService(Type serviceType)
175 if (serviceType == typeof(IViewSourceLoader))
176 return viewsourceloader;
177 return null;
180 #endregion
183 public class TestableViewEngineBase : ViewEngineBase
185 private bool _supportsJSGeneration;
186 private string _viewFileExtension;
187 private string _jsGeneratorFileExtension;
189 public TestableViewEngineBase()
191 _supportsJSGeneration = false;
192 _viewFileExtension = ".test";
193 _jsGeneratorFileExtension = ".testjs";
196 public override bool SupportsJSGeneration
198 get { return _supportsJSGeneration; }
201 public override string ViewFileExtension
203 get { return _viewFileExtension; }
206 public override string JSGeneratorFileExtension
208 get { return _jsGeneratorFileExtension; }
211 /// <summary>
212 /// Processes the view - using the templateName
213 /// to obtain the correct template,
214 /// and using the context to output the result.
215 /// </summary>
216 public override void Process(IRailsEngineContext context, IController controller, string templateName)
218 throw new NotImplementedException();
221 ///<summary>
222 /// Processes the view - using the templateName
223 /// to obtain the correct template
224 /// and writes the results to the System.IO.TextWriter.
225 /// </summary>
226 public override void Process(TextWriter output, IRailsEngineContext context, IController controller,
227 string templateName)
229 throw new NotImplementedException();
232 /// <summary>
233 /// Should process the specified partial. The partial name must contains
234 /// the path relative to the views folder.
235 /// </summary>
236 /// <param name="output">The output.</param>
237 /// <param name="context">The request context.</param>
238 /// <param name="controller">The controller.</param>
239 /// <param name="partialName">The partial name.</param>
240 public override void ProcessPartial(TextWriter output, IRailsEngineContext context, IController controller,
241 string partialName)
243 throw new NotImplementedException();
246 /// <summary>
247 /// Implementors should return a generator instance if
248 /// the view engine supports JS generation.
249 /// </summary>
250 /// <param name="context">The request context.</param>
251 /// <returns>A JS generator instance</returns>
252 public override object CreateJSGenerator(IRailsEngineContext context)
254 throw new NotImplementedException();
257 /// <summary>
258 /// Processes the js generation view template - using the templateName
259 /// to obtain the correct template, and using the specified <see cref="TextWriter"/>
260 /// to output the result.
261 /// </summary>
262 /// <param name="output">The output.</param>
263 /// <param name="context">The request context.</param>
264 /// <param name="controller">The controller.</param>
265 /// <param name="templateName">Name of the template.</param>
266 public override void GenerateJS(TextWriter output, IRailsEngineContext context, IController controller,
267 string templateName)
269 throw new NotImplementedException();
272 /// <summary>
273 /// Wraps the specified content in the layout using the
274 /// context to output the result.
275 /// </summary>
276 public override void ProcessContents(IRailsEngineContext context, IController controller, string contents)
278 throw new NotImplementedException();