-
Notifications
You must be signed in to change notification settings - Fork 275
Closed
Description
Suppose I have the following interface.
public interface IDoStuffs
{
int Calculate();
}
I love the current syntax for setting up a return value. So simple.
var stuffDoer = Substitute.For<IDoStuffs>();
stuffDoer.Calculate().Returns(42);
But if I need to also run a callback, my tight clean code gets a bit ugly. Not too ugly, but ugly. I can no longer use a simple lambda, I have to use a code block.
var manualResetEvent = new ManualResetEvent();
var stuffDoer = Substitute.For<IDoStuffs>();
stuffDoer.Calculate().Returns(x => {
manualResetEvent.Signal();
return 42;
});
What I'd love to do instead is chain a callback before the Returns
call.
var manualResetEvent = new ManualResetEvent();
var stuffDoer = Substitute.For<IDoStuffs>();
stuffDoer.Calculate().Do(() => manualResetEvent.Signal()).Returns(42);
If it feels more natural, you could chain it to the end instead. But the behavior would probably be the same.
var manualResetEvent = new ManualResetEvent();
var stuffDoer = Substitute.For<IDoStuffs>();
stuffDoer.Calculate().Returns(42).Do(() => manualResetEvent.Signal());
Bonus if the callback method has 2-overloads:
- One that accepts a parameterless
Action
. - One that accepts an
Action
with the same arguments as the method being substituted.
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels