File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -880,6 +880,10 @@ function TProxy<T>._AddRef: Integer;
880880
881881function TProxy <T>._Release: Integer;
882882begin
883+ if FSetupMode <> TSetupMode.None then begin
884+ ClearSetupState;
885+ raise EMockSetupException.Create(' Setup called on non-virtual method' );
886+ end ;
883887 result := inherited ;
884888end ;
885889
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ TCommand = class
3333 procedure TestVarParam (var msg : string);virtual ;abstract ;
3434 procedure TestOutParam (out msg : string);virtual ;abstract ;
3535 function VirtualMethod : Integer; virtual ;
36+ function NonVirtualMethod : Integer;
3637 end ;
3738
3839 { $M+}
@@ -65,6 +66,8 @@ TTestObjectProxy = class
6566 procedure TestVarParam ;
6667 [Test]
6768 procedure MockNoBehaviorDefined ;
69+ [Test]
70+ procedure WillRaiseMockNonVirtualMethod ;
6871 end ;
6972 { $M-}
7073
@@ -249,6 +252,15 @@ procedure TTestObjectProxy.MockNoBehaviorDefined;
249252 mock.Verify;
250253end ;
251254
255+ procedure TTestObjectProxy.WillRaiseMockNonVirtualMethod ;
256+ var
257+ mock : TMock<TCommand>;
258+ begin
259+ mock := TMock<TCommand>.Create;
260+ Assert.WillRaise(procedure begin mock.Setup.Expect.Once.When.NonVirtualMethod; end );
261+ Assert.WillRaise(procedure begin mock.Setup.WillReturn(2 ).When.NonVirtualMethod; end );
262+ end ;
263+
252264procedure TTestObjectProxy.MockWithArgProcedureUsingOnce ;
253265var
254266 mock : TMock<TCommand>;
@@ -282,6 +294,11 @@ constructor TMultipleConstructor.Create;
282294
283295{ TCommand }
284296
297+ function TCommand.NonVirtualMethod : Integer;
298+ begin
299+ Result := 1 ;
300+ end ;
301+
285302function TCommand.VirtualMethod : Integer;
286303begin
287304 Result := 1 ;
You can’t perform that action at this time.
0 commit comments