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
Here's the pseudo test code:

SupportingClass source = GenerateSourceWithValues("TEST");
Isolate.Fake.StaticMethods(typeof(Foo), Members.CallOriginal);

AnotherClass target = AnotherClass.FactoryMethod(source);

Assert.IsNotNull(target);
Isolate.Verify.WasCalledWithExactArguments(() => Foo.FactoryMethod(source.SomeProperty));


When executing (I'm still on 5.2.2 - can't go to 5.2.3 until later this week) I get the following exception from Isolator (not very clear by the way):

***Isolate.Verify does not support objects that were not fake using Isolate.Fake.Instance(), or passed through WhenCalled().

I tried several combinations, all of which resulted in the same error message:

SupportingClass source = GenerateSourceWithValues("TEST");
Isolate.WhenCalled(() => Foo.FactoryMethod(null)).CallOriginal();

AnotherClass target = AnotherClass.FactoryMethod(source);

Assert.IsNotNull(target);
Isolate.Verify.WasCalledWithExactArguments(() => Foo.FactoryMethod(source.SomeProperty));


and

SupportingClass source = GenerateSourceWithValues("TEST");
Isolate.Fake.StaticMethods(typeof(Foo));
Isolate.WhenCalled(() => Foo.FactoryMethod(null)).CallOriginal();

AnotherClass target = AnotherClass.FactoryMethod(source);

Assert.IsNotNull(target);
Isolate.Verify.WasCalledWithExactArguments(() => Foo.FactoryMethod(source.SomeProperty));


***Using 'WithAnyArguments' method results in the same problem.

More Info:::

So because I needed this test to run I switched syntax to following and it passes - now maybe this is all because Foo.FactoryMethod is internal and I'm using InternalsVisibleTo???? But it seems like my original test (at least one of them should work)

Tests that passes:
SupportingClass source = GenerateSourceWithValues("TEST");
Isolate.NonPulbic.WhenCalled(typeof(Foo), "FactoryMethod").CallOriginal();

AnotherClass target = AnotherClass.FactoryMethod(source);

Assert.IsNotNull(target);
Isolate.Verify.NonPublic.WasCalled(typeof(Foo), "FactoryMethod");
asked by boo (21.8k points)

4 Answers

0 votes
Hi boo,

In your failing tests you are using a nested chain when trying to verify; source.SomeProperty is called inside the call to Foo.FactoryMethod. This is throwing Isolator off, and should be circumvented by breaking down the nesting like this:
var argValue = source.SomeProperty;
Isolate.Verify.WasCalledWithExactArguments(() => Foo.FactoryMethod(argValue ));


The real problem is with the exception message throwing you off - I will work to improve that for an upcoming release.

Please let me know if the workaround works for you.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Yes this change worked, but I have to admit its non-intuitive (btw: passing null for the property also worked for the 'WithAny' check). Will Isolator be fixed to handle the nesting in the future?

I can see already somebody coming through the code and saying:

Foo propertyToCheck = bar.FooValue;
Isolate.Verify.WasCalledWithExactArguments(() => Test.Method(propertyToCheck));


Well let me optimize to:

Isolate.Verify.WasCalledWithExactArguments() => Test.Method(bar.FooValue);


And get us right back where we started - I'll comment of course - but nobody ever reads those!

Also: Is the the check I'm making just doing a reference check on propertyToCheck I imagine?
answered by boo (21.8k points)
0 votes
This one got me again on something else.... :x

Is this something that will be fixed in an upcoming version?
answered by boo (21.8k points)
0 votes
Hi Brian,

Not in the really next one. For the time being, we'll improve the error. But it is on our list.
answered by gilz (14.5k points)
...