Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test HtmlHelpers that call Partial?
    text
    copied!<p>I've been looking at <a href="https://stackoverflow.com/questions/271699/testing-htmlhelpers-in-asp-net-mvc">this</a> Stackoverflow question and have the answer implemented. It works all fine and dandy until I get to call HtmlHelper.Partial in my helper method, which is listed below. I know it might not be the best code, but this is until I can refactor more of the app. The error it throws is</p> <blockquote> <p>Previous method 'ViewContext.get_TempData();' requires a return value or an exception to throw.</p> </blockquote> <p>Am I missing mocking something, or is there a better way to render a usercontrol?</p> <p><strong>Edit</strong> Ok I did miss something, I didn't call mocks.Replay(). Now have another error which it wants something named controller in routeData...progress.</p> <p><strong>Edit #2</strong> Clarifying I'm trying to mock the call to HtmlHelper.Partial(partialPath, model), I just want that to return whatever partialPath I send in I suppose, or at least not blowup. I did find this page <a href="http://andrevianna.com/blog/?p=8" rel="nofollow noreferrer">http://andrevianna.com/blog/?p=8</a> which was very helpful and I almost got things working. This was helpful as well <a href="http://farm-fresh-code.blogspot.com/2009/10/mocking-htmlhelper-class-with.html" rel="nofollow noreferrer">http://farm-fresh-code.blogspot.com/2009/10/mocking-htmlhelper-class-with.html</a></p> <pre><code> public static string RenderRateDetails(this HtmlHelper html, string partialPath, RatesViewData model, RateDetailType type) { switch (type) { case RateDetailType.AR: if (model.ExistingRateDetailAR != null) return html.Partial(partialPath, model).ToString(); break; case RateDetailType.AP: if (model.ExistingRateDetail != null) return html.Partial(partialPath, model).ToString(); break; } return string.Empty; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload