JSONRPC // all tests are green (WIP)

This commit is contained in:
Daniele Teti 2022-07-23 01:21:52 +02:00
parent 321e80e403
commit 10dff93784
7 changed files with 79 additions and 111 deletions

View File

@ -345,6 +345,7 @@ type
class function Create: TSimpleRecord; overload; static; class function Create: TSimpleRecord; overload; static;
class function Create(Value: Integer): TSimpleRecord; overload; static; class function Create(Value: Integer): TSimpleRecord; overload; static;
function ToString: String; function ToString: String;
function Equals(SimpleRecord: TSimpleRecord): Boolean;
end; end;
TSimpleRecordDynArray = TArray<TSimpleRecord>; TSimpleRecordDynArray = TArray<TSimpleRecord>;
@ -365,6 +366,7 @@ type
SimpleRecordDynArray: TSimpleRecordDynArray; SimpleRecordDynArray: TSimpleRecordDynArray;
SimpleRecordStaticArray: TSimpleRecordStaticArray; SimpleRecordStaticArray: TSimpleRecordStaticArray;
class function Create: TComplexRecord; static; class function Create: TComplexRecord; static;
function Equals(ComplexRecord: TComplexRecord): Boolean;
end; end;
TComplexRecordArray = TArray<TComplexRecord>; TComplexRecordArray = TArray<TComplexRecord>;
@ -790,6 +792,21 @@ begin
Result.CurrencyProperty := Value + Value div 1000; Result.CurrencyProperty := Value + Value div 1000;
end; end;
function TSimpleRecord.Equals(SimpleRecord: TSimpleRecord): Boolean;
begin
Result := StringProperty = SimpleRecord.StringProperty;
Result := IntegerProperty = SimpleRecord.IntegerProperty;
Result := FloatProperty = SimpleRecord.FloatProperty;
Result := CurrencyProperty = SimpleRecord.CurrencyProperty;
Result := DateProperty = SimpleRecord.DateProperty;
Result := TimeProperty = SimpleRecord.TimeProperty;
Result := CompareValue(DateTimeProperty, SimpleRecord.DateTimeProperty, 0.0001) = 0;
Result := BooleanProperty = SimpleRecord.BooleanProperty;
Result := EnumProperty = SimpleRecord.EnumProperty;
Result := SetProperty * SimpleRecord.SetProperty = [EnumItem1, EnumItem3];
Result := SetProperty - SimpleRecord.SetProperty = [];
end;
function TSimpleRecord.ToString: String; function TSimpleRecord.ToString: String;
function SetToString: String; function SetToString: String;
var var
@ -838,6 +855,22 @@ begin
Result.SimpleRecordStaticArray[2] := TSimpleRecord.Create(5); Result.SimpleRecordStaticArray[2] := TSimpleRecord.Create(5);
end; end;
function TComplexRecord.Equals(ComplexRecord: TComplexRecord): Boolean;
begin
Result := StringProperty = ComplexRecord.StringProperty;
Result := IntegerProperty = ComplexRecord.IntegerProperty;
Result := FloatProperty = ComplexRecord.FloatProperty;
Result := CurrencyProperty = ComplexRecord.CurrencyProperty;
Result := DateProperty = ComplexRecord.DateProperty;
Result := TimeProperty = ComplexRecord.TimeProperty;
Result := CompareValue(DateTimeProperty, ComplexRecord.DateTimeProperty, 0.0001) = 0;
Result := BooleanProperty = ComplexRecord.BooleanProperty;
Result := EnumProperty = ComplexRecord.EnumProperty;
Result := SetProperty * ComplexRecord.SetProperty = [EnumItem1, EnumItem3];
Result := SetProperty - ComplexRecord.SetProperty = [];
end;
initialization initialization
Randomize; Randomize;

View File

