HashLoad / horse

Fast, opinionated, minimalist web framework for Delphi
MIT License
1.15k stars 217 forks source link

THorse unity tests - Mocks #362

Closed arthurmluz closed 10 months ago

arthurmluz commented 12 months ago

Hey, how can I make unity tests to validate my middlewares/controller/service?

I'm trying to create a THorseRequestMock and THorseResponseMock that inherit from their respective classes, but as my middlewares expects THorseRequest, it keeps calling the ancestor method when trying to do a Requests.Query, so I get an Access Violation;

How can I do this in a better way?

type
  THorseRequestMock = class(THorseRequest)
  private
    FHeaders  : THorseCoreParam;
    FQuery    : THorseCoreParam;
    FParams   : THorseCoreParam;

    procedure InitializeRequest;
  public
    constructor Create;

    function Headers : THorseCoreParam; 
    function Query   : THorseCoreParam; 
    function Params  : THorseCoreParam;

I can't call override because those functions arent virtual;

dps de escrever em ingles eu vi q as issues tão em pt, entao podem responder em PT

viniciussanchez commented 11 months ago

Se for um problema, pode enviar um PR tornando-as como virtual