This is a migrated thread and some comments may be shown as answers.

Cannot raise events on non-eventargs derived EventHandler<T>

1 Answer 57 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
Isaac Abraham
Top achievements
Rank 1
Isaac Abraham asked on 20 Nov 2013, 01:20 PM
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: -

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.

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 22 Nov 2013, 12:54 PM
Hi Isaac,

Thank you for reporting this. It appears to be a missing functionality in JustMock. It is now into our backlog and it should be implemented soon. I will notify you upon release. I hope this works for you.

P.S. I have added some Telerik points into your account. Thanks for the feedback once again.

Regards,
Kaloyan
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
JustMock Free Edition
Asked by
Isaac Abraham
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or