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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I seem to be having the opposite problem that the person in this thread (https://www.typemock.com/community/viewtopic.php?t=396) was having. I have an interface derived from another interface. I have events defined in each. I can successfully mock the events in the base interface, but I cannot use the ones defined in the derived interface. Here's some sample code. The MockedEvent I get from this code points to the base interface's event. When I try to mock only the derived event, I get an exception saying that no events were mocked when I try to fire the event.


namespace Tests
{
    public interface IBase
    {
        event EventHandler<EventArgs> BaseEvent1;
    }

    public interface IDerived : IBase
    {
        event EventHandler<EventArgs> DerivedEvent1;
    }

    public class EventSubscriber
    {
        private IDerived obj;

        public EventSubscriber(IDerived arg)
        {
            obj = arg;
            obj.BaseEvent1 += BaseEvent1Handler;
            obj.DerivedEvent1 += DerivedEvent1Handler;
        }

        private void DerivedEvent1Handler(object sender, EventArgs e) {}

        private void BaseEvent1Handler(object sender, EventArgs e) {}
    }

    [TestFixture]
    public class EventTests
    {
        [Test]
        public void test_event_hookups()
        {
            MockManager.Init();
            IDerived obj = RecorderManager.CreateMockedObject<IDerived>(StrictFlags.ArbitraryMethodsAllowed);

            MockedEvent baseEvent, derivedEvent;
            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                obj.BaseEvent1 += null;
                baseEvent = RecorderManager.LastMockedEvent;
                
                obj.DerivedEvent1 += null;
                derivedEvent = RecorderManager.LastMockedEvent;
            }
            EventSubscriber subscriber = new EventSubscriber(obj);
            baseEvent.Fire(null, null);
            derivedEvent.Fire(null, null);  // this incorrectly points to the baseEvent
        }
        
    }
}


How can I successfully mock my derived interface's event? I'm using the TypeMock evaluation version 4.1.0.0.

thanks,
Chris
asked by cfarmerga (1.8k points)

2 Answers

0 votes
Hi Chris,

you have found a bug :twisted:
We will fix this and send you a patch.
answered by lior (13.2k points)
0 votes
Hi,

The fix for the bug is part of the Typemock Isolator 4.2 version.
You can download it here: https://www.typemock.com/Downloads.php.
answered by gilz (14.5k points)
...