Failing unit tests.

May 18, 2009 at 6:03 AM

I am trying to write unit Tests for BlogEngine.Core.dll. I wrote a unit test for StripHtml function. The test getting failed (Second Assert Statement) for input, which has a comment line (e.g:<!—something --->)in two rows. The same test is getting passed for a comment line which spans in one line.

Now, my doubt is, is it a bug? Or Am I missing something? Or Are my tests wrong? .I know little about Regex.

The test code goes here..


public void StripHtml()


StreamReader reader = new StreamReader("TextFile1.txt");

StringBuilder sb = new StringBuilder();

while (reader.ReadLine() != null)


sb = sb.Append(reader.ReadLine());



Assert.True(!_htmlRegex.Replace(sb.ToString(), string.Empty).Contains(">"));


The second Assert statement is getting failed for a comment line which spans in two rows .

You can reproduce the test results (Pass or Fail) copying any html code into TextFile1.txt, which has a comment line spanned in one row and two rows ,respectively.

I am also providing StripHtml function in Utils.cs in BlogEngine.Core.

private static readonly Regex STRIP_HTML = new Regex("<[^>]*>", RegexOptions.Compiled);

public static string StripHtml(string html)


if (string.IsNullOrEmpty(html))

return string.Empty;

return STRIP_HTML.Replace(html, string.Empty);


Please point me in right direction?



May 30, 2009 at 5:13 AM

Did you try RegexOptions.Multiline ?