I am feeding a fake to an instance of class under test which sets properties on the fake and then makes an inner call, again setting properties. Only the properties in the outer call are persisted unless I explicitly set ReturnRecursiveFakes on the property.
Setting Members behavior in constructor has no effect so does this mean that I must explicitly set recursive fake on any property that I expect to be set more than one call deep?
In any case, I was unable to find any references to this kind of behavior in the documentation and the behavior illustrated by the code below is unintuitive.
Am I missing something?
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
namespace Test
{
public interface IFakeObject
{
string Property { get; set; }
}
public class ClassUnderTest
{
public void Outer(IFakeObject fakeObject)
{
fakeObject.Property = "Outer";
Inner(fakeObject);
}
private void Inner(IFakeObject fakeObject)
{
fakeObject.Property = "Inner";
}
}
[TestFixture]
public class TypeMockTest
{
[Test, Isolated]
public void TestPropSetterVsCallDepth()
{
ClassUnderTest cut = new ClassUnderTest();
IFakeObject fakeObject1 = Isolate.Fake.Instance<IFakeObject>();
cut.Outer(fakeObject1);
// is 'Outer' but should be 'Inner'? Fake only accepts property sets one call deep
Assert.AreEqual("Outer", fakeObject1.Property);
// set Members.ReturnRecursiveFakes
IFakeObject fakeObject2 = Isolate.Fake.Instance<IFakeObject>(Members.ReturnRecursiveFakes);
cut.Outer(fakeObject2);
// is 'Outer' but should be 'Inner'? Fake only accepts property sets one call deep
// even with Members.ReturnRecursiveFakes
Assert.AreEqual("Outer", fakeObject2.Property);
IFakeObject fakeObject3 = Isolate.Fake.Instance<IFakeObject>();
// set a recursive fake on the property itself
Isolate.WhenCalled(() => fakeObject3.Property).ReturnRecursiveFake();
cut.Outer(fakeObject3);
//Finally, is Inner
Assert.AreEqual("Inner", fakeObject3.Property);
}
}
}