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
Hi all, I'm using Natural TypeMocks (Enterprise Edition) and I would like to mock calls to every methods to the instance of a concrete class.

Is this possible?

Here is the example :

MyConcreteClass myMockObject = (MyConcreteClass)RecorderManager.CreateMockedObject(typeof(MyConcreteClass));

using (RecordExpectations recorder = new RecordExpectations())
{
recorder.DefaultBehavior.RepeatAlways();
recorder.DefaultBehavior.IgnoreArguments();
recorder.MockAllInstances = true;

// mocked methods calls
new MyConcreteClass();
myMockObject.MyMethod();
myMockObject.MyProperty = "dumb";
string s = myMockObject.MyProperty;
}


Here the sample code do record every single mocked method calls (and if it miss just one then MockManager.Verify will fail) but what I'm looking for is a way to automatically mock all methods calls with 1 line of code.

TIA (luKa)
asked by luka (600 points)

1 Answer

0 votes
Luka hi,

Currently there is no such API.
The fastest way to a achieve what you need will probably be to use System.Reflection to extract the class methods list, and then using our reflective API set a dummy expectation on each method.

In any case we have added your request to our to do list
than you for this report.
answered by lior (13.2k points)
...