Mocking a chain object of the struct type will throw cannot use mockall exception.
Here's the production code
public struct SpecialValue
{
public double X
{ get; set; }
public double Y
{ get; set; }
}
public class Typemockclass
{
public SpecialValue pt1
{ get; private set; }
public SpecialValue pt2
{ get; private set; }
}
Here's the test code
[Test, Isolated]
public void testSpecialValue()
{
Typemockclass mock = Isolate.Fake.Instance<Typemockclass>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => mock.pt1.X).WillReturn(30);
Isolate.WhenCalled(() => mock.pt2.X).WillReturn(60);
}
Here's the exception:
TestCase 'TypeMockTest.testSpecialValue'
failed: TypeMock.TypeMockException :
*** Cannot use MockAll twice for type SpecialValue
at ds.a(Constructor A_0, Boolean A_1)
at TypeMock.MockManager.MockAll(Type type, Constructor mockConstructors)
at TypeMock.MockManager.Mock(Type type, Constructor mockConstructors)
at TypeMock.MockManager.b(Object A_0, String A_1)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at SpecialValue.get_X()
But let's say if the test is
[Test, Isolated]
public void testSpecialValue()
{
Typemockclass mock = Isolate.Fake.Instance<Typemockclass>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => mock.pt1.X).WillReturn(30);
}
Then there is no error at all.
________
Weed vaporizers