moq icon indicating copy to clipboard operation
moq copied to clipboard

Possibility of adding Callback to ISetupSequentialAction

Open jflevesque-genetec opened this issue 9 months ago • 1 comments

Hi,

I've had a situation where I need to raise a signal once a certain number of calls are made on a mock that has void return value.

My setup is as such:

        mock.SetupSequence(x => x.SendMessage(It.IsAny<Message>()))
            .Throws(new SomeException())
            .Throws(new SomeException())
            .Throws(new SomeException())
            .Pass(() => _tcs.SetResult()); // this does not compile

As it stands, the Pass operation does not take any argument, so we can't inject a callback to occur when that step happens.

Is this something that can be added to the Pass operation? Or would it be a new operation called Callback?

If it is not worth it, is there another approach that can be taken that would be cleaner than using a counter + switch in a standard Setup + Callback ?

Back this issue Back this issue

jflevesque-genetec avatar May 09 '25 20:05 jflevesque-genetec

Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.

github-actions[bot] avatar Nov 06 '25 01:11 github-actions[bot]

This issue will now be closed since it has been labeled 'stale' without activity for 30 days.

github-actions[bot] avatar Dec 07 '25 01:12 github-actions[bot]