title: ASP.NET MVC: Unit testing controllers that use UrlHelper
body: <p>One of my controllers actions, one that is being called in an Ajax request, is returning an URL to the client side so it can do a redirection. I'm using <code>Url.RouteUrl(..)</code> and during my unit tests this fails since the <code>Controller.Url</code> parameter is not pre-filled.</p>
  
  <p>I tried a lot of things, among others attempting to stub <code>UrlHelper</code> (which failed), manually creating a <code>UrlHelper</code> with a <code>RequestContext</code> that has a stubbed <code>HttpContextBase</code> (which failed on a <code>RouteCollection.GetUrlWithApplicationPath</code> call).</p>
  
  <p>I have searched Google but found virtually nothing on the subject. Am I doing something incredibly stupid using <code>Url.RouteUrl</code> in my Controller action? Is there an easier way?</p>
  
  <p>To make it even worse, I'd like to be able to test the returned URL in my unit test - in fact I'm only interested in knowing it's redirecting to the right route, but since I'm returning an URL instead of a route, I would like to control the URL that is resolved (eg. by using a stubbed <code>RouteCollection</code>) - but I'll be happy to get my test passing to begin with.</p>