使用RhinoMocks我想提出一个事件,其中事件处理程序签名如下:
MyEventHandler(int a value, ref bool handled) {..}
如果我使用:
myMock.Raise(x => x.MyEventHandler += null, aValue, handled);
我收到以下错误消息: System.InvalidOperationException:参数#2是System.Boolean但应该是System.Boolean&
我尝试过:
myMock.Raise(x => x.MyEventHandler += null, aValue, ref Arg<bool>.Ref(Is.Anything(), handled).Dummy);
但这甚至没有编译......
提出此事件的正确方法是什么?
答案 0 :(得分:0)
看看以下示例
[Test]
public void RaiseEvent()
{
var mock = MockRepository.GenerateMock<IEventsRaiser>();
mock.GetEventRaiser(x => x.MyEvent += null).Raise(1, Arg<bool>.Ref(new Anything(), true).Dummy);
}
public delegate void MyEventHandler(int a, ref bool handled);
public interface IEventsRaiser
{
event MyEventHandler MyEvent;
}