Hi,

I have a problem that is best described on the example. Here is the
class that is under the test:

public class A
{
    public virtual event EventHandler TestEvent;

    public void TestEventHandler(object sender, EventArgs e) { }

    public void SubscribeChildToEvent(A child)
    {
        TestEvent += child.TestEventHandler;
    }
}

I want to test if the child.TestEventHandler method is subscribed to
the TestEvent. Here is the test:

[TestMethod]
public void TestEventSubscription()
{
    A parent = _Mocks.PartialMock<A>();
    A child = _Mocks.PartialMock<A>();

    parent.TestEvent += child.TestEventHandler;

    _Mocks.ReplayAll();

    parent.SubscribeChildToEvent(child);

    _Mocks.VerifyAll();
}

The test fails saying: The method TestEventSubscription threw
exception: ExpectationViolationException: A.add_TestEvent
(System.EventHanlder); Expected #1, Actual #0.

However, if I subscribe to the same event with the same handler
explicitely, the test passes:

[TestMethod]
public void TestEventSubscription()
{
    A parent = _Mocks.PartialMock<A>();
    A child = _Mocks.PartialMock<A>();

    parent.TestEvent += child.TestEventHandler;

    _Mocks.ReplayAll();

    parent.TestEvent += child.TestEventHandler;

    _Mocks.VerifyAll();
}

My question is: why event subscription in mocks cannot be verified? I
hope the answer helps me to resolve my issue.

Thanks,
Vitaly

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to