And to the participants of the workshop, here's the answer I promised.
If you want to catch all calls to some function while mocking, you can pass in Arg.IsAny
I have added an example to the Mocking project.
mockCalc.Setup.Returns(4).When.AddTwo(2);
mockCalc.Setup.Executes(
function(const
callInfo:
TCallInfo):
TValue
begin
lbLog.Items.Add('Don''t
know how to handle '
+
callInfo.Method.Name
+
'(' + IntToStr(callInfo.Args[0].AsInteger) + ')');
'(' + IntToStr(callInfo.Args[0].AsInteger) + ')');
end).When.AddTwo(Arg.IsNotIn([ 2]));
Or you can pass Args.Any to the When function. In that case, the argument passed to AddTwo is ignored.
mockCalc.Setup.Returns(-1).When(Args.Any).AddTwo(0);
Thanks for the shout out for my book!
ReplyDeleteAny time! :)
DeleteThank you for sharing this, as always.
ReplyDeleteI'm using several Spring4D classes in production, but your samples seems to teach me lots of things I don't know and should know. I want to take time to read/execute your samples.
BTW, I translated your presentation in English with built-in translation function of PowerPoint.
https://www.dropbox.com/s/lf1wz0muc63bk5m/EA-Spring4D-English.pps?dl=0
It could be useful for non Slovenian like us :)
Thanks!