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
Hi

suppose i have a line like

Isolate.Fake.Instance<LookUpListSearchAlwaysEnableController>(Members.ReturnRecursiveFakes)

using that line all methods (private and public are not executed) am i right?

how can i exclude all methods from isolation?
asked by (28.8k points)

3 Answers

0 votes
Hi,

Check out the CallOriginal flag (on fake creation).
I think thats what you are looking for.
answered by (6.6k points)
0 votes
No

what i need is to fake all properties at any level but fake no method
answered by (28.8k points)
0 votes
Tolisss,

There is no built in way to do what you are describing. You can do it using reflection to get methods and iterating over them to fake them one by one. You would need to use the NonPublic entry point to fake methods based on their name. It should look approximately like this:

// our fake will return recursive fakes for any method or property
var fake = Isolate.Fake.Instance< LookUpListSearchAlwaysEnableController>(Members.ReturnRecursiveFakes);
// iterate over all instance methods
foreach(var method in LookUpListSearchAlwaysEnableController.GetMethods(BindingFlags.Public | BindingFlags.Private | BindingFlags.Instance)
{
   // CallOriginal on any non-properties (this is a crude way to do this...)
   if(!method.Name.StartsWith("get_") && !method.Name.StartsWith("set_"))
   {
      Isolate.NonPublic.WhenCalled(fake, method.Name).CallOriginal();
   }
}
answered by (16.5k points)
...