I've created a custom helper according to instructions here and here. Here's a snippet of what it looks like (ThemeHelper.cs)
:
@inherits Helpers.HelperPage
@using System.Web.Mvc
@using System.Web.Mvc.Html
@...
@helper PathTo(string fileName) {
@Url.Content("~/Content/Themes/" + Theme.CurrentTheme.FolderName + "/" + fileName);
}
I've placed this in App_Code, as instructed. I can use these helpers in my views, which is what I want.
Now my question is, how do I test this thing? I cannot, for example, reflectively get an instance of the ThemeHelper
class, neither in the current assembly nor by reflectively accessing the App_Code
or __Code
assemblies (neither of which actually return).
Ideally, I would like to somehow call these functions and verify the results/HTML. I have a framework in place (C# version of HtmlUnit 2.7) that allows me to request URLs and verify the HTML.
Is there a way to test my custom helper? I would like to write something like:
ThemeHelper h = new ThemeHelper(); // or: Assembly.CreateInstance(...) or something
string html = h.PathTo("Site.css");
Assert.IsTrue(html.contains("Themes");