I suggest you ...

Add reporting to to mocks, outputing as much information as possible for every method invoked

When your debugging or simply trying to understand what is happening it would be very useful if we could get a list of all the methods that were invoked on a particular mock (or all mocks from a factory)

This could either be in the form of an explicit call:

mock.Report();

or as part of the ToString():

Console.Writeline(mock.ToString());

6 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    azdlowryazdlowry shared this idea  ·   ·  Admin →
    under review  ·  kzuAdminkzu (Admin, moq) responded  · 

    we have significantly improved this reporting in case of verify errors. Would you want this to also be available when the verifications actually succeed too?

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • azdlowryazdlowry commented  · 

        I finally managed to take a look at version 4, and the reporting on verifications is awesome, great work.

        However this is not the case I am suggesting here. What I'm suggesting is another method which has nothing to do with Verifications which just dumps out all the invocations on the mock, so we can see what actually happened.

        This is useful when Mock is used at a higher level than simple unit tests such as integration tests, and dumping out all the interactions would be easier than attaching a debugger. I tried adding this feature myself and managed to get something to work but there was a few things I didn't understand about the internal workings of Moq which suggested my code wouldn't work in all cases. Even with this I was able to use it to track down a bug i wouldn't have easily found without it.

      Feedback and Knowledge Base