chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

I have come across an issue which mixes up the firing of two eventhandlers of the same name under the same interface. It starts with the following implementation

    public class BaseArgs : EventArgs

    {

    }

    public interface IBaseInterface

    {

        event EventHandler<BaseArgs> Handler;

    }

    public class ExtendedArgs : BaseArgs

    {

    }

    public interface IExtendedInterface : IBaseInterface

    {

        new event EventHandler<ExtendedArgs> Handler;

    }

 When we try to add an event to the extended eventhandler and fire the event, then eventhandler is never invoked. This can be seen with the following test case, where the event should have set the bool to true when fired, but it fails at the assert.

     [TestMethod]

     public void TestMethodFail()

     {

         IExtendedInterface targetInterface = Isolate.Fake.Instance<IExtendedInterface>();

         var sentArgs = Isolate.Fake.Instance<ExtendedArgs>();

         bool eventWasCalled = false;

         EventHandler<ExtendedArgs> testEventHandler = new EventHandler<ExtendedArgs>((sender, args) =>

         {

             eventWasCalled = true;

         });

         targetInterface.Handler += testEventHandler;

         Isolate.Invoke.Event(() => targetInterface.Handler += null, targetInterface, sentArgs);

         Assert.IsTrue(eventWasCalled);

     }

We've found that what is likely happening is that the invoker is firing the base eventhandler, as the following test passes

         [TestMethod]

        public void TestMethodPass()

        {

            IExtendedInterface targetInterface = Isolate.Fake.Instance<IExtendedInterface>();

            var sentArgs = Isolate.Fake.Instance<ExtendedArgs>();

            bool eventWasCalled = false;

            EventHandler<BaseArgs> testEventHandler = new EventHandler<BaseArgs>((sender, args) =>

            {

                eventWasCalled = true;

            });

            ((IBaseInterface)targetInterface).Handler += testEventHandler; // Add the event to the base eventhandler instead

            Isolate.Invoke.Event(() => targetInterface.Handler += null, targetInterface, sentArgs);

            Assert.IsTrue(eventWasCalled);

        }

asked by avagadros (600 points)

1 Answer

0 votes
Hi,

Thank you for bringing this to our attention. With the information you gave us, our team was able to reproduce this issue and is currently looking into this.
answered by Erel_TypeMock (2.6k points)

We have provided a patch to the email address you signed up with.

Please take a look, try it when you can and let us know that it works. cool

...