Nein, so sollst du das machen
Delphi-Quellcode:
unit Unit1;
interface
type
IFoo =
interface
['
{45486F85-F11C-47B8-A85A-328C8845CA41}']
procedure Foo( );
end;
implementation
end.
Delphi-Quellcode:
unit Unit2;
interface
type
{$M+}
IMirrorFoo =
interface
['
{B5628A7F-7ECF-4123-A079-0193C8894185}']
procedure Foo( );
end;
{$M-}
implementation
end.
Delphi-Quellcode:
program MockMock;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Rtti,
Delphi.Mocks,
Unit1
in '
Unit1.pas',
Unit2
in '
Unit2.pas';
procedure Test( );
var
mock: TMock<IMirrorFoo>;
mirror: IMirrorFoo;
org: IFoo;
begin
mock := TMock<IMirrorFoo>.Create( );
mock.Setup.WillExecute( '
Foo',
function(
const args: TArray<TValue>;
const ReturnType: TRttiType ): TValue
begin
WriteLn( '
Foo called' );
end );
mirror := mock;
org := IFoo( mirror );
org.Foo();
end;
begin
try
Test( );
except
on E:
Exception do
Writeln( E.ClassName, '
: ', E.
Message );
end;
ReadLn;
end.