Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Configuration / ViewEngineConfigTestCase.cs
blob77c7fc7e4f3e0ff5b49a54dc5cd67b2ad4210ae1
1 // Copyright 2004-2008 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.Configuration
17 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Xml;
21 using Castle.MonoRail.Framework.Configuration;
22 using Castle.MonoRail.Framework.Internal;
23 using Castle.MonoRail.Framework.Views.Aspx;
24 using NUnit.Framework;
26 [TestFixture]
27 public class ViewEngineConfigTestCase
29 private string viewFolder = AppDomain.CurrentDomain.BaseDirectory;
31 [Test]
32 public void ShouldProcessAdditonalSourcesElement_IfConfiguringSingleViewEngine()
34 string configXml =
36 <monorail>
37 <controllers>
38 <assembly>Castle.MonoRail.Framework.Tests</assembly>
39 </controllers>
41 <viewEngine viewPathRoot=""" +
42 viewFolder +
43 @""">
45 <additionalSources>
46 <assembly name=""Castle.MonoRail.Framework.Tests"" namespace=""Castle.MonoRail.Framework.Tests.Content"" />
47 </additionalSources>
48 </viewEngine>
49 </monorail>";
51 XmlDocument doc = new XmlDocument();
52 doc.LoadXml(configXml);
53 ViewEngineConfig config = new ViewEngineConfig();
54 config.Deserialize(doc.DocumentElement);
56 Assert.IsTrue(config.Sources.Count > 0, "additonal sources not loaded");
59 [Test]
60 public void ShouldProcessAdditionalSourcesElement_IfConfiguringMultipleViewEngines()
62 string configXml =
64 <monorail>
65 <controllers>
66 <assembly>Castle.MonoRail.Framework.Tests</assembly>
67 </controllers>
69 <viewEngines viewPathRoot=""" +
70 viewFolder +
71 @""">
72 <add type=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine, Castle.MonoRail.Framework.Tests"" />
73 <additionalSources>
74 <assembly name=""Castle.MonoRail.Framework.Tests"" namespace=""Castle.MonoRail.Framework.Tests.Content"" />
75 </additionalSources>
76 </viewEngines>
77 </monorail>";
79 XmlDocument doc = new XmlDocument();
80 doc.LoadXml(configXml);
81 ViewEngineConfig config = new ViewEngineConfig();
82 config.Deserialize(doc.DocumentElement);
84 Assert.IsTrue(config.Sources.Count > 0, "Additional sources not loaded");
87 [Test]
88 public void ConfigureWithMultipleViewEngines_AssignedEnginesToViewEnginesProperty()
90 string configXml =@"
91 <monorail>
92 <controllers>
93 <assembly>Castle.MonoRail.Framework.Tests</assembly>
94 </controllers>
95 <viewEngines viewPathRoot=""" + viewFolder + @""">
96 <add
97 type=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine,
98 Castle.MonoRail.Framework.Tests"" />
99 <add
100 type=""Castle.MonoRail.Framework.Views.Aspx.WebFormsViewEngine,
101 Castle.MonoRail.Framework"" />
102 </viewEngines>
103 </monorail>";
105 XmlDocument doc = new XmlDocument();
106 doc.LoadXml(configXml);
107 ViewEngineConfig config = new ViewEngineConfig();
108 config.Deserialize(doc.DocumentElement);
110 Assert.AreEqual(2, config.ViewEngines.Count);
112 Assert.IsTrue(config.ViewEngines.Exists(TestViewEngineSpecification));
114 Assert.IsTrue(config.ViewEngines.Exists(WebFormsViewEngineSpecification));
117 [Test]
118 public void ConfigureWithSingleViewEngine_Should_Work_For_Backward_Compatibility()
120 string configXml =
122 <monorail>
123 <viewEngine customEngine=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine,Castle.MonoRail.Framework.Tests"" viewPathRoot=""" + viewFolder + @"""/>
124 </monorail>";
126 XmlDocument doc = new XmlDocument();
127 doc.LoadXml(configXml);
128 ViewEngineConfig config = new ViewEngineConfig();
129 config.Deserialize(doc.DocumentElement);
131 Assert.AreEqual(1, config.ViewEngines.Count);
133 Assert.IsTrue(config.ViewEngines.Exists(TestViewEngineSpecification));
136 static bool TestViewEngineSpecification(ViewEngineInfo engineInfo)
138 return engineInfo.Engine == typeof(TestViewEngine);
141 static bool WebFormsViewEngineSpecification(ViewEngineInfo engineInfo)
143 return engineInfo.Engine == typeof(WebFormsViewEngine);
147 public class TestViewEngine : ViewEngineBase
149 private bool _supportsJSGeneration;
150 private string _viewFileExtension;
151 private string _jsGeneratorFileExtension;
153 public TestViewEngine()
155 _supportsJSGeneration = false;
156 _viewFileExtension = "test";
157 _jsGeneratorFileExtension = "testjs";
160 public override bool SupportsJSGeneration
162 get { return _supportsJSGeneration; }
165 public override string ViewFileExtension
167 get { return _viewFileExtension; }
170 public override string JSGeneratorFileExtension
172 get { return _jsGeneratorFileExtension; }
175 public override object CreateJSGenerator(JSCodeGeneratorInfo generatorInfo,
176 IEngineContext context, IController controller,
177 IControllerContext controllerContext)
179 throw new NotImplementedException();
182 public override void GenerateJS(string templateName, TextWriter output, JSCodeGeneratorInfo generatorInfo,
183 IEngineContext context, IController controller, IControllerContext controllerContext)
185 throw new NotImplementedException();
188 public override void Process(string templateName, TextWriter output, IEngineContext context, IController controller,
189 IControllerContext controllerContext)
191 throw new NotImplementedException();
194 public override void Process(string templateName, string layoutName, TextWriter output,
195 IDictionary<string, object> parameters)
197 throw new NotImplementedException();
200 public override void ProcessPartial(string partialName, TextWriter output, IEngineContext context,
201 IController controller, IControllerContext controllerContext)
203 throw new NotImplementedException();
206 public override void RenderStaticWithinLayout(string contents, IEngineContext context, IController controller,
207 IControllerContext controllerContext)
209 throw new NotImplementedException();