unit UtOpenApiPascalTypes; {$mode ObjFPC}{$H+} interface uses Classes, SysUtils, fpcunit, testregistry, fpjson.schema.types, fpjson.schema.pascaltypes, fpopenapi.types, fpopenapi.objects, fpopenapi.pascaltypes; Type { TTestPascalTypes } TTestPascalTypes = Class(TTestCase) private FAPI: TOpenAPI; FAPIData: TAPIData; function AssertService(const Msg: String; aService: TAPIService; const aName: string; aMethods: array of string): TAPIService; function AssertServiceMethod(const Msg: string; aMethod: TAPIServiceMethod; aParams: array of string; const aResultName, aBodyName: string): TAPIServiceMethod; function AssertServiceMethodResult(const Msg: string; aMethod: TAPIServiceMethod; aResultTypeData: TAPITypeData; const aResultClassName, aResultInterfaceName: string): TAPIServiceMethod; procedure AssertSimpleComponent(const Msg: String; aType: TAPITypeData); Public class procedure AssertEquals(const Msg: string; aExpected, aActual: TPascalType); overload; function AssertPascalTypeData(const Msg: string; aType: TPascalTypeData; aPascaltype: TPascalType; const aSchemaName, aPascalName: String) : TPascalTypeData; procedure AssertProperty(Msg: String; aType: TPascalTypeData; aIndex: Integer; const aSchemaName, aPascalName, aPascalTypeName: String; aPascalType: TPascalType; aTypeData: TPascalTypeData); procedure Load(const aFileName: string); procedure Setup; override; procedure TearDown; override; Property API : TOpenAPI Read FAPI; Property Data : TAPIData Read FAPIData; Published procedure TestHookup; procedure TestFindService; procedure TestSimpleComponent; procedure TestSimpleService; procedure TestSimpleServiceArrayArgument; procedure TestDoubleServiceArrayArgument; procedure TestServiceNoApplicationJSONResponse; procedure TestServiceNoApplicationJSONRequestBody; end; implementation uses typinfo, fpopenapi.reader; { TTestPascalTypes } class procedure TTestPascalTypes.AssertEquals(const Msg : string; aExpected, aActual : TPascalType); begin AssertEquals(Msg,GetEnumName(Typeinfo(TPascalType),Ord(aExpected)), GetEnumName(Typeinfo(TPascalType),Ord(aActual))); end; function TTestPascalTypes.AssertPascalTypeData(const Msg: string; aType: TPascalTypeData; aPascaltype: TPascalType; const aSchemaName, aPascalName: String): TPascalTypeData; begin AssertNotNull(Msg+': have type',aType); AssertEquals(Msg+' Schema name',aSchemaName,aType.SchemaName); AssertEquals(Msg+' Pascal name',aPascalName,aType.PascalName); AssertEquals(Msg+' Pascal type',aPascalType,aType.PascalType); Result:=aType; end; procedure TTestPascalTypes.AssertProperty(Msg : String; aType : TPascalTypeData; aIndex : Integer; const aSchemaName,aPascalName,aPascalTypeName : String; aPascalType : TPascalType; aTypeData: TPascalTypeData); var lProp : TPascalPropertyData; begin AssertNotNull(Msg+': have type',aType); AssertTrue(Msg+': have properties',aType.PropertyCount>0); AssertTrue(Msg+': have valid index',aIndex