I'm having a tough go trying to figure out what I need to mock in my tests to show that UrlHelper.RouteUrl() is returning the right URL. It works, but I'd like to have the right test coverage. The meat of the controller method looks like this:
var urlHelper = new UrlHelper(ControllerContext.RequestContext);
return Json(new BasicJsonMessage { Result = true,
Redirect = urlHelper.RouteUrl(new { controller = "TheController",
action = "TheAction",
id = somerecordnumber }) });
Testing the result object is easy enough, like this:
var controller = new MyController();
var result = controller.DoTheNewHotness());
Assert.IsInstanceOf<JsonResult>(result);
var data = (BasicJsonMessage)result.Data;
Assert.IsTrue(data.Result);
result.Redirect is always null because the controller obviously doesn't know anything about the routing. What do I have to do to the controller to let it know? As I said, I know it works when I exercise the production code, but I'd like some testing assurance. Thanks for your help!