mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
2.1.3 (lithium)
FIX https://github.com/danieleteti/delphimvcframework/issues/64 ADDED Unit Tests for avoid regressions
This commit is contained in:
parent
9a3ab1f1dc
commit
c8074649a1
BIN
docs/periodic_table.png
Normal file
BIN
docs/periodic_table.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 MiB |
@ -1949,6 +1949,8 @@ var
|
||||
LClassName: string;
|
||||
LJSONKeyIsNotPresent: boolean;
|
||||
begin
|
||||
if not Assigned(AJSONObject) then
|
||||
raise EMapperException.Create('JSON Object cannot be nil');
|
||||
jvalue := nil;
|
||||
_type := ctx.GetType(AObject.ClassInfo);
|
||||
_fields := _type.GetFields;
|
||||
@ -2216,6 +2218,8 @@ var
|
||||
ListItem: TValue;
|
||||
ListParam: TRttiParameter;
|
||||
begin
|
||||
if not Assigned(AJSONObject) then
|
||||
raise EMapperException.Create('JSON Object cannot be nil');
|
||||
_type := ctx.GetType(AObject.ClassInfo);
|
||||
_fields := _type.GetProperties;
|
||||
for _field in _fields do
|
||||
@ -2437,11 +2441,16 @@ var
|
||||
lJSON: TJSONObject;
|
||||
begin
|
||||
lJSON := TJSONObject.ParseJSONValue(AJSONObjectString) as TJSONObject;
|
||||
try
|
||||
InternalJSONObjectFieldsToObject(ctx, lJSON, AObject);
|
||||
finally
|
||||
lJSON.Free;
|
||||
end;
|
||||
if Assigned(lJSON) then
|
||||
begin
|
||||
try
|
||||
InternalJSONObjectFieldsToObject(ctx, lJSON, AObject);
|
||||
finally
|
||||
lJSON.Free;
|
||||
end;
|
||||
end
|
||||
else
|
||||
EMapperException.Create('Invalid JSON');
|
||||
end;
|
||||
|
||||
class function Mapper.JSONObjectFieldsToObject(AJSONObject
|
||||
@ -2477,11 +2486,16 @@ var
|
||||
JObj: TJSONObject;
|
||||
begin
|
||||
JObj := TJSONObject.ParseJSONValue(AJSONObjectString) as TJSONObject;
|
||||
try
|
||||
Result := JSONObjectToObject<T>(JObj);
|
||||
finally
|
||||
JObj.Free;
|
||||
end;
|
||||
if Assigned(JObj) then
|
||||
begin
|
||||
try
|
||||
Result := JSONObjectToObject<T>(JObj);
|
||||
finally
|
||||
JObj.Free;
|
||||
end;
|
||||
end
|
||||
else
|
||||
raise EMapperException.Create('Invalid JSON');
|
||||
end;
|
||||
|
||||
class procedure Mapper.JSONObjectToDataSet(AJSONObject: TJSONObject;
|
||||
|
@ -1,2 +1,2 @@
|
||||
const
|
||||
DMVCFRAMEWORK_VERSION = '2.1.2 (helium)';
|
||||
DMVCFRAMEWORK_VERSION = '2.1.3 (lithium)';
|
@ -64,7 +64,8 @@ type
|
||||
procedure TestJSONArrayToObjectListNoGenericsWrappedList;
|
||||
procedure TestCheckMapperSerializeAsStringIsEmptyStrIfObjIsNil;
|
||||
procedure TestJSONObjectToObjectWithNullInJSONString;
|
||||
|
||||
procedure TestJSONObjectStringToObject;
|
||||
procedure TestJSONObjectStringToObjectWithWrongJSON;
|
||||
end;
|
||||
|
||||
TTestRouting = class(TTestCase)
|
||||
@ -586,6 +587,39 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestMappers.TestJSONObjectStringToObject;
|
||||
const
|
||||
MYOBJECTJSON =
|
||||
'{"PropString":"Some text \u00E0\u00E8\u00E9\u00EC\u00F2\u00F9",' +
|
||||
'"PropAnsiString":"This is an ANSI text","PropInteger":-1234,' +
|
||||
'"PropUInt32":1234,"PropInt64":-1234567890,"PropUInt64":1234567890,' +
|
||||
'"PropUInt16":12345,"PropInt16":-12345,"PropBoolean":true,' +
|
||||
'"PropDate":"2010-10-20","PropTime":"10:20:30",' +
|
||||
'"PropDateTime":"2010-10-20 10:20:30",' +
|
||||
'"PropTimeStamp":63423339630040,"PropCurrency":1234.5678}';
|
||||
var
|
||||
lMyObject: TMyObject;
|
||||
lMyObject2: TMyObject;
|
||||
begin
|
||||
lMyObject := Mapper.JSONObjectStringToObject<TMyObject>(MYOBJECTJSON);
|
||||
try
|
||||
lMyObject2 := GetMyObject;
|
||||
try
|
||||
CheckTrue(lMyObject.Equals(lMyObject2));
|
||||
finally
|
||||
lMyObject2.Free;
|
||||
end;
|
||||
finally
|
||||
lMyObject.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestMappers.TestJSONObjectStringToObjectWithWrongJSON;
|
||||
begin
|
||||
ExpectedException := EMapperException;
|
||||
Mapper.JSONObjectStringToObject<TObject>('{wrongjson}');
|
||||
end;
|
||||
|
||||
procedure TTestMappers.TestJSONObjectToObjectAndBack;
|
||||
var
|
||||
Obj: TMyObject;
|
||||
|
Loading…
Reference in New Issue
Block a user