I have a HtmlHelper which is used to output some accordion style functionality. This helper is going to be used extensively throughout the site.
The code used to create this functionality makes extensive use of TagBuilder and of course we are outputting the html using:
htmlHelper.ViewContext.Writer.WriteLine(someTag.ToString(TagRenderMode.StartTag));
We have a few helpers which use this pattern and it’s working great.
All good so far – it does exactly what I want. However – testing this is proving to be a nightmare. how do i test htmlHelper.ViewContext.Writer.WriteLine ?
we’re using xUnit and Moq if it matters
When you assert, whatever is written out to Writer.WriteLine will be in the text method’s
textvariable.