1 // Copyright 2004-2007 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
.Views
.Brail
.Tests
18 using System
.Configuration
;
21 using NUnit
.Framework
;
25 public class JustViewFixture
: BaseControllerTest
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
));
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());
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
));
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
;