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,

I've encountered odd difficulties getting properties to work.

When I execute the following code in my unit test it always throws the exception.

I'm also getting sporadic problems with other properties setup the same way. My debug.writeline output inidicate sometimes the property is set up sometimes it ain't.

                MockManager.Init();

                MockObject tvMock = MockManager.MockObject(typeof(TV));
                tvMock.ExpectGetAlways("TVGuid", Guid.NewGuid());
                TV tvObj = (TV)tvMock.Object;

                if (tvObj.TVGuid == Guid.Empty)
                    throw new OperationCanceledException("Aaaargh");


I'm running VS2005 and TypeMock 3.0.1.1.

Kerry
asked by kerryr (1.8k points)

2 Answers

0 votes
Never mind, I've worked it out.

I use NHibernate to persist my objects and TypeMock doesn't like it.

If I configure NHibernate first it sticks it's own proxy objects in place of the real ones. When TypeMock comes along after and inserts it's own proxy it doesn't get through to the real object but gets the NHibernate proxy instead (I think).

The workaround for this is to do a MockManager.Init() before configuring NHibernate. That way NHibernate works with the TypeMock proxy rather than the other way around.

This seems to work ok.

Cheers
Kerry
answered by kerryr (1.8k points)
0 votes
Hi,
Thanks for sharing this with us.
The actual problem is that TypeMock cannot mock types that have already been JITTED (i.e. called) before the Init() statement.

NHibernate creates the objects when being configured, and thus they have been JITTED and cannot be mocked.

The solution is as you say:
call Init() as soon as possible in your tests.

For more details see InitFastMode()
answered by scott (32k points)
...