TypeMock
它非常强大。我想它能做到。对于Moq或Rhino等其他模拟框架,您需要使用另一种策略。
Rhino或Moq的策略:
类以获取程序集全名。
public class YourClass
{
public string GetFullName()
{
Assembly ass = Assembly.GetExecutingAssembly();
return ass.FullName;
}
}
装配
_Assembly
. 因此,与其使用
您可以直接注入接口。然后,为测试模拟接口就很容易了。
修改后的类:
public class YourClass
{
private _Assembly _assbl;
public YourClass(_Assembly assbl)
{
_assbl = assbl;
}
public string GetFullName()
{
return _assbl.FullName;
}
}
在你的测试中,你嘲笑我
:
public void TestDoSomething()
{
var assbl = MockRepository.GenerateStub<_Assembly>();
YourClass yc = new YourClass(assbl);
string fullName = yc.GetFullName();
//Test conditions
}