/// <summary> /// Raises the specified event passing the given arguments to the handlers. /// </summary> /// <param name="name">The name of the event to raise.</param> /// <param name="eventArgs">Arguments to pass to the event handlers. Must match the event handler signature exactly.</param> public void RaiseEvent(string name, params object[] eventArgs) { ProfilerInterceptor.GuardInternal(() => { var evt = this.type.GetEvent(name, MockingUtil.AllMembers); MockingUtil.RaiseEventThruReflection(this.instance, evt, eventArgs); }); }
public static void RaiseEventImpl(object instance, EventInfo evt, object[] args) { if (evt == null) { throw new MockException("Unable to deduce which event was specified in the parameter."); } if (args == null) { args = new object[] { null }; } if (args.Length == 1 && (evt.EventHandlerType.IsGenericType && evt.EventHandlerType.GetGenericTypeDefinition() == typeof(EventHandler <>) || evt.EventHandlerType == typeof(EventHandler) || args[0] is EventArgs) ) { args = new[] { instance, args[0] }; } if (!(instance is IMockMixin)) { var mockMixin = MocksRepository.GetMockMixin(instance, evt.DeclaringType); if (mockMixin != null) { instance = mockMixin; } } var mixin = instance as IEventsMixin; if (mixin != null) { mixin.RaiseEvent(evt, args); } else { MockingUtil.RaiseEventThruReflection(instance, evt, args); } }