I have the following interface :
public interface IOuputDestination
{
void Write(String s);
}
In my unit test, I mock it like so :
var outputDestination = A.Fake<IOutputDestination>();
What I want to do, is intercept the Write method so that it uses my custom implementation that I define in my test. Something like this :
String output = "";
A.CallTo(() => outputDestination.Write(A<String>.Ignored)).Action(s => output += s);
//Is something like this even possible ? ----^
Here the Action
method does not exist, but what I would like to happen is that any parameter passed into outputDestination.Write
be redirected to my custom action. Is this possible using FakeItEasy? If not, is there another mocking framework that allows this kind of behavior?
You can get that behavior with Invokes
:
String output = "";
A.CallTo(() => outputDestination.Write(A<String>.Ignored))
.Invokes((string s) => output += s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With