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

I have been trying to create some unit tests for the following code:

void SecurityInitialized(PassedObject pObj) {
_dispatcher.BeginInvoke((CrossAppDomainDelegate) delegate() {

            try {
            catch (Exception exception) {


_dispatcher is an object of System.Windows.Forms.Form class. Is there a way to mock the pObj object from the inside of the BeginInvoke?

I have tried:

Mock pObjMock = MockManager.MockObject(typeof(PassedObject));

and calling the SecurityInitlialized method

but it does not work. Typemock says that:

Not all expectations where called:
Method PassedObject.DoSomething has 1 more expected calls.
asked by tbarto (1.1k points)

1 Answer

0 votes
Did you passed the mocked instance to the SecurityInitialized method?
ClassUnderTest classUnderTest = new ClassUnderTest();
classUnderTest.SecurityInitialized(pObjMock.Object as PassedObject);

:arrow: Remember when you create a MockObject the Isolator create an instance and mock it. So the expectations are made on the instance in MockObject.Object and not on future object.

Hope it helps.
If it still doesn't work please post here the full test code and we'll try to help you.
answered by ohad (35.4k points)