When to Use
When your test requires a fake property to behave as an auto-property, and you have public set and get.
Syntax
C# var fakeDependency = Isolate.Fake.Instance<Dependency>(); fakeDependency.Number = <value> // sets the property to return the value
VB
Dim fakeDependency = FakeInstance(Of <Dependency>)()
fakeDependency.Number = <value> ' sets the property to return the value
Samples
Sample 1: Using True Properties
C# [TestMethod, Isolated] public void FakeAutoProperty() { var fakeDependency = Isolate.Fake.Instance<Dependency>(); fakeDependency.Number = 5; // sets the property to return 5 Assert.AreEqual(5, fakeDependency.Number); }
VB
<TestMethod(), Isolated()>
Public Sub FakeAutoProperty()
Dim fakeDependency = FakeInstance(Of <Dependency>)()
fakeDependency.Number = 5 ' sets the property to return 5
Assert.AreEqual(5, fakeDependency.Number)
End Sub
Sample 2: Using True Properties for Members.CallOriginal() Fakes
An ability to use true properties is not applied when Members.CallOriginal() is used because the original implementation will be executed. In this case, if you want to use true properties, use Isolate.WhenCalled().ReturnRecursiveFake() on that property as follows:
C# var dependency = new Dependency(); // not fake Isolate.WhenCalled(() => dependency.Number).ReturnRecursiveFake(); // Number will act like an auto property dependency.Number = 5;
VB
Dim dependency = New Dependency() ' not fake
Using TheseCalls.WillReturnRecursiveFake ' Number will act like an auto property
Dim dummy = dependency.Number
End Using