[Mocks] Not mocking every single object from call-hierarchy results in an AV

Issue #22 invalid
Former user created an issue

Hi,

I just stumbled over an Exception while setting up my Mock, that confused me because it was an AccessViolation.

If you setup a mock like this:

....
LTestAV.Setup.WillReturn(true).Any.WhenCalling.ReturnITest.ReturnBoolean;
....

without mocking the call of "ReturnITest", it results in an AV. It would be nice to get something more meaningful than an AV (in case you agree ;-)).

Kind Regards, Aleks

Comments (4)

  1. Stefan Glienke repo owner

    The mock is in setup mode so it does return TValue.Empty internally which is nil.

    The general rule is: never call anything on a result of method called on the mock during setup. While it might be possible to return a mock for methods with interface that would not do anything since the expected return value is taken for the ReturnITest method and not for the method called on the result of ReturnITest.

    In your case setting up the mock is a two step process that requires 2 mocks.

    LTestAV.Setup.WillReturn<ITest>(LOther).Any.WhenCalling.ReturnITest;
    LOther.Setup.WillReturn(True).Any.WhenCalling.ReturnBoolean;
    
  2. Former user Account Deleted

    Yeah I know that I set it up the wrong way. I just thought it might be possible to check whether something is already mocked or not in setup mode and if not, to raise something like "Dude, you did not Mock XY but tried to access it".

  3. Stefan Glienke repo owner

    It might work for a result of an interceptable interface but not for say objects. So that solution would only solve half of the problem - for the other half there is no solution.

  4. Former user Account Deleted

    Oh, yes, i focused completely on the use of Interfaces. Forget about that and have a nice weekend, sorry for wasting your time :P

  5. Log in to comment