Is there any sophisticated way how to unit test the results of HtmlHelpers? For example I have a helper that generates html markup for my custom inputs (I am using TagBuilder inside). The result is IHtmlString which I have to convert to string and compare it with expected string in unit tests. But this becomes very complicated, since in html I dont care about attributes order, I have to escape expected strings etc. Any ideas how to test it more cleaner?
SOLUTION: Based on comments and answers bellow I have started to write unit tests using HtmlAglityPack. Code looks like this:
var states = new[] { MultiStateInputState.Unknown, MultiStateInputState.Yes, MultiStateInputState.No };
var actual = Html.Abb().MultiStateInput(states).Name("myinput").ToHtmlString();
var doc = new HtmlDocument();
var actualTextInput = doc.DocumentNode.ChildNodes.First(n => n.Name == "input");
Assert.That(node, Is.Not.Null);
Assert.That(node.Attributes, Is.Not.Null);
Assert.That(node.Attributes, Is.Not.Empty);
var attribute = node.Attributes.Single(a => a.Name == "name");
Assert.That(attribute, Is.Not.Null);
Assert.That(attribute.Value, Is.EqualTo("myinput"));
This is much more better than comparing two strings. No need to take care about attribute order and other stuff.