Hi,
I just wanted to clarify some unexpected behaviour I encountered when mocking a public property. Consider the following class;
public class SimpleClass
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
}
The following unit test passes yet checking the code coverage, neither the getter or setter of the property are covered;
[TestMethod]
public void TestNameProperty()
{
string mockName = "TESTNAME";
SimpleClass simple =
Isolate.Fake.Instance<SimpleClass>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => simple.Name).CallOriginal();
simple.Name = mockName;
Assert.AreEqual(mockName, simple.Name);
}
I discovered that this is down to omitting the following line of code that overrides the behaviour of the fake on the setter as well as the getter;
Isolate.WhenCalled(() => simple.Name = null).CallOriginal();
This led me to question why the original test passes at all as I have, in effect, mocked the getter and not the setter so the getter should return null and the setter would just be ignored.
By contrast, if I only mock the setter and not the getter, then the test fails as expected as the setter works by calling the original implementation and the getter returns a fake.
Is this expected behaviour?
Thanks
Steve.