Doesn't detect method call, when callback is added.
When added callback in Mock.Setup verifying of sequence is fail. I looked to source code and noticed that AddStep adds Callback and when we pass Action to ISetup.Callback it overrides old one so after calling mock method Serquence.Record() doesn't call and EnsureComplete is fail.
Hi @minhay, I'll look into it, however my initial feeling is that this will be difficult to fix in a clean manner. I can see two possible solutions:
- Change Moq so it allows more than one callback per setup; or
- Introducing another extension method such as
.InSequenceWithCallback(action)that essentially combines.InSequence()with.Callback(action).
There is no guarantee that change (1) would be accepted into the main Moq library. (2) appears to be feasible, but results in a somewhat clunky API design. It would obviously be nicer if the separate methods combined as expected without having to fuse them into a single method.
I ran into the same issue, and solved it by adding extension methods like @stakx suggested. It would be nice perhaps to have this included somewhere even if it's optional
@AlexDocking: The upcoming new major version 5 of Moq has a much better extensibility model than Moq 4 which Moq.Sequences currently targets, it'll be interesting to see whether we can resolve this issue properly when upgrading to Moq 5.