I'm having a little bit of a dilemma. I have a very basic class with functions returning specific XPath query results.
Here is the code I'm currently using.
[TestFixture]
public class MarketAtAGlance_Test
{
private XmlDocument document;
private MarketAtAGlance marketAtAGlance;
[SetUp]
public void setUp()
{
this.document = new XmlDocument();
// load document from file located in the project
this.marketAtAGlance = new MarketAtAGlance(document);
}
[Test]
public void getHourlyImport_Test()
{
Assert.AreEqual(100.0d, marketAtAGlance.getHourlyImport());
}
[Test]
public void getHourlyExport_Test()
{
Assert.AreEqual(1526.0d, marketAtAGlance.getHourlyExport());
}
}
public class MarketAtAGlance
{
XmlDocument document;
public MarketAtAGlance(XmlDocument document)
{
this.document = document;
}
public double getHourlyImport() {
double value = Convert.ToDouble(document.SelectSingleNode("//information[@id=\"dat11\"]/new_val").InnerText);
return value;
}
public double getHourlyExport() {
double value = Convert.ToDouble(document.SelectSingleNode("//information[@id=\"dat12\"]/new_val").InnerText);
return value;
}
}
This is my first use of unit testing so I'm still unsure of many minor things. As you can see, I'm loading a static XML file located on my hard drive. Should I have the extra dependency or put the XML text in a big string? I'm loading an older XML file (with the same format) because I can test with already known values.
Also, how would I go about unit testing an XmlHttpReader (class that takes in an XML url and loads it as a document?
Any comments on my question or comments about the design?