#1 2015-04-10 18:58:30

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Problem with TInterfaceMock

Hello,

I'm trying to use TInterfaceMock to create unit tests. I'm trying to create mock for interface:

  IExceptionHandler = interface(IInvokable)
    ['{E869A018-624E-429D-8245-428FE9620FCE}']
    function Handle(const AException: Exception): Boolean;
  end;

But if I'm trying to create mock with code:

  localExc := Exception.Create('');
  TInterfaceMock.Create(TypeInfo(IGxExceptionHandler), mckHandler).
      ExpectsCount('Handle', [localExc], qoEqualTo, 1);

it raises exception with message: TInterfaceFactoryRTTI.Create: IGxExceptionHandler.Handle "AException" parameter has unexpected type Exception - use TJSONSerializer.RegisterCustomSerializer() It is raised even if reader for Exception class is registered. Is it possible to use mORMot mocks to create mocks for interfaces like my?


best regards
Adam Siwon

Offline

#2 2015-04-10 19:50:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Problem with TInterfaceMock

It is not handled.

For two reasons.

In fact, parameters are passed and stored by representation, so only TPersistent / TSQLRecord kind of classes are supported.

And you need to pass the same exception instance class as defined.

Offline

#3 2015-04-10 20:47:33

ASiwon
Member
From: Poland
Registered: 2015-01-30
Posts: 82

Re: Problem with TInterfaceMock

And you need to pass the same exception instance class as defined.

I had problem with registering custom serializer. Only read method was defined. Thats why it doesn't worked correctly while creating mock.

In my case only for testing purposes it would be enough to use simple pointer values for such parameters - without defining custom serializer. I know that for service using pointers have no sense but for testing it really would be enough. Is it possible to add this behaviour?


best regards
Adam Siwon

Offline

Board footer

Powered by FluxBB