我有一个类,其中有一个无参数构造函数。但是当这个构造函数被调用时,类有五个属性从构造函数的配置文件中获取值。类中有两个方法使用在构造函数中初始化的参数。
我想使用模拟框架为两种方法编写单元测试。但是,我不确定如何初始化构造函数中的参数,因为调用该方法不会为这些属性提供值。
public class ABC
{
public ABC()
{
a = ConfigurationManager.AppSetting["GetValue"];
b = ConfigurationManager.AppSetting["GetValue1"];
}
public int Method1(IDictionary<string, string> dict)
{
d = a + b /2; (how to mock values of a and b while writing unit tests
using mock framework. In reality, a in my case is
dictionary)
//some business logic
return d;
}
}
提前致谢,