如何使用具有 ref bool 参数的 Rhino Mocks 引发事件
我正在尝试编写一个测试来涵盖特定类中的错误处理。此类正在侦听具有以下签名的 Error 事件:
OnError(int ErrorNumber, string ErrorText, ref bool retry)
问题出在末尾的 ref bool 变量。我正在使用 Rhino Mocks 创建一个模拟接口进行测试,当我尝试使用以下内容引发错误时:
bool retry = false;
AdapterMock.Raise(x => x.Error += null, 0, "0", ref retry);
它甚至无法编译,告诉我它无法从 ref bool 转换为 Object。
如果我将签名更改为:
bool retry = false;
AdapterMock.Raise(x => x.Error += null, 0, "0", retry);
我编译正常,但测试因 System.InvalidOperationException 失败:参数 #3 是 System.Boolean 但应该是 System.Boolean&
我在这个问题上抓狂了,我该如何在我的模拟中正确地引发这个事件?
I am trying to write a test that covers my error handling in a particular class. This class is listening for an Error event with the following signature:
OnError(int ErrorNumber, string ErrorText, ref bool retry)
The problem is with the ref bool variable at the end. I am using Rhino Mocks to create a mock interface for testing and when I try to raise the error using the following:
bool retry = false;
AdapterMock.Raise(x => x.Error += null, 0, "0", ref retry);
It won't even compile, telling me it can't convert from ref bool to Object.
If I change the signature to:
bool retry = false;
AdapterMock.Raise(x => x.Error += null, 0, "0", retry);
I compiles fine but the test fails with System.InvalidOperationException : Parameter #3 is System.Boolean but should be System.Boolean&
I'm pulling my hair out on this one, how do I properly raise this event in my mock?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
Try: