Rhino Mock throws an exception when raising an event

混江龙づ霸主 提交于 2020-01-06 02:51:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!