Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing with ControllerActionInvoker to invoke action with parameters

I use ControllerActionInvoker to invoke controller actions form unit tests

var controllerInvoker = new ControllerActionInvoker();
var result = controllerInvoker.InvokeAction(
                 testController.ControllerContext, "Default" );

How do I use it to call an action that has parameters?

[AcceptVerbs( HttpVerbs.Post )]
[ActionException( SomeAttribute )]
public SomeResult AddMethod( long[] Ids )
{
    //some code
}
like image 363
user99322 Avatar asked Jul 17 '09 19:07

user99322


1 Answers

From the documentation it looks like you want to use the InvokeActionMethod method which allows you to pass parameters in an IDictionary as the third argument.

The ControllerContext actually carries with it additional data that the controller will use for binding (filters, model binders, route data). Your argument will need to be passed through the ControllerContext.

I found an example about unit testing controllers.

like image 179
cfeduke Avatar answered Sep 27 '22 16:09

cfeduke