我需要为一个十年以上历史的代码编写单元测试,以下逻辑位于具体类的构造函数中。如何为这样的遗留代码编写单元测试/模拟测试?我使用MSTest/RhinoMocks框架和带有.Net framework 4.0的VS 2010 IDE。
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
}
}
}