I am working on an application which would take an XHTML.
<documents>
<document>
<span class="style1"> This is some text1 </span>
<span class="style2"> This is some text2 </span>
<span class="style3"> This is some text2 </span>
</document>
</documents>
The values for class attribute are basically styles. Those styles are mapped to certain actions in database. The actions tells my application what to do with those span tags when my application sees those styles.
Style - Action - ReplaceText
Style1 - Remove - NULL
Style2 - Keep - NULL
Style3 - Replace - H1
The application has the following output :-
<documents>
<document>
This is some text1
<span class="style2"> This is some text2 </span>
<h1> This is some text2 </h1>
</document>
</documents>
Following is kinda pseudocode I am thinking of:-
foreach(XmlNode documentNode in documentNodes)
{
XmlNode[] spanNodes =documentNode.SelectNodes("//span") ;
foreach(XmlNode spanNode in spanNodes)
{
if(spanNode .Attributes["class"]!=null && !string.IsNullOrEmpty(spanNode .Attributes["class"].value)))
{
string styleName = spanNode.Attributes["class"].value;
string styleActionMapping = GetActionMappingForStyle (styleName);
switch (styleActionMapping)
{
case StyleActionMapping.Remove
RemoveSpanNode(spanNode);
break;
case StyleActionMapping.ReplaceWith
ReplaceSpanNode(spanNode);
break;
case StyleActionMapping.Keep
break;
}
}
}
}
The input could be quite more complex than what I showed above and the application could be very prone to bugs. S, I wanted to use unit testing so that when one makes any changes to the app, i can run the unit tests and be confident of them being working still. So, I wanted to have a simple table like this with pre-populated data:-
Id - Scenario - Input - ExpectedOutput
and I want to test with my app code with this unit testing data using Visual studio.NET 2010. Could anybody provide me directions on this.
Sorry for this long question. I am a newbie in unit testing and I just wanted to be as much clear as possible. Feel free to ask questions.