nunit testing data reader

D

Darren Guy

If this is in the wrong newsgroup, my apologoes, and please tell me the
correct newsgroup to repost in

Been using nunit for new project that I am working on, but have now hit a
stumbling block.

I am calling a routine that will return a data reader, but i do not know how
to test what is returned for a data reader.
I have searched and can find no examples of using nunit to test a data
reader.

I could strip it out to test each row in a loop, but i dont want to do that
as I am sure there has got to be an easier way to test than this.

If anybody could give me some examples to help me out, most grateful


Thanks in advance



Darren
 
G

Guest

The idea behind testing is ensuring that a known input gives consistent
output. As such, rolling through the DataReader and comparing to a set of
known values is the best way. How you accomplish this is up to you.

Consider running against an XML file of expected values, etc. and running
against the DataReader.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
D

Darren Guy

Consider running against an XML file of expected values, etc. and running
against the DataReader.

---

Gregory:

thats what i figured. Now as this is my 1st attempt at navigating an xml
file, I am not so sure that what i have done is totally correct, or can be
improved
This is the contents of the xml file that I will be checking against

<?xml version="1.0" encoding="utf-8" ?>
<TestServices>
<TestService>
<UserID>1</UserID>
<service>1</service>
<description>HelpDesk</description>
<ForeGroundColour>0</ForeGroundColour>
<BackGroundColour>16744576</BackGroundColour>
<DefaultCallSource>0</DefaultCallSource>
<OptionFlag>0</OptionFlag>
</TestService>
<TestService>
<UserID>1</UserID>
<service>2</service>
<description>External</description>
<ForeGroundColour>0</ForeGroundColour>
<BackGroundColour>-16777201</BackGroundColour>
<DefaultCallSource>8</DefaultCallSource>
<OptionFlag>0</OptionFlag>
</TestService>
</TestServices>

and this is my test

[Test]
public void CheckAdministratorServices()
{
XmlTextReader xmlReader = new
XmlTextReader("../../XMLTestDocuments/GetServices1.xml");
xmlReader.WhitespaceHandling = WhitespaceHandling.None;
xmlReader.MoveToContent();
// TODO: filter the xmldocument by userid
HelpDesk wasHelpDesk = new HelpDesk();
IDataReader dr = wasHelpDesk.GetUserServices(1);
string Expected, Received;
xmlReader.MoveToElement();
while ( dr.Read() )
{
// make sure that position on 1st element that needs to be checked
while ( xmlReader.Read() )
{
Expected = xmlReader.Name;
if ( Expected.CompareTo("service") == 0 )
{
xmlReader.Read(); // move to the XmlNodeType.Text
break;
}
}
for (int jj=0; jj < dr.FieldCount; jj++)
{
Received = dr.GetValue(jj).ToString();
Expected = xmlReader.Value;
Assert.AreEqual(Expected, Received);
xmlReader.Read();
if ( xmlReader.NodeType == XmlNodeType.EndElement )
xmlReader.Read();
if ( xmlReader.NodeType == XmlNodeType.Element )
xmlReader.Read();
}
}
}

It does run through and passes the test, but I am not happy about
xmlReader.Read() code that I have scattered throughout the function. Is
there a better way get the value to test? or just stick with what I have.


Thanks in advance


Darren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top