I'm trying to learn unit testing, and have this super simple class, with unit test:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new HomeViewModel
{
LogoUrl = this.Url.Content("~/Images/product.png")
});
}
}
[TestMethod]
public void Index()
{
Assert.IsNotNull(new HomeController().Index() as ViewResult);
}
I'm getting null reference exceptions. It's related to using this.Url()
without an HttpContext
in the unit test, I believe.
How can I get the unit test to pass while still using my this.Url()
? I'm fine with using Moq. :)