ControllerActionInvoker for invoking an action with parameters

I use ControllerActionInvoker to call unit tests of controls

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

How to use it to call an action with parameters?

 [AcceptVerbs( HttpVerbs.Post )] [ActionException( SomeAttribute )] public SomeResult AddMethod( long[] Ids ) { //some code } 
+6
asp.net-mvc
source share
2 answers

You should not use ControllerActionInvoker from your unit tests. What are you really trying to accomplish?

If you are trying to check the behavior of your actions, just name them directly (these are normal methods). If you are trying to test the behavior of your filters, create a context layout for the filter and call its OnXxx () method.

+1
source share

The documentation shows that you want to use the InvokeActionMethod method, which allows you to pass parameters to an IDictionary as the third argument.

ControllerContext actually stores additional data that the controller will use for binding (filters, model bindings, route data). Your argument must be passed through a ControllerContext.

I found an example about unit test controllers .

0
source share

All Articles