More working tests.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Actions / DefaultActionSelectorTestCase.cs
blob7951bec3b8962cab4d6b6d4f9e6e764c963721aa
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.Actions
17 using Castle.MonoRail.Framework.Descriptors;
18 using Castle.MonoRail.Framework.Services;
19 using Castle.MonoRail.Framework.Test;
20 using NUnit.Framework;
22 [TestFixture]
23 public class DefaultActionSelectorTestCase
25 private DefaultActionSelector selector;
26 private MockEngineContext engine;
28 [SetUp]
29 public void Init()
31 selector = new DefaultActionSelector();
33 MockRequest request = new MockRequest();
34 MockResponse response = new MockResponse();
35 MockServices services = new MockServices();
36 engine = new MockEngineContext(request, response, services, new UrlInfo("area", "controller", "action1"));
39 [Test]
40 public void CanSelectMethodAndCreatesAnActionMethodExecutorForIt()
42 ControllerMetaDescriptor controllerMeta = new ControllerMetaDescriptor();
43 BaseClassController controller = new BaseClassController();
44 ControllerContext context = new ControllerContext("baseclass", "", "action1", controllerMeta);
46 controllerMeta.Actions["action1"] = typeof(BaseClassController).GetMethod("Action1");
48 IExecutableAction action = selector.Select(engine, controller, context);
49 Assert.IsNotNull(action);
50 Assert.IsInstanceOfType(typeof(ActionMethodExecutor), action);
53 [Test]
54 public void CanSelectDynActionAndCreatesADynamicActionExecutor()
56 ControllerMetaDescriptor controllerMeta = new ControllerMetaDescriptor();
57 BaseClassController controller = new BaseClassController();
58 ControllerContext context = new ControllerContext("baseclass", "", "action2", controllerMeta);
60 context.DynamicActions.Add("action2", new DummyDynamicAction());
62 IExecutableAction action = selector.Select(engine, controller, context);
63 Assert.IsNotNull(action);
64 Assert.IsInstanceOfType(typeof(DynamicActionExecutor), action);
67 public class BaseClassController : Controller
69 public void Action1()
74 public class DummyDynamicAction : IDynamicAction
76 public object Execute(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
78 return null;