Fixing an issue where setting a custom property on a handler will not propagate it...
[castle.git] / Components / General / TemplateEngine / Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests / NVelocityTestCase.cs
blob278b465acf922c2a962043214938951beffa6268
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.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests
17 using System;
18 using System.IO;
19 using System.Collections;
20 using System.ComponentModel;
22 using NUnit.Framework;
25 [TestFixture]
26 public class NVelocityTestCase
28 [Test]
29 public void SimpleTemplateProcessing()
31 String path = Path.Combine(
32 AppDomain.CurrentDomain.BaseDirectory,
34 Path.Combine(System.Configuration.ConfigurationManager.AppSettings["tests.src"], "templates"));
36 ITemplateEngine engine = new NVelocityTemplateEngine(path);
37 (engine as ISupportInitialize).BeginInit();
39 StringWriter writer = new StringWriter();
41 Assert.IsTrue( engine.Process(new Hashtable(), "simple.vm", writer) );
43 Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString());
46 [Test]
47 public void SimpleTemplateProcessingWithinResource()
49 NVelocityTemplateEngine engine = new NVelocityTemplateEngine();
51 engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests");
53 (engine as ISupportInitialize).BeginInit();
55 StringWriter writer = new StringWriter();
57 string templateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests/compiledres/simple.vm";
58 Assert.IsTrue( engine.Process(
59 new Hashtable(),
60 templateFile,
61 writer) );
63 Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString());
67 [Test]
68 public void SimpleTemplateProcessingWithinTwoResources()
70 NVelocityTemplateEngine engine = new NVelocityTemplateEngine();
72 engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests");
73 engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests.SR");
75 (engine as ISupportInitialize).BeginInit();
77 StringWriter writer = new StringWriter();
79 string templateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests/compiledres/simple.vm";
80 Assert.IsTrue(engine.Process(
81 new Hashtable(),
82 templateFile,
83 writer));
85 Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString());
87 // clear the writer for the second run
88 writer = new StringWriter();
90 string secondTemplateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests.SR/compiledres/simple.vm";
91 Assert.IsTrue(engine.Process(
92 new Hashtable(),
93 secondTemplateFile,
94 writer));
96 Assert.AreEqual("This is the second simple template", writer.GetStringBuilder().ToString());
101 [Test]
102 public void ShouldProcessAStringTemplate()
104 NVelocityTemplateEngine engine = new NVelocityTemplateEngine();
106 (engine as ISupportInitialize).BeginInit();
108 StringWriter writer = new StringWriter();
109 StringWriter contextWriter = new StringWriter();
111 string template = "This is a simple template";
112 string contextTemplate = "This is a simple $templateType template";
113 IDictionary context = new Hashtable();
114 context.Add("templateType", typeof(NVelocityTemplateEngine).Name);
116 Assert.IsTrue(engine.Process(new Hashtable(), "ShouldProcessAStringTemplate", writer, template));
118 Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString());
120 Assert.IsTrue(engine.Process(context, "ShouldProcessAStringTemplate", contextWriter, contextTemplate));
122 Assert.AreEqual("This is a simple NVelocityTemplateEngine template", contextWriter.GetStringBuilder().ToString());
125 [Test]
126 public void ShouldProcessATextReaderTemplate()
128 NVelocityTemplateEngine engine = new NVelocityTemplateEngine();
130 (engine as ISupportInitialize).BeginInit();
132 StringWriter writer = new StringWriter();
133 StringWriter contextWriter = new StringWriter();
135 string template = "This is a simple template";
136 string contextTemplate = "This is a simple $templateType template";
137 IDictionary context = new Hashtable();
138 context.Add("templateType", typeof(NVelocityTemplateEngine).Name);
140 Assert.IsTrue(engine.Process(new Hashtable(), "ShouldProcessAStringTemplate", writer, new StringReader(template)));
142 Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString());
144 Assert.IsTrue(engine.Process(context, "ShouldProcessAStringTemplate", contextWriter, new StringReader(contextTemplate)));
146 Assert.AreEqual("This is a simple NVelocityTemplateEngine template", contextWriter.GetStringBuilder().ToString());