0

I have a function that accept a TWebRequest by argument, eg.:

function foo(const request: TWebRequest ): boolean;

how can i create a TWebRequest and set some property like:

  • Host
  • ServerPort
  • QueryFields
  • ContentFields

I have tried:

var
  aWebRequest: TWebRequest;
begin
  aWebRequest := TWebRequest.Create;

but on creation Delphi raise an exception:

First chance exception at $XXXXXXXX. Exception class EAbstractError with message 'Abstract Error'.

the descendant is TIdHTTPAppRequest, but it require:

constructor TIdHTTPAppRequest.Create(
  AThread: TIdContext; 
  ARequestInfo: TIdHTTPRequestInfo; 
  AResponseInfo: TIdHTTPResponseInfo
);

each argument require other object etc etc.

there is a simple way (eg. third party unit, unknown snippet or trick) for mockup a request for unit test purpose?

ar099968
  • 6,963
  • 12
  • 64
  • 127

1 Answers1

2

EAbstractError usually means that you are trying to instantiate generic abstract class (e.g. TStrings) instead of it's descendant that contains required implementations (e.g. TStringList). So you need to find the TWebRequest descendant and use it instead.

For mocking purposes you could try to write your own "empty" descendant, but I doubt that will work as expected.

Kromster
  • 7,181
  • 7
  • 63
  • 111