I'm using DSharp mocks in Delphi XE5 (thanks Stefan!!) but have a problem with some enumerators. If I try to define an enumerator with specific values, the {$M+} directive causes the following error:
E2134 Type 'TMyEnum' has no type info
Here is a sample console app which sums it all up:
program DSharpMockEnum;
program DSharpMockEnum;
{$APPTYPE CONSOLE}
{$R *.res}
uses
DSharp.Testing.Mock,
System.SysUtils;
type
TBadEnum = (badEnum1 = 1, badEnum2); // <---- WONT COMPILE
TGoodEnum = (goodEnum1, goodEnum2); // This compiles OK
{$M+}
IBadMock = interface
['{34B3904E-3EBA-4C6E-BBA8-A40A67A32E7F}']
function GetEnum: TBadEnum;
procedure SetEnum(Value: TBadEnum);
property MyEnum: TBadEnum read GetEnum write SetEnum;
end;
{$M+}
IGoodMock = interface
['{34B3904E-3EBA-4C6E-BBA8-A40A67A32E7F}']
function GetEnum: TGoodEnum;
procedure SetEnum(Value: TGoodEnum);
property MyEnum: TGoodEnum read GetEnum write SetEnum;
end;
var
LGoodMock: Mock<IGoodMock>;
LBadMock: Mock<IBadMock>;
begin
try
Writeln('Good Mock');
LGoodMock.Setup.WillReturn(goodEnum1).Any.WhenCalling.MyEnum;
Writeln('Bad Mock');
LBadMock.Setup.WillReturn(badEnum1).Any.WhenCalling.MyEnum;
Writeln('Stop');
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Any ideas or suggestions? I prefer to avoid resetting all my enums since some are stored in the database and need specific values. Delphi XE5. Thanks. Rick.