Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Actions / ActionMethodExecutorCompatibleTestCase.cs
blobaf254a3a0bb5ec4ea21e39f1704ffc2b24698862
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 System.Collections.Generic;
18 using System.Reflection;
19 using Castle.MonoRail.Framework.Descriptors;
20 using Castle.MonoRail.Framework.Test;
21 using NUnit.Framework;
23 [TestFixture]
24 public class ActionMethodExecutorCompatibleTestCase
26 [Test]
27 public void CompatibleExecutorDelegatesInvocationToControllerUsingDelegate()
29 BaseController controller = new BaseController();
30 ActionMetaDescriptor actionMeta = new ActionMetaDescriptor();
32 ActionMethodExecutorCompatible.InvokeOnController delegateToController = controller.InvokeMethodStub;
34 ActionMethodExecutorCompatible executor =
35 new ActionMethodExecutorCompatible(GetActionMethod(controller), actionMeta, delegateToController);
37 MockRequest req = new MockRequest();
38 MockResponse res = new MockResponse();
39 MockServices services = new MockServices();
40 IEngineContext engineContext = new MockEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));
41 object retVal = executor.Execute(engineContext, controller, new ControllerContext());
43 Assert.IsTrue(controller.WasExecuted);
44 Assert.AreEqual(2, retVal);
47 private MethodInfo GetActionMethod(object controller)
49 return controller.GetType().GetMethod("Action1");
52 public class BaseController : Controller
54 private bool wasExecuted;
56 public object Action1()
58 return 1;
61 public bool WasExecuted
63 get { return wasExecuted; }
66 public object InvokeMethodStub(MethodInfo method, IRequest request, IDictionary<string,object> methodArgs)
68 wasExecuted = true;
69 return 2;