Friday, December 08, 2017

Spring4D presentation slides and more

Slides and code for my Spring4D presentation are now online on the Presentations page.

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 (or call some other function of the TArg type, defined in Spring.Mocking.Matching).

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) + ')');

  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);


3 comments:

  1. Thanks for the shout out for my book!

    ReplyDelete
  2. Thank you for sharing this, as always.
    I'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!

    ReplyDelete