I have an interface function that has a constant array and an anonymous function as parameters:
TCodeword = array[0..7] of Char;
TIntFunc = reference to function: Integer;
IMyInterface = interface(IInvokable)
function DoSomething(const codeword: TCodeword; func: TIntFunc): Boolean;
end;
I want to mock that interface to test an object, that is using it:
function IntFunc: Integer;
begin
Result := 5;
end;
procedure Test;
var
MyInterfaceMock: Mock<IMyInterface>;
MyInterface: IMyInterface;
begin
MyInterfaceMock := Mock<IMyInterface>.Create(TMockbehavior.Strict);
MyInterfaceMock.Setup.Returns(true).When.DoSomething(arg.IsAny<TCodeword>, arg.IsAny<TIntFunc>());
MyInterface := MyInterfaceMock;
MyInterface.DoSomething('12345678', IntFunc);
end;
When running, an ENotSupportedException: ‚Type is not supported: TCodeword‘ is raised when Setup. Can somebody explain why this is a not supported type? How can I pass a not specified TCodeword to mock that function correctly?
Alternatively I tried to pass explicit arguments in Setup:
procedure Test;
var
MyInterfaceMock: Mock<IMyInterface>;
MyInterface: IMyInterface;
begin
MyInterfaceMock := Mock<IMyInterface>.Create(TMockbehavior.Strict);
MyInterfaceMock.Setup.Returns(true).When.DoSomething('12345678', IntFunc);
MyInterface := MyInterfaceMock;
MyInterface.DoSomething('12345678', IntFunc);
end;
That way it will work for the constant array but not for the anonymous function. I get an EMockException: 'unexpected call of function DoSomething(const codeword: TCodeword; func: TIntFunc): Boolean with arguments: nil, (array)';
How can I make this work? I am glad for any help!