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

2 posts, 0 answers
  1. Isaac Abraham
    Isaac Abraham avatar
    21 posts
    Member since:
    Sep 2009

    Posted 20 Nov 2013 Link to this post

    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.
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 22 Nov 2013 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top