我希望有可能.Object通过Moq中的扩展方法操作模拟,但我没有找到任何适用的扩展方法.
例如:
interface IFoo
{
void Bar();
}
/* ... */
var mock = Mock<IFoo>();
mock.Verify(x => x.Bar());
IFoo foo = mock.Object;
foo.Verify(x => x.Bar()); // this does not compile!
Run Code Online (Sandbox Code Playgroud)
反正我是否可以编写上面的代码(不编译的代码?)如果没有,为什么不呢?
您可能想要使用Mock.Get<T>哪个检索给定对象实例的模拟对象:
Mock.Get(foo).Verify(x => x.Bar());
Run Code Online (Sandbox Code Playgroud)