Hi!

I started doing maintenance on an old system, and the first thing I did was to fix a bug in a method that loads a connection string from a custom cml config file.
Here is the code:

Code:
private string GetConnectionstring(string configFilename)
        {
            var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFilename);

            if (XmlDoc == null)
            {
                XmlDoc = new XmlDocument();
                XmlDoc.Load(configFilePath); //load xml-file
            }
            XmlNode statistics = XmlDoc.SelectSingleNode("config/statistics"); //read statistics
            if (statistics != null && !string.IsNullOrEmpty(statistics.InnerText))
            {
                _trackStatisticsFilename = statistics.InnerText;
            }
            return XmlDoc.SelectSingleNode("config/connectionstring").InnerText; //read connectionstring
        }
The fix was replacing some error prone string concatenation with the Path.Combine call. There is no unit test what so ever for this class "DaoFactory" I want to write a unit test for this method, once I ahve made a change to it.

My question is, how "testable" is the above code? It has the following responsibilities

1) It combines two strings to create a filepath in a string
2) It loads an XML document from disk
3) It performs a read on that xml file to set an internal member variable if tracking should be enabled or not
4) It reads the connectionstring element from the file and returns it.

The code has dependencies to other elements outside the "unit"
1) The file system
2) The environment (Appdomain class)
3) The private field _trackStatisticsFilename (should not be tested since it is state and not behaviour)

Caveats:
* The class DAOFactory inherit from an abstract class BaseDAOFactory, sadly not an interface.
* The file system can be mocked using MOQ or something similar





What would YOU do, when confronted with this code? Is there a way to properly unit test it?

My skills when it comes to unit testing is rather limited, I have written a book, and done some work in an existing system which was designed for unit testing and had reviewers that checked all my work. Now I am on my own.

/H