First, let me say I've searched on this topic and did come across a solution here:
asp.net mvc: how to mock Url.Content("~")?
However, this solution involves creating a new base controller which, in my current scenario, is not something I have permission to do. So, the question...
I'm writing some unit tests currently for an MVC3 app (the first written by my current employer so I really am trying to drive home the benefits of unit testing [while being relatively new to unit testing myself]) and I've hit a snag with Url.Content
The application has an action as follows:
[HttpGet]
public ActionResult SearchResults()
{
...
...
...
if(results == null)
{
DisplayMessageInView("...Some display message...");
return RedirectToAction("Index");
}
where DisplayMessageInView is defined as
private void DisplayMessageInView(string message)
{
string imageUrl = Url.Content("~/Content/Images/109_AllAnnotations_Info_48x48_72.png");
TempData["AlertMessage"] = string.Format("<img alt='info' src='{0}' /> {1}", imageUrl, message);
}
So, they're building a message and an image to diplay to the user on the Index action. Url.Content gets in the way of unit testing this so I'm looking for suggestions to resolve/work around this.
I do have an alternative solution that involves a little more effort and refactoring, but figured this was a good discussion point either way as I've run up this a few times prior and always had to do something a little out of the ordinary.
Short of the solution above, what other options are there to push beyond this? Your input is appreciated.
Thank You