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


2 comments: