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
Please see: https://www.typemock.com/community/viewtopic.php?t=1299 (read Inc as int).

I have used the EventTunnel.DuringMethodCall hooks in typemock and they are very powerful! I would like to know if there is a hook or event for private field gets / sets since they can be mocked.

Thanks,
Tom

The Example below could display hello world;

public class TestClass {
public static void TestMethod(){ EventTunnel.ShouldInterceptDecision += ShouldIntercept; EventTunnel.DuringMethodCall += FieldChanged; MockMe.SetMe = 0; }

private void FieldChanged(InterceptedCallEventArgs args)
{
Console.Writeline( "HelloWorld!" );
}

private void ShouldIntercept( TMShouldInterceptEventArgs args )
{
args.Returns( InterceptBehavior.Intercept );
}
}

public class MockMe {
public static int SetMe;
}
asked by trp (4.1k points)

8 Answers

0 votes
Hi Tom,

This is a nice work around idea for the field mocking problem. Unfortunately, implementing this on top of Isolator would have the same problem - field access is not intercepted in Isolator, so hooking into it is currently not possible.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
is there another way I can accomplish "watching" for any field change?
answered by trp (4.1k points)
0 votes
Hi Tom,

As Doron said the real problem is that field accesses are not intercepted by the isolator framework.

There was however a partial solution for handling fields (as long as they were classes and not struct/primitive types) that you might find useful.

try looking here:
https://www.typemock.com/Docs/UserGuide/ ... Field.html
answered by error (6.6k points)
0 votes
OK. Thanks. It would be a nice feature to see in the future but for now I will use MockField. Can MockManager be used in the same test as Isolator? Will I need to clear Isolator and MockManager?

Thanks,
Tom
answered by trp (4.1k points)
0 votes
Hi,

Basically you can however its quite tricky to make them work together.
I would suggest, for simplicity, picking a single API version per test.

The "reflective" API should be able to do anything the AAA API can.
answered by error (6.6k points)
0 votes
10x
answered by trp (4.1k points)
0 votes
Please see: https://www.typemock.com/community/viewtopic.php?t=1299 (read Inc as int).

I have used the EventTunnel.DuringMethodCall hooks in typemock and they are very powerful! I would like to know if there is a hook or event for private field gets / sets since they can be mocked.

Thanks,
Tom

The Example below could display hello world;

public class TestClass {
public static void TestMethod(){ EventTunnel.ShouldInterceptDecision += ShouldIntercept; EventTunnel.DuringMethodCall += FieldChanged; MockMe.SetMe = 0; }

private void FieldChanged(InterceptedCallEventArgs args)
{
Console.Writeline( "HelloWorld!" );
}

private void ShouldIntercept( TMShouldInterceptEventArgs args )
{
args.Returns( InterceptBehavior.Intercept );
}
}

public class MockMe {
public static int SetMe;
}


Good question. At me a similar problem. I too am for the first time at this forum.
answered by terry3111 (140 points)
0 votes
Hi,

What is the exact issue you encountered? Can you post sample of the code you're trying to test?

Regards,
Elisha
Typemock Support
answered by Elisha (12k points)
...