title: ASP.NET MVC - Unit testing HTML that is generated by TagBuilders
body: <p>I have code that generates html via <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.tagbuilder.aspx" rel="nofollow">TagBuilders</a> How could I test if the right HTML is generated? My TagBuilder is not as simple as just one tag, it also contains other tags. So I have a function that returns TagBuilder object with following HTML</p>
  
  <pre><code>&lt;div&gt; 
     &lt;input type="checkbox" name=".." /&gt; &lt;label for=".." /&gt;
     &lt;input type="checkbox" name=".." /&gt; &lt;label for=".." /&gt;
     &lt;input type="checkbox" name=".." /&gt; &lt;label for=".." /&gt;
  &lt;div/&gt;
  </code></pre>
  
  <p>So, to test if we have first checkbox we do:  </p>
  
  <pre><code>Assert.True(MyTag.InnerHtml.Contains("&lt;input type="checkbox" name=".." /&gt;");  
  </code></pre>
  
  <p>This seems wrong.  Is there another way to do this? </p>