I have the following logic in a more than decade old code for which I have to write Unit Tests. It is a concrete class and the following logic lies in the ctor. Is there a good way to write Unit Tests/Mocks for such legacy code. I am using MSTest / RhinoMocks framework and VS 2010 IDE with .Net framework 4.0
public class SomeClass
{
/// ctor
public SomeClass(XmlNode node)
{
//Step 1: Initialise some private variable based on attributes values from the node
//Step 2: Lot of If , else -if statements ---> something like -
if (/*attributeValue is something*/)
{
// Connect to Db, fetch some value based on the attribute value.
// Again the logic of connecting and fetching is in another concrete class
}
else if (/*attributeValue is somthing else*/)
{
// fetch a value by loading a config file (this loading and reading of config file
// is again a singleton class where config file path is hardcoded)
}
else
{
// set some private member variable
}
}
}