I have a simple event which does not derive from event args. It seems that there is no way to raise these events on mocked objects: -
It appears that either (a) you must create a custom delegate rather than using EventHandler<T>, or (b) create a full class that inherits from EventArgs. If so - this is slightly cumbersome to use. It would be much better if there were no restriction that the type of T on EventHandler must derive from EventArgs.
public
interface
IFoo
{
event
EventHandler<
string
> Message;
}
[Fact]
public
void
Sample()
{
bool
fired =
false
;
var create = Mock.Create<IFoo>();
create.Message += (o,e) => fired =
true
;
Mock.Raise(() => create.Message +=
null
,
"Test"
);
//bang
Assert.True(fired);
}
It appears that either (a) you must create a custom delegate rather than using EventHandler<T>, or (b) create a full class that inherits from EventArgs. If so - this is slightly cumbersome to use. It would be much better if there were no restriction that the type of T on EventHandler must derive from EventArgs.