@ -68,6 +68,8 @@
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys> <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale> <VerInfo_Locale>1033</VerInfo_Locale>
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File> <Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
<DCC_ExeOutput>.\bin</DCC_ExeOutput>
<AppDPIAwarenessMode>none</AppDPIAwarenessMode>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''"> <PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_UsePackage>DBXSqliteDriver;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;Intraweb;DBXOracleDriver;Spring.Data;inetdb;FmxTeeUI;emsedge;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;DataSnapCommon;DataSnapConnectors;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;emshosting;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;DataSnapServerMidas;$(DCC_UsePackage)</DCC_UsePackage> <DCC_UsePackage>DBXSqliteDriver;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;Intraweb;DBXOracleDriver;Spring.Data;inetdb;FmxTeeUI;emsedge;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;DataSnapCommon;DataSnapConnectors;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;emshosting;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;DataSnapServerMidas;$(DCC_UsePackage)</DCC_UsePackage>
@ -84,6 +86,8 @@
<DCC_RemoteDebug>false</DCC_RemoteDebug> <DCC_RemoteDebug>false</DCC_RemoteDebug>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes> <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode> <AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''"> <PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols> <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
@ -127,6 +131,12 @@
<Source> <Source>
<Source Name="MainSource">jsonrpcclientwithobjects.dpr</Source> <Source Name="MainSource">jsonrpcclientwithobjects.dpr</Source>
</Source> </Source>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k280.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp280.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\bcboffice2k280.bpl">Embarcadero C++Builder Office 2000 Servers Package</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\bcbofficexp280.bpl">Embarcadero C++Builder Office XP Servers Package</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality> </Delphi.Personality>
<Deployment Version="3"> <Deployment Version="3">
<DeployFile LocalName="Win32\Debug\jsonrpcclientwithobjects.exe" Configuration="Debug" Class="ProjectOutput"> <DeployFile LocalName="Win32\Debug\jsonrpcclientwithobjects.exe" Configuration="Debug" Class="ProjectOutput">

View File

@ -453,7 +453,12 @@ uses
procedure RaiseSerializationError(const Msg: string); procedure RaiseSerializationError(const Msg: string);
begin begin
raise EMVCSerializationException.Create(Msg); raise EMVCSerializationException.Create(Msg) at ReturnAddress;
end;
procedure RaiseDeSerializationError(const Msg: string);
begin
raise EMVCDeSerializationException.Create(Msg) at ReturnAddress;
end; end;
function StrDict: TMVCStringDictionary; overload; function StrDict: TMVCStringDictionary; overload;
@ -1205,7 +1210,7 @@ begin
end end
else else
begin begin
raise EMVCDeserializationException.Create('Cannot deserialize field ' + RaiseDeSerializationError('Cannot deserialize field ' +
AField.FieldName); AField.FieldName);
end; end;
end; end;

View File

@ -54,9 +54,6 @@ type
procedure DeserializeRoot(const ASerializerObject: TObject; const AObject: TObject; procedure DeserializeRoot(const ASerializerObject: TObject; const AObject: TObject;
const AAttributes: TArray<TCustomAttribute>); const AAttributes: TArray<TCustomAttribute>);
public
{ public declarations }
end; end;
TMVCStringDictionarySerializer = class(TInterfacedObject, IMVCTypeSerializer) TMVCStringDictionarySerializer = class(TInterfacedObject, IMVCTypeSerializer)
@ -98,8 +95,6 @@ type
const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>); const ASerializerObject: TObject; const AAttributes: TArray<TCustomAttribute>);
procedure DeserializeRoot(const ASerializerObject: TObject; const AObject: TObject; procedure DeserializeRoot(const ASerializerObject: TObject; const AObject: TObject;
const AAttributes: TArray<TCustomAttribute>); const AAttributes: TArray<TCustomAttribute>);
// internal use
// class procedure Serialize(const ADict: TMVCStringDictionary; const AJSONObject: TJsonObject); inline;
end; end;
TMVCListOfStringSerializer = class(TInterfacedObject, IMVCTypeSerializer) TMVCListOfStringSerializer = class(TInterfacedObject, IMVCTypeSerializer)

