1 // Copyright 2004-2008 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
.Configuration
18 using System
.Collections
.Generic
;
21 using Castle
.MonoRail
.Framework
.Configuration
;
22 using Castle
.MonoRail
.Framework
.Internal
;
23 using Castle
.MonoRail
.Framework
.Views
.Aspx
;
24 using NUnit
.Framework
;
27 public class ViewEngineConfigTestCase
29 private string viewFolder
= AppDomain
.CurrentDomain
.BaseDirectory
;
32 public void ShouldProcessAdditonalSourcesElement_IfConfiguringSingleViewEngine()
38 <assembly>Castle.MonoRail.Framework.Tests</assembly>
41 <viewEngine viewPathRoot=""" +
46 <assembly name=""Castle.MonoRail.Framework.Tests"" namespace=""Castle.MonoRail.Framework.Tests.Content"" />
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");
60 public void ShouldProcessAdditionalSourcesElement_IfConfiguringMultipleViewEngines()
66 <assembly>Castle.MonoRail.Framework.Tests</assembly>
69 <viewEngines viewPathRoot=""" +
72 <add type=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine, Castle.MonoRail.Framework.Tests"" />
74 <assembly name=""Castle.MonoRail.Framework.Tests"" namespace=""Castle.MonoRail.Framework.Tests.Content"" />
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");
88 public void ConfigureWithMultipleViewEngines_AssignedEnginesToViewEnginesProperty()
93 <assembly>Castle.MonoRail.Framework.Tests</assembly>
95 <viewEngines viewPathRoot=""" + viewFolder
+ @""">
97 type=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine,
98 Castle.MonoRail.Framework.Tests"" />
100 type=""Castle.MonoRail.Framework.Views.Aspx.WebFormsViewEngine,
101 Castle.MonoRail.Framework"" />
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
));
118 public void ConfigureWithSingleViewEngine_Should_Work_For_Backward_Compatibility()
123 <viewEngine customEngine=""Castle.MonoRail.Framework.Tests.Configuration.TestViewEngine,Castle.MonoRail.Framework.Tests"" viewPathRoot=""" + viewFolder
+ @"""/>
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();