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
0 votes
:shock:
I want to check that a particular event is wired to a particular eventhandler during a method call:
e.g.
buttonTest.Click += new EventHandler(buttonTest_Click);


I have mocked the buttonTest to check that button properties get/set OK but am struggling to check that the Click event is hooked up.

Cheers.

c0d3
asked by c0d3-m0nk3y (8.7k points)

1 Answer

0 votes
Hi,
8) See this topic

mock.ExpectCall("add_Click"); 


:roll: We already have plans to add event specific API's, but the above will always work.

:idea: If you want to check that the correct EventHandler is passed you could probably test the argument (use .Args())
and then use the Delegate Method and Target properties to test that the correct event is passed.

:idea: If you want to Change the event handler to a mocked one, you can either mock buttonTest_Click or you can pass a new event handler and TypeMock will switch the argument before the real method gets it. You will need an Enterprise License and the code will look like this.
mock.ExpectUnmockedCall("add_Click").Args(new Assign(new EventHandler(mockedButton_Click)));

then in the test you can create your own handler
answered by scott (32k points)
...