Can't mock MouseUp event on UserControl?

41 views
Skip to first unread message

Claudio Lassala

unread,
Dec 22, 2008, 3:04:54 PM12/22/08
to Rhino.Mocks
Hi all,

first and foremost, I'm new to Rhino Mocks, so bear with me
there... :)

I have a UserControl class in a WPF app that looks sort of like this:

public class SelectorDisplayView : UserControl
{
public bool Active { get; set; }

protected void SelectorDisplayView_MouseUp(object sender,
MouseButtonEventArgs e)
{
this.Active = true;
}
}

I'm trying to write a test to make sure the Active property gets set
whenever the control has been clicked. I thought I could use Rhino's
EventRaiser to raise the MouseUp event and test my code, so I wrote
the test like so:

[TestMethod]
public void
Active_property_should_be_set_to_true_when_view_has_been_clicked()
{
var mockRepository = new MockRepository();
m_View = mockRepository.PartialMock<SelectorDisplayView>
();

m_View.MouseUp += delegate { };
var mouseUpRaiser = LastCall.IgnoreArguments
().GetEventRaiser();

mockRepository.ReplayAll();

bool eventWasRaised = false;
m_View.ActiveChanged += (sender, e) => eventWasRaised =
true;

mouseUpRaiser.Raise(m_View, EventArgs.Empty);

Assert.IsTrue(eventWasRaised);

mockRepository.VerifyAll();
}

The test fails with the following error:

System.InvalidOperationException: Invalid call, the last call has been
used or no call has been made (make sure that you are calling a
virtual (C#) / Overridable (VB) method).

I'm not sure what I'm doing wrong here... any clue?

Ayende Rahien

unread,
Dec 22, 2008, 7:46:24 PM12/22/08
to Rhino...@googlegroups.com
MouseUp is likely not virtual

Claudio Lassala

unread,
Dec 23, 2008, 5:40:09 PM12/23/08
to Rhino.Mocks
I'm confused... so the event has to be flagged virtual in the class
for one to be able to raised it using the EventRaiser?

Ayende Rahien

unread,
Dec 23, 2008, 10:49:29 PM12/23/08
to Rhino...@googlegroups.com
Yes
Reply all
Reply to author
Forward
0 new messages