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