Permalink
Browse files

more fixes

  • Loading branch information...
vincentparrett committed Sep 9, 2011
1 parent 010512c commit 4d14f8d0745899de6afa5b89fc6db20e305b4c27
View
@@ -5,6 +5,7 @@ interface
uses
Rtti,
SysUtils,
Delphi.Mocks,
Delphi.Mocks.Interfaces;
type
@@ -130,16 +131,17 @@ function TBehavior.Match(const Args: TArray<TValue>): Boolean;
begin
result := False;
case FBehaviorType of
WillReturn: result := MatchArgs;
ReturnDefault: result := True;
WillRaise:
WillReturn : result := MatchArgs;
ReturnDefault : result := True;
WillRaise :
begin
result := MatchArgs;
if FExceptClass <> nil then
raise FExceptClass.Create('Raised by Mock');
end;
WillRaiseAlways : result := True;
WillExecute: result := MatchArgs;
WillExecuteWhen : result := MatchArgs;
WillExecute : result := True;
end;
end;
@@ -209,7 +209,7 @@ procedure TProxyBase<T>.DoInvoke(Method: TRttiMethod; const Args: TArray<TValue>
end;
TBehaviorType.WillRaise:
begin
methodData.WillRaiseWhen(FExceptClass,Args);
methodData.WillRaiseAlways(FExceptClass);
end;
TBehaviorType.WillExecuteWhen :
begin
@@ -3,28 +3,27 @@
interface
uses
Rtti,
SysUtils,
Generics.Collections;
Generics.Collections,
Delphi.Mocks,
//Delphi.Mocks.Types,
Rtti;
type
{$M+}
TBehaviorType = (WillReturn,ReturnDefault,WillRaise,WillRaiseAlways,WillExecute,WillExecuteWhen);
IBehavior = interface
['{9F6FE14D-4522-48EE-B564-20E2BECF7992}']
['{9F6FE14D-4522-48EE-B564-20E2BECF7992}']
function GetBehaviorType : TBehaviorType;
function Match(const Args: TArray<TValue>) : boolean;
function Execute(const Args: TArray<TValue>; const returnType : TRttiType) : TValue;
property BehaviorType : TBehaviorType read GetBehaviorType;
end;
IVerify = interface
['{58C05610-4BDA-451E-9D61-17C6376C3B3F}']
procedure Verify(const message : string = '');
end;
IExpectation = interface
['{960B95B2-581D-4C18-A320-7E19190F29EF}']
TExecuteFunc = reference to function (const args : TArray<TValue>; const ReturnType : TRttiType) : TValue;
end;
IMethodData = interface
@@ -48,16 +47,11 @@ interface
property DefaultReturnValue : TValue read GetDefaultReturnValue;
end;
IExpectation = interface
['{960B95B2-581D-4C18-A320-7E19190F29EF}']
IVerify = interface
['{58C05610-4BDA-451E-9D61-17C6376C3B3F}']
procedure Verify(const message : string = '');
end;
implementation
end.
@@ -6,6 +6,7 @@ interface
Rtti,
SysUtils,
Generics.Collections,
Delphi.Mocks,
Delphi.Mocks.Interfaces;
type
@@ -45,7 +46,6 @@ TMethodData = class(TInterfacedObject,IMethodData)
implementation
uses
Delphi.Mocks,
Delphi.Mocks.Behavior;
{ TMethodData }
View
@@ -29,8 +29,7 @@ interface
uses
Rtti,
sysutils,
Delphi.Mocks.Interfaces;
sysutils;
type
IWhen<T> = interface;
@@ -48,7 +47,7 @@ interface
end;
IWhen<T> = interface
['{A8C2E07B-A5C1-463D-ACC4-BA2881E8419F}']
// ['{A8C2E07B-A5C1-463D-ACC4-BA2881E8419F}']
function When : T;
end;
@@ -57,9 +56,8 @@ interface
/// called on the Mock. If the method returns a value then your anon func must
/// return that.. and the return type must match. The return type is passed in
/// so that you can ensure tha.
//TExecuteFunc = reference to function (const args : TArray<TValue>; const ReturnType : TRttiType) : TValue;
//Aliased to avoid circular reference problem.
TExecuteFunc = Delphi.Mocks.Interfaces.TExecuteFunc;
TExecuteFunc = reference to function (const args : TArray<TValue>; const ReturnType : TRttiType) : TValue;
//We use the Setup to configure our expected behaviour rules and to verify
@@ -104,7 +102,7 @@ interface
//used by the mock - need to find another place to put this.. circular references problem means we need it here
IProxy<T> = interface
['{1E3A98C5-78BA-4D65-A4BA-B6992B8B4783}']
// ['{1E3A98C5-78BA-4D65-A4BA-B6992B8B4783}']
function Setup : ISetup<T>;
function Proxy : T;
end;
@@ -116,14 +114,14 @@ interface
TInterfaceMock<T> = record
private
FProxy : IProxy<T>;
class operator Implicit(const Value: TInterfaceMock<T>): T;
public
class operator Implicit(const Value: TInterfaceMock<T>): T;
function Setup : ISetup<T>;
//Verify that our expectations were met.
procedure Verify(const message : string = '');
function Instance : T;
class function Create: TInterfaceMock<T>; static;
// explicit cleanup.
// explicit cleanup. Not sure if we really need this.
procedure Free;
end;
@@ -135,9 +133,6 @@ EMockNoRTTIException = class(EMockException);
EMockNoProxyException = class(EMockException);
procedure Test;
implementation
@@ -146,65 +141,9 @@ implementation
Classes,
Generics.Defaults,
Delphi.Mocks.Utils,
Delphi.Mocks.Interfaces,
Delphi.Mocks.InterfaceProxy;
type
{$M+}
IFoo = interface
// ['{69162E72-8C1E-421B-B970-15230BBB3B2B}']
function GetProp : string;
procedure SetProp(const value : string);
function GetIndexProp(index : integer) : string;
procedure SetIndexedProp(index : integer; const value : string);
function Bar(const param : integer) : string;overload;
function Bar(const param : integer; const param2 : string) : string;overload;
procedure TestMe;
property MyProp : string read GetProp write SetProp;
property IndexedProp[index : integer] : string read GetIndexProp write SetIndexedProp;
end;
procedure Test;
var
mock : TInterfaceMock<IFoo>;
procedure TestImplicit(value : IFoo);
begin
value.TestMe;
value.Bar(1234567);
end;
begin
mock := TInterfaceMock<IFoo>.Create;
// mock.Setup;
mock.Setup.WillReturn('blah blah').When.Bar(1);
mock.Setup.WillReturn('goodbye world').When.Bar(2,'sdfsd');
mock.Setup.WillRaise(Exception).When.TestMe;
mock.Setup.WillReturn('hello').When.MyProp;
mock.Setup.WillRaise(Exception).When.MyProp;
mock.Setup.WillReturnDefault('Bar','hello world');
//define that Bar must be called before TestMe and will return 'abc' when passed in 33
// mock.Setup.Before('TestMe').WillReturn('abc').When.Bar(33);
//mock.Setup.Expect.AtLeastOnce.&On('testMe');
//mock.Setup.Expect.Once.When.Bar(99);
// mock.Setup.Expect.Exactly(2).OnMethod('Bar');
// mock.Setup.WillReturn('hello').When.MyProp;
mock.Instance.MyProp := 'hello';
mock.Instance.IndexedProp[1] := 'hello';
WriteLn('Calling Bar(1) : ' + mock.Instance.Bar(1));
WriteLn('Calling Bar(2) : ' + mock.Instance.Bar(2));
WriteLn('Calling Bar(2,sdfsd) : ' + mock.Instance.Bar(2,'sdfsd'));
TestImplicit(mock);
try
mock.Instance.TestMe;
except
end;
mock.Verify('did it work???');
//mock.Free;
end;
class function TInterfaceMock<T>.Create: TInterfaceMock<T>;
var
View
@@ -27,10 +27,10 @@
<MSBuild Projects="Sample1.dproj" Targets="Make"/>
</Target>
<Target Name="Delphi_Mocks_Tests">
<MSBuild Projects="Test\Delphi.Mocks.Tests.dproj"/>
<MSBuild Projects="Tests\Delphi.Mocks.Tests.dproj"/>
</Target>
<Target Name="Delphi_Mocks_Tests:Clean">
<MSBuild Projects="Test\Delphi.Mocks.Tests.dproj" Targets="Clean"/>
<MSBuild Projects="Tests\Delphi.Mocks.Tests.dproj" Targets="Clean"/>
</Target>
<Target Name="Delphi_Mocks_Tests:Make">
<MSBuild Projects="Tests\Delphi.Mocks.Tests.dproj" Targets="Make"/>
View
Binary file not shown.
View
@@ -7,14 +7,15 @@ program Sample1;
uses
SysUtils,
Delphi.Mocks in 'Delphi.Mocks.pas',
Delphi.Mocks.InterfaceProxy in 'Delphi.Mocks.InterfaceProxy.pas',
Delphi.Mocks.Utils in 'Delphi.Mocks.Utils.pas',
Delphi.Mocks.VirtualInterface in 'Delphi.Mocks.VirtualInterface.pas',
Sample1Main in 'Sample1Main.pas',
Delphi.Mocks.Behavior in 'Delphi.Mocks.Behavior.pas',
Delphi.Mocks.Helpers in 'Delphi.Mocks.Helpers.pas',
Delphi.Mocks.When in 'Delphi.Mocks.When.pas',
Delphi.Mocks.InterfaceProxy in 'Delphi.Mocks.InterfaceProxy.pas',
Delphi.Mocks.Interfaces in 'Delphi.Mocks.Interfaces.pas',
Delphi.Mocks.MethodData in 'Delphi.Mocks.MethodData.pas',
Delphi.Mocks.Interfaces in 'Delphi.Mocks.Interfaces.pas';
Delphi.Mocks.Utils in 'Delphi.Mocks.Utils.pas',
Delphi.Mocks.VirtualInterface in 'Delphi.Mocks.VirtualInterface.pas',
Delphi.Mocks.When in 'Delphi.Mocks.When.pas';
begin
try
View
@@ -6,7 +6,7 @@
<MainSource>Sample1.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>3</TargetedPlatforms>
<AppType>Console</AppType>
<DCC_DCCCompiler>DCC32</DCC_DCCCompiler>
@@ -89,14 +89,15 @@
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="Delphi.Mocks.pas"/>
<DCCReference Include="Sample1Main.pas"/>
<DCCReference Include="Delphi.Mocks.Behavior.pas"/>
<DCCReference Include="Delphi.Mocks.Helpers.pas"/>
<DCCReference Include="Delphi.Mocks.InterfaceProxy.pas"/>
<DCCReference Include="Delphi.Mocks.Interfaces.pas"/>
<DCCReference Include="Delphi.Mocks.MethodData.pas"/>
<DCCReference Include="Delphi.Mocks.Utils.pas"/>
<DCCReference Include="Delphi.Mocks.VirtualInterface.pas"/>
<DCCReference Include="Delphi.Mocks.Behavior.pas"/>
<DCCReference Include="Delphi.Mocks.Helpers.pas"/>
<DCCReference Include="Delphi.Mocks.When.pas"/>
<DCCReference Include="Delphi.Mocks.MethodData.pas"/>
<DCCReference Include="Delphi.Mocks.Interfaces.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Oops, something went wrong.

0 comments on commit 4d14f8d

Please sign in to comment.