Today it is way to cumbersome to unittest controllers that uses the Url.Action for example. We need to mock the HttpContext which is too much work for something that should be simple. There are two reasons we need to do this:
1) Controller.Url is read only. If we could set this property it would be much easier. This can be worked around by creating a proxy like this:
private UrlHelper xUrl = null;
public UrlHelper XUrl
return xUrl ?? Url;
xUrl = value;
But then we have problem #2:
Because the UrlHelper is a concrete class and the methods aren't virtual it is not as easy to mock as it should be so even if we could swap the UrlHelper in our tests it would still be problematic to mock it.
What I usually resort to is either set a Func that will resolve the Url when I need it and then just ignore the urls when testing or simply set the url to and empty string if Url is null.