Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: Refactor the UrlHelper so it becomes easier to test [397]

$
0
0
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
{
get
{
return xUrl ?? Url;
}
set
{
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.
Comments: It is dup of http://aspnetwebstack.codeplex.com/workitem/175.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>