The mock has a WillExecute
method where you can pass an anonymous method that will execute when the mock is called. You can evaluate the passed TData
objects. Unfortunately after a quick look it seems that you cannot combine the WillExecute
with an expected call count.
With DSharp Mocks which is very similar to Delphi Mocks it would look like this:
var
mock: Mock<IReceiver>;
sut: TSUTClass;
callCount: Integer;
begin
sut := TSUTClass.Create(mock);
callCount := 0;
mock.Setup.WillExecute(
function(const args: TArray<TValue>; const ReturnType: TRttiType): TValue
var
data: TData;
begin
Inc(callCount);
data := args[0].AsType<TData>;
case callCount of
1:
begin
CheckEquals('xyz', data.Field1);
CheckEquals('abc', data.Field2);
end;
2: ///...
end;
end).Exactly(2).WhenCallingWithAnyArguments.Process(nil);
sut.DoSomething('x');
end;