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
[Test]
public void LoadingPropertiesUsingAttributesLoadsCorrectValues()
{
var collectionFake = Isolate.Fake.Instance<PropertyCollection>();
Isolate.SwapNextInstance<PropertyCollection>();
Isolate.WhenCalled(() => collectionFake.Add(new Property("", null))).IgnoreCall(); //note, have to use bogus params for prop object ctor or it throws exception

var mFake = Isolate.Fake.Instance<Mod>();
Isolate.SwapNextInstance<Mod>();
Isolate.WhenCalled(() => mFake.LoadPropertiesUsingAttributes()).CallOriginal();
Isolate.WhenCalled(() => mFake.AddProperty(new Property("", null))).CallOriginal();

var m = new ModTest();
m.LoadPropertiesUsingAttributes();

//Erroring line below
Isolate.Verify.WasCalledWithAnyArguments(() => m.AddProperty(new Property("AppName", this)));
Isolate.Verify.WasCalledWithAnyArguments(() => m.AddProperty(new Property("ShouldShowDetails", this)));
Isolate.Verify.WasNotCalled(() => m.AddProperty(new Property("ShouldNotFind", this)));
}

Results in an error:

ModTest.LoadingPropertiesUsingAttributesLoadsCorrectValues:
TypeMock.TypeMockException :
*** Isolate.Verify does not support objects that were not faked using Isolate.Fake.Instance(), or passed through WhenCalled()

at dp.a()
at cm.a(Delegate A_0)
at cm.d(Delegate A_0)
at cm.b(Action A_0)
at Nucleo.Model.BaseModuleTest.LoadingPropertiesUsingAttributesLoadsCorrectValues()

What object didn't I fake or call WhenCalled for? Is it the Property objects I have to do that for too? Any insight would be helpful.

Thanks.
asked by bmains (13.2k points)

1 Answer

0 votes
Hi,

There's actually one and a half things here.
First, you verify on m. m is a real object and you haven't set any behavior on it. It is a current limitation we have that you still need to go through one of the mentioned API to verify on it.

There's another thing. The last Verify has a New inside it. you should not use a constructor inside a function (or in any of the other of the API). it's actually a function call inside a function, and Isolator doesn't like it:). You can just pass null instead for it to work.

Gil
answered by gilz (14.5k points)
...