testing controller action which returns RedirectToRouteResult
- by csetzkorn
Hi,
I have an action in my controller:
RedirectToRouteResult Create(UserDTO UserDTO)
Which at some point decides with which HTML to respond after a post request by redirecting to an action:
return ModelState.IsValid ? RedirectToAction("ThanksCreate") : RedirectToAction("Register");
In my unit tests I would like to get hold of the ‘views’ modelstate somehow like this:
var modelState = result.ViewData.ModelState;
Assert.IsFalse( modelState.IsValid );
where ‘result’ (ViewResult) is the result of the action ‘Create’ depending on the submitted DTO. My dilemma is that my action ‘returns’ a RedirectToRouteResult which I thought is quite nice but it might not be testable or is it?
How could I get hold of the ModelState in my scenario? Thanks.
Best wishes,
Christian
enter code here