I'm trying to test with Delphi Mocks framework a class that creates simple value objects and passes them to a collaborator. How to check contents of these objects?
General idea of the code is like this:
TData = class
Code : string;
Field1 : string;
Field2 : string;
end;
IReceiver = interface
procedure Process(aData : TData);
end;
TSUTClass = class
public
procedure DoSomething(const aCode : string);
property Receiver : IReceiver;
end;
So when a call to DoSomething is made, TSUTClass should make several instances of TData and pass them one by one to Receiver.Process. I can verify that correct count of calls is made with this setup:
Mock := TMock<IReceiver>;
Mock.Setup.Expect.Exactly('Process', ExpectedCount);
But how to check if values of Field1 and Field2 are correct?
The mock has a
WillExecutemethod where you can pass an anonymous method that will execute when the mock is called. You can evaluate the passedTDataobjects. Unfortunately after a quick look it seems that you cannot combine theWillExecutewith an expected call count.With DSharp Mocks which is very similar to Delphi Mocks it would look like this: