Fixing previous commit (forgot build script).
[castle.git] / MonoRail / Castle.MonoRail.Views.Brail.Tests / JustViewFixture.cs
blob0eea94cfe15bf0691e5f386fbea5a41945ae5f61
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.Views.Brail.Tests
17 using System;
18 using System.Configuration;
19 using System.IO;
20 using Framework;
21 using NUnit.Framework;
22 using TestSupport;
24 [TestFixture]
25 public class JustViewFixture : BaseControllerTest
27 [Test]
28 public void CanRenderViewWithoutUsingFullMonoRailPipeline()
30 BooViewEngine bve = new BooViewEngine();
31 string viewPath = Path.Combine(ConfigurationManager.AppSettings["tests.src"], "Views");
32 bve.Service(new ViewSourceLoaderServiceProvider(viewPath));
33 bve.Initialize();
34 StringWriter sw = new StringWriter();
35 DummyController controller = new DummyController();
36 PrepareController(controller, "", "home", "index");
37 bve.Process(sw, Context, controller, "home/index");
38 Assert.AreEqual("Brail is wonderful", sw.ToString());
41 [Test]
42 public void WithParameters()
44 BooViewEngine bve = new BooViewEngine();
45 string viewPath = Path.Combine(ConfigurationManager.AppSettings["tests.src"], "Views");
46 bve.Service(new ViewSourceLoaderServiceProvider(viewPath));
47 bve.Initialize();
48 StringWriter sw = new StringWriter();
49 DummyController controller = new DummyController();
50 controller.PropertyBag["list"] = new int[] {2, 5, 7, 8};
51 controller.PropertyBag["name"] = "test";
52 PrepareController(controller, "", "home", "index");
53 bve.Process(sw, Context, controller, "home/bag");
54 string expected = @"test is the name
60 Assert.AreEqual(expected, sw.ToString());
63 private class DummyController : Controller
68 internal class ViewSourceLoaderServiceProvider : IServiceProvider
70 private string viewRootDir;
72 public ViewSourceLoaderServiceProvider(string viewRootDir)
74 this.viewRootDir = viewRootDir;
77 #region IServiceProvider Members
79 public object GetService(Type serviceType)
81 if (typeof(IViewSourceLoader) == serviceType)
83 FileAssemblyViewSourceLoader loader = new FileAssemblyViewSourceLoader();
84 loader.ViewRootDir = viewRootDir;
85 return loader;
87 return null;
90 #endregion