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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I think it would be a lot easier to mock method behavior if method/property callbacks where allowed when recording/setting expectations.

It could be achieved by adding a Callback method to the IMockBehavior interface:

Callback(MockMethodCalledEventHandler mockMethodCalled)


Or by adding ExpectAndCallback and Calback methods to the RecordExpectations class:

public IMockBehavior ExpectAndCall(
    object mockedStatements,
    object returnValue,
    MockMethodCalledEventHandler mockMethodCalled
);

public IMockBehavior Call(
    MockMethodCalledEventHandler mockMethodCalled
);
asked by paulo.morgado (11k points)

3 Answers

0 votes
Hi,

As I think I mentioned in another thread, I really like this idea.
so we have added this into our future feature list
answered by lior (13.2k points)
0 votes
Paulo,
You can do this using mock.MethodSettings("method").MockMethodCalled
and mock.MockMethodCalled

here is an example:
Mock mock = MockManager.Mock<TestedClass>();
mock.MockMethodCalled += new MockMethodCalledEventHandler(Callback);
answered by eli (5.7k points)
0 votes
Hi Lior.

I just posted here to make a "formal" feature request. :D

Hi Eli.

I was thinking about Natural Mocks. Would this be the same as this?

recorder.MethodCalled += new MockMethodCalledEventHandler(CallBack);
answered by paulo.morgado (11k points)
...