如何使用 MS Moles 向鼹鼠发起事件?
Moles 文档描述了如何在类存根上引发事件,但相同的方法不适用于完整的 Mole。您可以将委托添加到添加/删除方法中,但无法手动引发事件。
我能想到的唯一解决方案是在正在测试的类上创建 RaiseEvent() 方法,但这有点违背了使用摩尔的目的。
有什么建议吗?
The Moles documentation describes how to raise events on class stubs but the same method doesn't work with a full Mole. You can add a delegate to the add / remove methods, but you can't manually raise the event.
The only solution I can think of is to create a RaiseEvent() method on the class being tested, but that kinda defeats the point of using moles.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,您可以在事件上使用 Add 方法并获取其中的事件处理程序。一旦有了事件处理程序,您就可以手动调用它,模拟事件。
It turns out you can Mole the Add method on the event and grab the event handler there. Once you have the event handler, you can just Invoke it manually, simulating the event.