Added specific test for ser/unser of objects decorated with Sqids

This commit is contained in:
Daniele Teti 2024-05-16 17:15:59 +02:00
parent 4c5441d5e4
commit cb01d14729
3 changed files with 80 additions and 2 deletions

View File

@ -30,8 +30,8 @@ type
[MVCPath('/($ID:sqids)')]
[MVCHTTPMethods([httpPUT])]
function UpdateCustomerByID(
[MVCFromBody] const Customer: TCustomer;
const ID: Integer;
[MVCFromBody] const Customer: TCustomer;
[MVCInject] CustomersService: ICustomersService): IMVCResponse;
[MVCPath]
@ -70,7 +70,7 @@ begin
Result := OKResponse(CustomersService.GetByRQL(RQLFilter));
end;
function TCustomersController.UpdateCustomerByID(const Customer: TCustomer; const ID: Integer; CustomersService: ICustomersService): IMVCResponse;
function TCustomersController.UpdateCustomerByID(const ID: Integer; const Customer: TCustomer; CustomersService: ICustomersService): IMVCResponse;
begin
CustomersService.UpdateByID(ID, Customer);
Result := OKResponse;

View File

@ -423,6 +423,13 @@ type
FPropCurrency: Currency;
fPropJSONObject: TJSONObject;
FPropIntegerSqids: Integer;
FPropInt64Sqids: Int64;
FPropUInt32Sqids: UInt32;
FPropInt32Sqids: Int32;
FPropUInt16Sqids: UInt16;
FPropInt16Sqids: Int16;
FPropUInt64Sqids: UInt64;
FPropInt32: cardinal;
procedure SetPropAnsiString(const Value: AnsiString);
procedure SetPropString(const Value: string);
procedure SetPropInt64(const Value: Int64);
@ -437,6 +444,7 @@ type
procedure SetPropTimeStamp(const Value: TTimeStamp);
procedure SetPropTime(const Value: TTime);
procedure SetPropCurrency(const Value: Currency);
procedure SetPropInt32(const Value: cardinal);
public
constructor Create;
destructor Destroy; override;
@ -444,6 +452,7 @@ type
property PropString: string read FPropString write SetPropString;
property PropAnsiString: AnsiString read FPropAnsiString write SetPropAnsiString;
property PropInteger: Integer read FPropInteger write SetPropInteger;
property PropInt32: cardinal read FPropInt32 write SetPropInt32;
property PropUInt32: cardinal read FPropUInt32 write SetPropUInt32;
property PropInt64: Int64 read FPropInt64 write SetPropInt64;
property PropUInt64: UInt64 read FPropUInt64 write SetPropUInt64;
@ -460,6 +469,18 @@ type
{sqids}
[MVCSerializeAsSqids]
property PropIntegerSqids: Integer read FPropIntegerSqids write FPropIntegerSqids;
[MVCSerializeAsSqids]
property PropInt16Sqids: Int16 read FPropInt16Sqids write FPropInt16Sqids;
[MVCSerializeAsSqids]
property PropUInt16Sqids: UInt16 read FPropUInt16Sqids write FPropUInt16Sqids;
[MVCSerializeAsSqids]
property PropInt32Sqids: Int32 read FPropInt32Sqids write FPropInt32Sqids;
[MVCSerializeAsSqids]
property PropUInt32Sqids: UInt32 read FPropUInt32Sqids write FPropUInt32Sqids;
[MVCSerializeAsSqids]
property PropInt64Sqids: Int64 read FPropInt64Sqids write FPropInt64Sqids;
[MVCSerializeAsSqids]
property PropUInt64Sqids: UInt64 read FPropUInt64Sqids write FPropUInt64Sqids;
end;
TMyChildObject = class
@ -799,6 +820,7 @@ begin
Result.PropString := 'Some text àèéìòù';
Result.PropAnsiString := 'This is an ANSI text';
Result.PropInteger := -1234;
Result.PropInt32 := 1234;
Result.PropUInt32 := 1234;
Result.PropInt64 := -1234567890;
Result.PropUInt64 := 1234567890;
@ -820,6 +842,12 @@ begin
{sqids}
Result.PropIntegerSqids := 1234;
Result.PropInt16Sqids := -12345;
Result.PropUInt16Sqids := 12345;
Result.PropInt32Sqids := 1234;
Result.PropUInt32Sqids := 1234;
Result.PropInt64Sqids := -1234567890;
Result.PropUInt64Sqids := 1234567890;
end;
constructor TMyObject.Create;
@ -862,8 +890,15 @@ begin
{sqids}
Result := Result and (Self.PropIntegerSqids = Obj.PropIntegerSqids);
Result := Result and (Self.PropInt16 = Obj.PropInt16);
Result := Result and (Self.PropUInt16 = Obj.PropUInt16);
Result := Result and (Self.PropInt32Sqids = Obj.PropInt32Sqids);
Result := Result and (Self.PropUInt32 = Obj.PropUInt32);
Result := Result and (Self.PropInt64 = Obj.PropInt64);
Result := Result and (Self.PropUInt64 = Obj.PropUInt64);
end;
procedure TMyObject.SetPropAnsiString(const Value: AnsiString);
begin
FPropAnsiString := Value;
@ -894,6 +929,11 @@ begin
FPropInt16 := Value;
end;
procedure TMyObject.SetPropInt32(const Value: cardinal);
begin
FPropInt32 := Value;
end;
procedure TMyObject.SetPropInt64(const Value: Int64);
begin
FPropInt64 := Value;

View File

@ -60,6 +60,8 @@ type
{ serialize declarations }
[Test]
procedure TestSerializeAsSqids;
[Test]
procedure TestSerializeAllTypes;
[Test]
procedure TestSerializeDateTimeProperty;
@ -983,6 +985,42 @@ begin
end;
end;
procedure TMVCTestSerializerJsonDataObjects.TestSerializeAsSqids;
var
lObj1: TMyObject;
lSer: string;
begin
lObj1 := GetMyObject;
try
lSer := fSerializer.SerializeObject(lObj1);
finally
lObj1.Free;
end;
var lJObj := StrToJSONObject(lSer, True);
try
Assert.IsTrue(lJObj.Types['PropInt16'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropInteger'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropInt16'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropUInt16'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropInt32'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropUInt32'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropInt64'] = jdtInt);
Assert.IsTrue(lJObj.Types['PropUInt64'] = jdtLong);
Assert.IsTrue(lJObj.Types['PropInt16Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropIntegerSqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropInt16Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropUInt16Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropInt32Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropUInt32Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropInt64Sqids'] = jdtString);
Assert.IsTrue(lJObj.Types['PropUInt64Sqids'] = jdtString);
finally
lJObj.Free;
end;
end;
procedure TMVCTestSerializerJsonDataObjects.TestSerializeCollection;
const
JSON = '[' + '{' + '"Description":"Description 1"' + '},' + '{' + '"Description":"Description 2"' + '},' + '{' +