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

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 tolisss (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 error (6.6k points)
0 votes
No

what i need is to fake all properties at any level but fake no method
answered by tolisss (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 doron (16.5k points)
...