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
0 votes
I have the following production code:
    public class Attach
    {
        public Attach()
        {
            throw new NotImplementedException();
        }
    }
    public class WrapList
    {
        public List<string> myStrings
        { get; private set;}

        public void Add(Attach attach)
        {
        
        }

    }


and this test code will fail:
        [Test, Isolated]
        public void WrapListMore()
        {
            WrapList wrapList = Isolate.Fake.Instance<WrapList>(Members.ReturnRecursiveFakes);
            wrapList.Add(new Attach());
        }


because the new Attach() statement is not mocked. But I think since the new Attach() is inside the wrapList.Add, which is a fake object, the new Attach() should be mocked as well so that no exception is thrown.
________
HALF-BAKED
asked by nsoonhui (59.1k points)

3 Answers

0 votes
Hi,

Technically speaking the new Attach() statement is executed before the call to WrapList.Add() so theres a real problem of order. the Isolator has no way of predicting the future so to speak.

Also, in my opinion there is no justification for stubbing calls on attach in this case.
Recursive mock semantics means: all calls on the fake object will be stubbed and object/values returned from these calls will be mocks as well.


:idea: Since WrapList is stubbed out, you can just as well pass in a null into the add call.
answered by error (6.6k points)
0 votes
Creating a fake object with recursive mocks only applies to objects returned from function/property calls on the faked object.
Attach used as a parameter is not exactly part of the faked object and as such is not faked automatically.
answered by dhelper (11.9k points)
0 votes
I see, OK, thanks :lol:
________
FREE KMART GIFT CARDS
answered by nsoonhui (59.1k points)
...