Hi Using moq and looked at callback but I have not been able to find a simple example to understand how to use it.
Do you have a small working snippet which clearly explain how and when to use it?
Thanks a lot
Hi Using moq and looked at callback but I have not been able to find a simple example to understand how to use it.
Do you have a small working snippet which clearly explain how and when to use it?
Thanks a lot
Hard to beat http://code.google.com/p/moq/wiki/QuickStart
If that's not clear enough, I'd call that a doc bug...
EDIT: In response to your clarification...
For each mocked method Setup
you perform, you get to indicate things like:
The .Callback
mechanism says "I can't describe it right now, but when one happens, call me back and I'll do what needs to be done and I'll take care of it". In the QS examples, an example is that they make the value being returned increase each time.
In general, you won't need a mechanism like this very often (xUnit Test Patterns have terms for antipatterns of the ilk Conditional Logic In Tests), and if there's any simpler or built-in way to establish what you need, it should be used in preference.
Part 3 of 4 in Justin Etheredge's Moq series covers it, and there's another example of callbacks here