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
In upgrading from 4.1.x to 5.4.x, many existing NaturalMock tests fail because of a new feature that automatically mocks data fields in objects. To resolve this problem, our engineers have to make the following change:
recorder.DefaultBehavior.AutomaticFieldMocking = False

Problem is that this change must be made to every single test, which is a lot of work. Is there some way to change the default behavior without having to modify every single test ?
asked by cabin (2.3k points)

1 Answer

0 votes
Hi Cabin,

Sorry there is no easy clean way to do that :(

As a workaround you can create a method that returns a RecordExpectations instance with default behavior that you want
private RecordExpectations CreateRecorder()
{
    RecordExpectations recorder = RecorderManager.StartRecording();
    recorder.DefaultBehavior.AutomaticFieldMocking = false;
    return recorder;
}


Than replace the creation of RecordExpectations and use it like this:
using (RecordExpectations recorder = CreateRecorder())
{
   // ...
}


You can write a visual studio macro that will do the replace automatically.
answered by ohad (35.4k points)
...