chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Struct is not supported in AAA syntax-- I wonder why? Here's a simple test code to reproduce the issue:
    public struct MyStruct
    {
        public double FirstNumber
        { get; set; }
    }
        [Test, Isolated]
        public void SupportStruct()
        {
            MyStruct strtw = Isolate.Fake.Instance<MyStruct>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(()=>strtw.FirstNumber).WillReturn(10);
        }


And here's the exception
failed: TypeMock.TypeMockException : 
*** Can not create MockObject of struct, try using MockAll
   at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
   at TypeMock.MockManager.a(Type A_0, BindingFlags A_1)
   at TypeMock.MockManager.CreateRecursiveFake[T](BindingFlags flags)
   at cc.Instance[T](Members behavior)

________
Laser
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon

Currently struct is not supported by AAA API
We will add the support in future versions.

The reason is that there is no instance for a struct (its created on the stack not on the heap) so you can only fake behavior for all the value of the same struct.
answered by ohad (35.5k points)
...