Hi,
There are few issues here:
1. What you want to do is swap the next instance of B (next call to - New B)
To do that you need to use the Isolator API SwapNextInstance(Of T)
2. From the code you posted it seems like you are using private accessors "A_Accessor" in your code. In that case you should not fake the accessor but the class that it is wrapping.
3. The Isolator can not fake fields so you can not change the value of B.x
In order to to work around that you should wrap the field with property or a method.
Combining the points above try the following code:
' I added a property to B class as a wrapper around the x field.
Public Class B
Public x As Int32
Public Property Prop() As Int32
Get
Return x
End Get
Set(ByVal value As Int32)
x = value
End Set
End Property
End Class
<TestMethod>
Public Sub TestMethod2()
Dim fake As A = FakeInstance(Of A)()
Dim fakeB As B = FakeInstance(Of B)()
Using TheseCalls.WillReturn(5)
Dim dummy As Int32 = fakeB.Prop
End Using
SwapAllInstances(Of B)(fakeB)
Dim accessor As A_Accessor = New A_Accessor()
Dim actualResult = accessor.MyTest()
Assert.AreEqual(5, actualResult.Prop)
End Sub
Things to note:
:arrow: I used the SwapAllInstances since the code creates few instances of B. if the code was creating only one instance I would use SwapNextInstance(Of B)(fakeB)
:arrow: the A_Accessor is not faked since I assume it only wraps A class.