View File

@ -81,12 +81,6 @@ type
const AIgnored: TMVCIgnoredList; const AIgnored: TMVCIgnoredList;
var AValue: TValue; const ACustomAttributes: TArray<TCustomAttribute>; var AValue: TValue; const ACustomAttributes: TArray<TCustomAttribute>;
const ARTTIField: TRTTIField); const ARTTIField: TRTTIField);
procedure JSONObjectToTValueForRecord(AJSONObject: TJSONObject;
const AType: TMVCSerializationType;
const AIgnored: TMVCIgnoredList;
var ABuffer: PByte;
var AValue: TValue;
const ACustomAttributes: TArray<TCustomAttribute>);
function GetDataSetFields(const ADataSet: TDataSet; const AIgnoredFields: TMVCIgnoredList; function GetDataSetFields(const ADataSet: TDataSet; const AIgnoredFields: TMVCIgnoredList;
const ANameCase: TMVCNameCase = ncAsIs): TMVCDataSetFields; const ANameCase: TMVCNameCase = ncAsIs): TMVCDataSetFields;
procedure ObjectToJsonObject(const AObject: TObject; const AJsonObject: TJDOJsonObject; procedure ObjectToJsonObject(const AObject: TObject; const AJsonObject: TJDOJsonObject;
@ -485,11 +479,16 @@ begin
begin begin
CastValue := AValue.AsType<TValue>; CastValue := AValue.AsType<TValue>;
if CastValue.TryCast(ValueTypeAtt.ValueTypeInfo, CastedValue) then if CastValue.TryCast(ValueTypeAtt.ValueTypeInfo, CastedValue) then
begin
TValueToJSONObjectProperty(AJsonObject, AName, CastedValue, stDefault, [], []) TValueToJSONObjectProperty(AJsonObject, AName, CastedValue, stDefault, [], [])
end
else else
raise EMVCSerializationException.CreateFmt begin
('Cannot serialize property or field "%s" of TypeKind tkRecord (TValue with MVCValueAsTypeAttribute).', RaiseSerializationError(
[AName]); Format(
'Cannot serialize property or field "%s" of TypeKind tkRecord (TValue with MVCValueAsTypeAttribute)',
[AName]));
end;
end end
else else
begin begin
@ -1743,13 +1742,6 @@ var
TSetOfType = set of TSetOfTypeElement; TSetOfType = set of TSetOfTypeElement;
var var
I: Integer; I: Integer;
lStrArr: TArray<string>;
lIntArr: TArray<Integer>;
lLongArr: TArray<Int64>;
lDoubleArr: TArray<Double>;
lBoolArr: TArray<Boolean>;
lSetOfType: TSetOfType;
lEl: TSetOfTypeElement;
lJArr: TJsonArray; lJArr: TJsonArray;
lArrayItemType: TJsonDataType; lArrayItemType: TJsonDataType;
begin begin
@ -2046,6 +2038,7 @@ begin
[AValue.GetArrayLength, AJSONObject.A[APropertyName].Count])); [AValue.GetArrayLength, AJSONObject.A[APropertyName].Count]));
end; end;
SetLength(lArr, AJSONObject.A[APropertyName].Count); SetLength(lArr, AJSONObject.A[APropertyName].Count);
lInnerType := lCtx.GetType(AValue.GetArrayElement(0).TypeInfo);
BuildATValueArrayFromJSONArrayOfJSONObject; BuildATValueArrayFromJSONArrayOfJSONObject;
AValue := TValue.FromArray(ARTTIField.FieldType.Handle, lArr); AValue := TValue.FromArray(ARTTIField.FieldType.Handle, lArr);
end end
@ -2489,33 +2482,6 @@ begin
end; end;
end; end;
//procedure TMVCJsonDataObjectsSerializer.JSONObjectToNestedRecordFieldStatic(
// const JSONObject: TJsonObject; RecordFieldRTTIType: TRttiField; const TypeOffset: Integer; );
//var
// lChildType: TRttiType;
// lChildFieldOffset: Integer;
// lKeyName: String;
// lValue: TValue;
//begin
// if RecordFieldRTTIType.FieldType.TypeKind <> tkRecord then
// begin
// raise EMVCDeserializationException.Create('Only record type allowed');
// end;
//
// //Recupero il tipo e l'offset
// lChildType := RecordFieldRTTIType.FieldType;
// lChildFieldOffset := RecordFieldRTTIType.Offset + TypeOffset;
//
// //recupero i campi
// for var lField in lChildType.GetFields do
// begin
// lKeyName := TMVCSerializerHelper.GetKeyName(lField, lChildType);
// lValue := lField.GetValue(Buffer + lChildFieldOffset);
// JSONObjectPropertyToTValueForRecord(JSONObject, lKeyName, stFields, nil, lValue, nil, lField);
// lField.SetValue(Buffer + lChildFieldOffset, lValue);
// end;
//end;
procedure TMVCJsonDataObjectsSerializer.ListToJsonArray(const AList: IMVCList; const AJsonArray: TJDOJsonArray; procedure TMVCJsonDataObjectsSerializer.ListToJsonArray(const AList: IMVCList; const AJsonArray: TJDOJsonArray;
const AType: TMVCSerializationType; const AIgnoredAttributes: TMVCIgnoredList; const AType: TMVCSerializationType; const AIgnoredAttributes: TMVCIgnoredList;
const ASerializationAction: TMVCSerializationAction); const ASerializationAction: TMVCSerializationAction);
@ -2527,7 +2493,9 @@ var
lJSONValue: TJsonBaseObject; lJSONValue: TJsonBaseObject;
begin begin
if not Assigned(AList) then if not Assigned(AList) then
begin
raise EMVCSerializationException.Create('List not assigned'); raise EMVCSerializationException.Create('List not assigned');
end;
if Assigned(ASerializationAction) then if Assigned(ASerializationAction) then
begin begin
lDict := TJDOLinks.Create; lDict := TJDOLinks.Create;
@ -2556,12 +2524,10 @@ begin
else else
begin begin
lJSONValue.Free; lJSONValue.Free;
RaiseSerializationError('Invalid JSON Data Type'); RaiseSerializationError('Invalid JSON Data Type: ' +
GetEnumName(TypeInfo(TJsonDataType), Ord(lJsonDataType)));
end end
end; end;
// InternalObjectToJsonObject(AList.GetItem(I), AJsonArray.AddObject, AType, AIgnoredAttributes, nil, nil,
// nil);
end; end;
end; end;
end; end;
@ -3780,28 +3746,6 @@ begin
raise EMVCException.Create(HTTP_STATUS.BadRequest, lErrMsg); raise EMVCException.Create(HTTP_STATUS.BadRequest, lErrMsg);
end; end;
end; end;
//
// for var lField in lType.GetFields do
// begin
// lKeyName := TMVCSerializerHelper.GetKeyName(lField, lType);
// lValue := lField.GetValue(@Result);
// JSONObjectToRecord()()
//// JSONObjectPropertyToTValueForRecord(JSONObject, lKeyName, stFields, nil, lValue, nil, lField);
//// var lB: PByte;
//// lB := PByte(@Result);
//// JSONObjectToNestedRecordField(JSONObject, lField, lField.Offset, lB);
// lField.SetValue(@Result, lValue);
// end;
end;
procedure TMVCJsonDataObjectsSerializer.JSONObjectToTValueForRecord(
AJSONObject: TJSONObject; const AType: TMVCSerializationType;
const AIgnored: TMVCIgnoredList; var ABuffer: PByte; var AValue: TValue;
const ACustomAttributes: TArray<TCustomAttribute>);
begin
end; end;
function TMVCJsonDataObjectsSerializer.StrToRecord<T>(const AJSONString: String): T; function TMVCJsonDataObjectsSerializer.StrToRecord<T>(const AJSONString: String): T;

