At the IL level:
public virtual event EventHandler TestEvent;
is translated to something similar to below:
[MethodImpl(MethodImplOptions.Synchronized)]
public virtual void add_TestEvent(EventHandler value)
{
this.TestEvent = (EventHandler) Delegate.Combine(this.TestEvent, value);
}
[MethodImpl(MethodImplOptions.Synchronized)]
public virtual void remove_TestEvent(EventHandler value)
{
this.TestEvent = (EventHandler) Delegate.Remove(this.TestEvent, value);
}
private EventHandler TestEvent;
And your SubscribeChildToEvent method is compiled as:
public void SubscribeChildToEvent(A child)
{
this.TestEvent = (EventHandler) Delegate.Combine(this.TestEvent,
new EventHandler(child.TestEventHandler));
}
You can see that it uses the private field directly instead of calling
the virtual add_TestEvent method. Is this the right thing to do? only
MS knows ;)
To workaround the issue, you can use custom event implementation:
private EventHandler _TestEvent;
public virtual event EventHandler TestEvent
{
add { _TestEvent += value; }
remove { _TestEvent -= value; }
}
HTH,
Kenneth
On Mon, Jul 27, 2009 at 3:25 AM, Vitaly<[email protected]> wrote:
> A parent = _Mocks.PartialMock<A>();
> A child = _Mocks.PartialMock<A>();
>
> parent.TestEvent += child.TestEventHandler;
>
> _Mocks.ReplayAll();
>
> parent.SubscribeChildToEvent(child);
>
> _Mocks.VerifyAll();
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---