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
Hello,

I'm trying to use:

Isolate.NonPublic.Property.WhenGetCalled(fakeObj, "Value").WillReturn(1);

fakeObj is an instance of B, which inherits from A, which A defines A.Value as an integer. Can I not do this?

Thanks.
asked by bmains (13.2k points)

6 Answers

0 votes
Hi,

Is A.Value a non-public field or a property? Isolator does not intercept calls to fields, so in that case the code below would not work.

Doron
Typemock Support
answered by doron (17.2k points)
0 votes
private object Value
{
get { return _value; }
}

This is what A.Value is. But I am getting an exception. Don't have the exception handy at the moment, but it seemed that TypeMock wasn't inheriting members...

Should that be true, and is there some way to handle/verify this?

Thanks.
answered by bmains (13.2k points)
0 votes
Hi,

You are trying to return an int, while the signature of the property is of type Object. We may have a bug here, trying to match the return types. The exception can help us here.

What I'd try is this:

object a = 1;
Isolate.NonPublic.Property.WhenGetCalled(fakeObj, "Value").WillReturn(a); 


Let me know if it worked for you.
answered by gilz (14.5k points)
0 votes
OK, I can't remember I test that I did get that error from; I think I may have changed the architecture before waiting for the result, sorry.

But I am getting this on a similar example, and I tried this to no avail:

[Test]
public void GettingAllPropertiesReturnsCorrectCollection()
{
object propertyCollectionFake = Isolate.Fake.Instance<PropertyCollection>();
var mFake = Isolate.Fake.Instance<ModTest>();
Isolate.SwapNextInstance<ModTest>();
Isolate.NonPublic.Property.WhenGetCalled(mFake, "Properties").WillReturn(propertyCollectionFake);

ModTest test = new ModTest();

Assert.AreEqual(propertyCollectionFake, test.GetProperties());
}

The error is:

Nucleo.Model.BaseModuleTest.GettingAllPropertiesReturnsCorrectCollection:
TypeMock.TypeMockException :
*** No get property with name Properties in type Nucleo.Model.BaseModuleTest exists.
at a9.a(Type A_0, String A_1, c3 A_2, Boolean A_3)
at dt.a(Object A_0, String A_1)
at Nucleo.Model.BaseModuleTest.GettingAllPropertiesReturnsCorrectCollection()
answered by bmains (13.2k points)
0 votes
Actually, that doesn't use object as the inherent type. I'll try to find that, and will get back to you. In the mean time, I am having a similar issue to this, and it's not because it's object (the underlying type is a collection, the same type as the original value). So replace object with var, and this is what I had before, which should work, but is not.

Thanks.
answered by bmains (13.2k points)
0 votes
Hi,

I would like to look at the entire code. Since you have multiple questions around the same code, let's take it offline. I'll write you a separate email.

Thanks,
answered by gilz (14.5k points)
...