tags:

views:

110

answers:

1

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

+1  A: 

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:

  • constraints on inputs
  • the value for / way in which the return value (if there is one) is to be derived

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

Ruben Bartelink
forgot to mention.Of course I have seen their example,but for some reason it's still not clear to me.embarrased to say but true.
Maybe give a code example where you think you need it and someone can connect the dots?
Ruben Bartelink
Hi RubenI am learning Moq and if you like I am bulding lots of examples to understand how to do things using it.My problem is I dont understand when to use it .Once I understand that problem solved I will write my own code.If you were to explain it in your own word when would you use callback?thanks appreciate your time
Thanks a lot for your help!! Appreciated