【发布时间】:2013-12-12 22:23:53
【问题描述】:
我在 VS2012 中使用 Microsoft Fakes 框架。
我使用以下代码填充我的类型的 instance 方法。
using (ShimsContext.Create())
{
ShimDateTime.NowGet = () => { return new DateTime(1949, 10, 1); };
DateTime now = DateTime.Now; // shim works for the static property DateTime.Now.
Class1 dependency = new Class1();
using (ShimsContext.Create())
{
ShimClass1 shim1 = new ShimClass1();
StubClass1 stub1 = new StubClass1();
shim1.method1 = () => { return "shim method1"; };
shim1.IMethod1 = () => { return "shim IMethod1"; };
String s1 = dependency.method1();// shim doesn't work for the instance method.
String s2 = dependency.IMethod1();// shim doesn't work for the instance method.
}
class1 如下所示:
public class Class1 : Interface1
{
public String method1()
{
return "real method1";
}
//Interface 1 member
public string IMethod1()
{
return "real IMethod1";
}
}
我希望 s1 和 s2 是匀场输出,但它仍然是实际输出。
为什么?
【问题讨论】:
标签: unit-testing mocking microsoft-fakes