问题
Is it possible to simulate an event using Rhino Mocks framework without getting the exception below?
A first chance exception of type 'System.NotSupportedException' occurred in Rhino.Mocks.dll - Can't create mocks of sealed classes
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());
}
}
}
来源:https://stackoverflow.com/questions/16648994/rhino-mock-throws-an-exception-when-raising-an-event