Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Controllers / SmartDispatcherSimpleBindingTestCase.cs
blob2e3e5f91b140854b3a4fb56248d18d98ed4e9eef
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.Controllers
17 using System.Collections;
18 using NUnit.Framework;
19 using Test;
21 [TestFixture]
22 public class SmartDispatcherSimpleBindingTestCase
24 private MockEngineContext engineContext;
25 private MockServices services;
26 private MockResponse response;
27 private MockRequest request;
29 [SetUp]
30 public void Init()
32 request = new MockRequest();
33 response = new MockResponse();
34 services = new MockServices();
35 engineContext = new MockEngineContext(request, response, services, null);
38 [Test]
39 public void CanInvokeWithoutParamsToFill()
41 SDController controller = new SDController();
43 IControllerContext context = services.ControllerContextFactory.
44 Create("", "home", "stringparam", services.ControllerDescriptorProvider.BuildDescriptor(controller));
46 controller.Process(engineContext, context);
48 Assert.IsTrue(controller.parameters.Count != 0);
49 Assert.IsNull(controller.parameters[0]);
52 [Test]
53 public void CanFillSimpleNameParametersWithDataFromParams()
55 SDController controller = new SDController();
57 request.Params.Add("name", "hammett");
59 IControllerContext context = services.ControllerContextFactory.
60 Create("", "home", "stringparam", services.ControllerDescriptorProvider.BuildDescriptor(controller));
62 controller.Process(engineContext, context);
64 Assert.IsTrue(controller.parameters.Count != 0);
65 Assert.AreEqual("hammett", controller.parameters[0]);
68 [Test]
69 public void CanFillSimpleNameParametersWithDataFromCustomParams()
71 SDController controller = new SDController();
73 IControllerContext context = services.ControllerContextFactory.
74 Create("", "home", "stringparam", services.ControllerDescriptorProvider.BuildDescriptor(controller));
76 context.CustomActionParameters["name"] = "hammett";
78 controller.Process(engineContext, context);
80 Assert.IsTrue(controller.parameters.Count != 0);
81 Assert.AreEqual("hammett", controller.parameters[0]);
84 [Test]
85 public void CustomParamsHasPrecedenceOverParams()
87 SDController controller = new SDController();
89 IControllerContext context = services.ControllerContextFactory.
90 Create("", "home", "stringparam", services.ControllerDescriptorProvider.BuildDescriptor(controller));
92 context.CustomActionParameters["name"] = "hammett";
93 request.Params.Add("name", "john doe");
95 controller.Process(engineContext, context);
97 Assert.IsTrue(controller.parameters.Count != 0);
98 Assert.AreEqual("hammett", controller.parameters[0]);
101 [Test]
102 public void CanConvertSimpleParameter()
104 SDController controller = new SDController();
106 request.Params.Add("age", "1");
108 IControllerContext context = services.ControllerContextFactory.
109 Create("", "home", "IntParam", services.ControllerDescriptorProvider.BuildDescriptor(controller));
111 controller.Process(engineContext, context);
113 Assert.IsTrue(controller.parameters.Count != 0);
114 Assert.AreEqual(1, controller.parameters[0]);
117 #region Controllers
119 class SDController : SmartDispatcherController
121 public ArrayList parameters = new ArrayList();
123 public void StringParam(string name)
125 parameters.Add(name);
128 public void IntParam(int age)
130 parameters.Add(age);
134 #endregion