Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4008296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:44:14+00:00 2026-05-20T08:44:14+00:00

Quite simply I want to be able to test that a Asp.Net web forms

  • 0

Quite simply I want to be able to test that a Asp.Net web forms server control is outputting the correct Html as it will be building dynamic content. I’m just starting to create the control and wanted to do it in a TDD style building up the Html that gets output.

I’ve created a separate class to do the actual Html building so that I am able to test it in isolation outside of the normal Asp.Net pipeline.

In my unit tests I can control what html is returned but I’m having problems confirming that the html contains the markup I am expecting for example:

<div id="wrapper">
    <div id="fields">
    </div>
    <div id="main">       
    </div> 
</div>

and as I’m using Nunit I would like to be able to store the output from the server control and test it by using Is.StringMatching like:

Assert.That(output, Is.StringMatching("<div id=\"main\">.*?</div>"));

This unfortunately won’t work because of the extra \r \n \t instructions that the HtmlTextwriter outputs.

The way I’m currently using it is by creating a StringWriter and then using it to create the HtmlTextWriter like this:

    stringWriter = new StringWriter();
    htmlTextWriter = new HtmlTextWriter(stringWriter);

and I then call the following method:

public string Build(HtmlTextWriter writer)
{

    writer.AddAttribute(HtmlTextWriterAttribute.Id, "wrapper");
    writer.RenderBeginTag(HtmlTextWriterTag.Div);

    writer.AddAttribute(HtmlTextWriterAttribute.Id, "fields");
    writer.RenderBeginTag(HtmlTextWriterTag.Div);
    writer.RenderEndTag();
    writer.WriteLine();
    writer.AddAttribute(HtmlTextWriterAttribute.Id, "main");
    writer.RenderBeginTag(HtmlTextWriterTag.Div);
    writer.RenderEndTag();
    writer.RenderEndTag();



    return writer.InnerWriter.ToString();
}

As the Html gets more complex I can forsee additional problems verifying that the output is correct.

An additional constraint is the requirement to be able to run the tests via a CI server (most likely TeamCity) so all code or referenced libraries need to sit in my solution.

I’ve done a fair bit of googling but cannot seem to find much about how to test the Html output can anybody offer any suggestions for the best way forward?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:44:14+00:00Added an answer on May 20, 2026 at 8:44 am

    You could make sure that your html output is well-formed xml. Then, in your testing code, load the output into an XmlDocument, thus you’re free of all whitespace issues. You can then check that all the tags are really there, and are where they are supposed to be with the XmlDocument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a design that uses custom styled submit-buttons. They are quite simply
ASP.NET MVC app, close to completion, then it was decided that it needed a
Today we faced a quite simple problem that were made even simpler by the
I am trying to accomplish something that seemed quite simple... I have 3 div
I've used ConfigParser for quite a while for simple configs. One thing that's bugged
I've got a simple calendar displaying some events, that's not quite giving me the
I have looked all over but can't find an answer to this... Quite simply
Quite simple really: var req:URLRequest=new URLRequest(); req.url=http://somesite.com; var header:URLRequestHeader=new URLRequestHeader(my-bespoke-header,1); req.requestHeaders.push(header); req.method=URLRequestMethod.GET; stream.load(req); Yet,
I am implementing a quite simple state-machine order processing application. It is a e-commerce
It's quite a simple question - how do I sort a collection? I've got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.