我可以对使用 Moles 创建的痣类型设定预期吗?
我不仅需要交换实现,还需要添加必要的检查以确保以正确的顺序调用某些方法。我可以想象像 Mole + Mock 这样的东西会给我这个选择。有谁知道Moles有这个功能吗?
这段代码应该有帮助:
// Verify if Dispose was called
MDisposableObject.Constructor = delegate(DisposableObject instance)
{
MDisposableObject mole = new MDisposableObject(instance);
...
// This doesn't work
//objectContext.Expects(i => i.Dispose()).ToBeCalledOneTime();
};
I need to not only swap implementation but also to add necessary check to make sure that certain methods were called in the right order. I can imagine something like Mole + Mock would give me this option. Does anybody know if Moles has this feature?
This code should be helpful:
// Verify if Dispose was called
MDisposableObject.Constructor = delegate(DisposableObject instance)
{
MDisposableObject mole = new MDisposableObject(instance);
...
// This doesn't work
//objectContext.Expects(i => i.Dispose()).ToBeCalledOneTime();
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Moles 的目标是为所有内容提供存根(而不是模拟),即使是静态或密封方法。 Moles 手册中写道,它们不像其他模拟框架那样针对模拟方面:它们提供隔离,而不是模拟。如果你想检查你的鼹鼠的通话,你必须按照自己的方式去做。
例如:
只有 Typemock Isolator (功能强大但昂贵)和 JustMock(新并发,也不是免费的)为所有内容启用模拟功能。
如果您有一些接口、委托和虚拟方法,请使用免费的模拟框架,例如 Moq 或 RhinoMocks。
关于我的示例的警告:到目前为止,我还没有找到如何调用原始构造函数,我的意思是
实际上,从我在 msdn 上读到的内容来看,这是不可能的...我希望以下版本能够实现这一点。
Moles aim to give stubs (and not mocks) for everything, even for static or sealed methods. It's written in the Moles manual that they are not aiming the mocking aspect like others mocking frameworks : they offer isolation, not mocks. If you want to check calls on your Moles, you have to do your own way.
For example:
Only Typemock Isolator (powerfull but expensive) and JustMock of Telerik (new concurrent, also not free) enable mocking features for everything.
If you have some interfaces, delegates and virtual method, use free mocking framework like Moq or RhinoMocks.
A warning about my example: until now I didn't found how to call the orignal constructor, I mean something like
Actually, from what I read on msdn, it's not possible... I hope following releases will enable that.