I have a situation where I need to mock a third-party interface and call a third-party extension method that interacts with my component-under-test. It’s hard to figure out what exactly I need to verify on the mocked interface, and I’m wondering if it’s possible to trace whatever interactions Moq recorded so I can see what actually went on. From that, I am hoping to be able to code a meaningful expectation. I don’t see any evidence that this can be done in the API docs, but it seems like the technology is there and maybe is exposed somewhere that I haven’t found.
Thanks!
I don’t believe that such “playback” type functionality is available in Moq.
However, a couple of techniques for determining the pattern of calls come to mind:
You could implement the interface with a very simple object, and then fire up your debugger and place breakpoints of all of the implemented methods and properties. That should enable you to map out what was called and with what values.
You could create a mock and set it use
MockBehavior.Strict. The result of doing that will be that the Mock will throw an exception whenever any of it’s properties or methods are called (as long as there are no expectations set). You can catch these exceptions one by one and define expectations as you go, and slowly build up a picture of what’s being called.Neither scenario ideal, I admit.
That being the case, have you considered whether this is the best place to mock the functionality? Could you instead introduce a layer of abstraction that hides all of the third party functionality, and mock that instead?