是否可以使用 Rhino Mocks 框架模拟事件而不会出现以下异常?
Rhino.Mocks.dll 中出现了“System.NotSupportedException”类型的第一次机会异常 - 无法创建密封类的模拟
public interface IWithEvent
{
event EventHandler RaiseMeWithoutExceptionPlease;
}
[TestClass]
public class MockedEvents
{
[TestMethod]
public void EventsTest()
{
IWithEvent withEvent = MockRepository.GenerateStub<IWithEvent>();
for (int i = 0; i < 500; i++)
{
// 500 exceptions thrown
withEvent.Raise(we => we.RaiseMeWithoutExceptionPlease += null, withEvent, new EventArgs());
}
}
}