View File

@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ProjectGuid>{ABDCF3F4-55C9-4C93-9DA7-7E7D35B0FE68}</ProjectGuid> <ProjectGuid>{ABDCF3F4-55C9-4C93-9DA7-7E7D35B0FE68}</ProjectGuid>
<ProjectVersion>19.3</ProjectVersion> <ProjectVersion>19.4</ProjectVersion>
<FrameworkType>VCL</FrameworkType> <FrameworkType>VCL</FrameworkType>
<MainSource>MVCAREntitiesGenerator.dpr</MainSource> <MainSource>MVCAREntitiesGenerator.dpr</MainSource>
<Base>True</Base> <Base>True</Base>
@ -1312,17 +1312,17 @@
<Operation>1</Operation> <Operation>1</Operation>
</Platform> </Platform>
</DeployClass> </DeployClass>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/> <ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/> <ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/> <ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/> <ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/> <ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
</Deployment> </Deployment>
<Platforms> <Platforms>
<Platform value="Win32">True</Platform> <Platform value="Win32">True</Platform>

View File

@ -303,8 +303,6 @@ type
[TestFixture] [TestFixture]
[Category('jsonrpc')] [Category('jsonrpc')]
TJSONRPCServerTest = class(TObject) TJSONRPCServerTest = class(TObject)
private
procedure TestRequest_NoParams_DynamicArrayOfRecordAsResult;
protected protected
FExecutor: IMVCJSONRPCExecutor; FExecutor: IMVCJSONRPCExecutor;
FExecutor2: IMVCJSONRPCExecutor; FExecutor2: IMVCJSONRPCExecutor;
@ -368,6 +366,8 @@ type
procedure TestRequest_Echo_SingleRecordAsResult; procedure TestRequest_Echo_SingleRecordAsResult;
[Test] [Test]
procedure TestRequest_Echo_ComplexRecords; procedure TestRequest_Echo_ComplexRecords;
[Test]
procedure TestRequest_NoParams_DynamicArrayOfRecordAsResult;
end; end;
[TestFixture] [TestFixture]
@ -2965,7 +2965,7 @@ procedure TJSONRPCServerTest.TestRequest_Echo_ComplexRecords;
var var
lReq: IJSONRPCRequest; lReq: IJSONRPCRequest;
lRPCResp: IJSONRPCResponse; lRPCResp: IJSONRPCResponse;
lComplexRecIn, lComplexRec: TComplexRecordArray; lComplexRecIn, lComplexRecOut: TComplexRecordArray;
begin begin
lReq := TJSONRPCRequest.Create; lReq := TJSONRPCRequest.Create;
lReq.Method := 'EchoArrayOfRecords'; lReq.Method := 'EchoArrayOfRecords';
@ -2978,21 +2978,12 @@ begin
lReq.Params.Add(TValue.From<TComplexRecordArray>(lComplexRecIn), pdtArrayOfRecords); lReq.Params.Add(TValue.From<TComplexRecordArray>(lComplexRecIn), pdtArrayOfRecords);
lRPCResp := FExecutor2.ExecuteRequest(lReq); lRPCResp := FExecutor2.ExecuteRequest(lReq);
Assert.IsFalse(lRPCResp.IsError, lRPCResp.Error.ErrMessage); Assert.IsFalse(lRPCResp.IsError, lRPCResp.AsJSONString);
TFile.WriteAllText('outputcomplexrecordarray.json', lRPCResp.ResultAsJSONArray.ToJSON(False)); TFile.WriteAllText('outputcomplexrecordarray.json', lRPCResp.ResultAsJSONArray.ToJSON(False));
// lSimpleRec := TMVCRecordUtils.JsonObjectToRecord<TSimpleRecord>(lRPCResp.ResultAsJSONObject); lComplexRecOut := TMVCRecordUtils.JSONArrayToArrayOfRecord<TComplexRecord>(lRPCResp.ResultAsJSONArray);
// Assert.AreEqual(lSimpleRecIn.StringProperty, lSimpleRec.StringProperty); lComplexRecIn[0].Equals(lComplexRecOut[0]);
// Assert.AreEqual(lSimpleRecIn.IntegerProperty, lSimpleRec.IntegerProperty); lComplexRecIn[1].Equals(lComplexRecOut[1]);
// Assert.AreEqual(lSimpleRecIn.FloatProperty, lSimpleRec.FloatProperty);
// Assert.AreEqual(lSimpleRecIn.CurrencyProperty, lSimpleRec.CurrencyProperty);
// Assert.AreEqual(lSimpleRecIn.DateProperty, lSimpleRec.DateProperty);
// Assert.AreEqual(lSimpleRecIn.TimeProperty, lSimpleRec.TimeProperty);
// Assert.AreEqual(lSimpleRecIn.DateTimeProperty, lSimpleRec.DateTimeProperty, 0.000001);
// Assert.AreEqual(lSimpleRecIn.BooleanProperty, lSimpleRec.BooleanProperty);
// Assert.AreEqual(lSimpleRecIn.EnumProperty, lSimpleRec.EnumProperty);
// Assert.IsTrue(lSimpleRecIn.SetProperty * lSimpleRec.SetProperty = [EnumItem1, EnumItem3]);
// Assert.IsTrue(lSimpleRec.SetProperty - lSimpleRecIn.SetProperty = []);
end; end;
procedure TJSONRPCServerTest.TestRequest_Echo_SingleRecordAsResult; procedure TJSONRPCServerTest.TestRequest_Echo_SingleRecordAsResult;
@ -3009,17 +3000,7 @@ begin
lReq.Params.Add(TValue.From<TSimpleRecord>(lSimpleRecIn), pdtRecord); lReq.Params.Add(TValue.From<TSimpleRecord>(lSimpleRecIn), pdtRecord);
lRPCResp := FExecutor2.ExecuteRequest(lReq); lRPCResp := FExecutor2.ExecuteRequest(lReq);
lSimpleRec := TMVCRecordUtils.JsonObjectToRecord<TSimpleRecord>(lRPCResp.ResultAsJSONObject); lSimpleRec := TMVCRecordUtils.JsonObjectToRecord<TSimpleRecord>(lRPCResp.ResultAsJSONObject);
Assert.AreEqual(lSimpleRecIn.StringProperty, lSimpleRec.StringProperty); Assert.IsTrue(lSimpleRecIn.Equals(lSimpleRec));
Assert.AreEqual(lSimpleRecIn.IntegerProperty, lSimpleRec.IntegerProperty);
Assert.AreEqual(lSimpleRecIn.FloatProperty, lSimpleRec.FloatProperty);
Assert.AreEqual(lSimpleRecIn.CurrencyProperty, lSimpleRec.CurrencyProperty);
Assert.AreEqual(lSimpleRecIn.DateProperty, lSimpleRec.DateProperty);
Assert.AreEqual(lSimpleRecIn.TimeProperty, lSimpleRec.TimeProperty);
Assert.AreEqual(lSimpleRecIn.DateTimeProperty, lSimpleRec.DateTimeProperty, 0.000001);
Assert.AreEqual(lSimpleRecIn.BooleanProperty, lSimpleRec.BooleanProperty);
Assert.AreEqual(lSimpleRecIn.EnumProperty, lSimpleRec.EnumProperty);
Assert.IsTrue(lSimpleRecIn.SetProperty * lSimpleRec.SetProperty = [EnumItem1, EnumItem3]);
Assert.IsTrue(lSimpleRec.SetProperty - lSimpleRecIn.SetProperty = []);
end; end;
procedure TJSONRPCServerTest.TestRequest_NamedParams_S_I_ret_S; procedure TJSONRPCServerTest.TestRequest_NamedParams_S_I_ret_S;