You have several alternative options. If you raise the event in a method dedicated for that purpose (as in your sample), then you can simply mock that method instead. So, in your sample that becomes:
Mock.Arrange(() => s.FireEvent()).DoNothing();
If that's not possible then you can mock the method that adds handlers to the event (the one called when Sample += ... is invoked). You can do this like so:
var mock = Mock.Create<Sample>();
// we need this just for the following arrangement
Mock.ArrangeSet(() => mock.TheEvent +=
null
).IgnoreInstance().IgnoreArguments().DoNothing();
var real =
new
Sample();
// TheEvent += CallMe will now do nothing
real.FireEvent();
// TheEvent is empty<br><br>
Finally, as a third option, you can remove all handlers from the event using reflection at some point where you know the event is just about to be fired, or that no one else will attach to it:
new
PrivateAccessor(real).SetField(
"TheEvent"
,
null
);
real.FireEvent();
// TheEvent is null right now
Caveat: this last option is dependent on the compiler implementation. It will work for event declarations in C# code, but will not work for VB events.