1
// Copyright 2004-2008 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
.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
;
23 public class DefaultActionSelectorTestCase
25 private DefaultActionSelector selector
;
26 private MockEngineContext engine
;
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"));
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
);
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
74 public class DummyDynamicAction
: IDynamicAction
76 public object Execute(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)