mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
This commit is contained in:
parent
c726fceb23
commit
35b7732b40
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<BorlandProject>
|
||||
<Transactions>
|
||||
<Transaction>2013/11/14 10:47:51.676,D:\DLib\DelphiMVCFramework\samples\angularjs\WebClientAngularJSSample.dproj=D:\DLib\DelphiMVCFramework\samples\angularjs\BasicDemo.dproj</Transaction>
|
||||
<Transaction>2013/11/14 10:48:01.461,D:\DLib\DelphiMVCFramework\samples\angularjs\WebClientSample.dproj=D:\DLib\DelphiMVCFramework\samples\angularjs\WebClientAngularJSSample.dproj</Transaction>
|
||||
<Transaction>2013/11/14 10:51:46.799,D:\DLib\DelphiMVCFramework\samples\angularjs\BaseController.pas=</Transaction>
|
||||
<Transaction>2013/11/14 10:52:18.660,D:\DLib\DelphiMVCFramework\samples\angularjs\WebSiteControllerU.pas=D:\DLib\DelphiMVCFramework\samples\angularjs\App1MainControllerU.pas</Transaction>
|
||||
<Transaction>2013/11/14 10:52:22.755,D:\DLib\DelphiMVCFramework\samples\angularjs\ToDoControllerU.pas=D:\DLib\DelphiMVCFramework\samples\angularjs\ToDoController.pas</Transaction>
|
||||
</Transactions>
|
||||
</BorlandProject>
|
@ -1143,7 +1143,7 @@ var
|
||||
begin
|
||||
inherited Create;
|
||||
c := AWebRequest.GetFieldByName('content-type');
|
||||
CT := c.Split([':'])[1].Split([';']);
|
||||
CT := c.Split([';']);
|
||||
FContentType := trim(CT[0]);
|
||||
FContentEncoding := 'UTF-8'; // default encoding
|
||||
if Length(CT) > 1 then
|
||||
|
@ -1358,6 +1358,8 @@ end;
|
||||
|
||||
class function Mapper.JSONObjectToObject<T>(AJSONObject: TJSONObject): T;
|
||||
begin
|
||||
if not Assigned(AJSONObject) then
|
||||
raise Exception.Create('JSONObject not assigned');
|
||||
Result := Mapper.JSONObjectToObject(T.QualifiedClassName, AJSONObject) as T;
|
||||
// Result := JSONObjectToObject(TObject.ClassInfo, AJSONObject);
|
||||
end;
|
||||
|
@ -21,7 +21,8 @@ uses
|
||||
LiveServerTestU in 'LiveServerTestU.pas',
|
||||
MessagingExtensionsTestU in 'MessagingExtensionsTestU.pas',
|
||||
TestControllersU in 'TestControllersU.pas',
|
||||
MVCFramework.RESTClient in '..\..\sources\MVCFramework.RESTClient.pas';
|
||||
MVCFramework.RESTClient in '..\..\sources\MVCFramework.RESTClient.pas',
|
||||
BusinessObjectsU in '..\..\samples\commons\BusinessObjectsU.pas';
|
||||
|
||||
{$R *.RES}
|
||||
|
||||
|
@ -97,6 +97,7 @@
|
||||
<DCCReference Include="MessagingExtensionsTestU.pas"/>
|
||||
<DCCReference Include="TestControllersU.pas"/>
|
||||
<DCCReference Include="..\..\sources\MVCFramework.RESTClient.pas"/>
|
||||
<DCCReference Include="..\..\samples\commons\BusinessObjectsU.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
|
@ -23,6 +23,7 @@ type
|
||||
published
|
||||
procedure TestReqWithParams;
|
||||
procedure TestPOSTWithParamsAndJSONBody;
|
||||
procedure TestPOSTWithObjectJSONBody;
|
||||
procedure TestPUTWithParamsAndJSONBody;
|
||||
procedure TestSession;
|
||||
procedure TestAsynchRequestPOST;
|
||||
@ -41,7 +42,7 @@ uses
|
||||
Data.DBXJSON,
|
||||
MVCFramework.Commons,
|
||||
System.SyncObjs,
|
||||
System.SysUtils;
|
||||
System.SysUtils, BusinessObjectsU, ObjectsMappers;
|
||||
|
||||
{ TServerTest }
|
||||
|
||||
@ -218,6 +219,33 @@ begin
|
||||
CheckEquals('àèéìòù', res.BodyAsJsonObject.Get('name3').JsonValue.Value);
|
||||
end;
|
||||
|
||||
procedure TServerTest.TestPOSTWithObjectJSONBody;
|
||||
var
|
||||
r: IRESTResponse;
|
||||
json: TJSONObject;
|
||||
P: TPerson;
|
||||
begin
|
||||
P := TPerson.Create;
|
||||
try
|
||||
P.FirstName := 'Daniele';
|
||||
P.LastName := 'àòùèéì';
|
||||
P.DOB := EncodeDate(1979, 1, 1);
|
||||
P.Married := true;
|
||||
r := RESTClient.Accept(TMVCMimeType.APPLICATION_JSON).doPOST('/objects', [], mapper.ObjectToJSONObject(P));
|
||||
finally
|
||||
P.Free;
|
||||
end;
|
||||
P := mapper.JSONObjectToObject<TPerson>(r.BodyAsJsonObject);
|
||||
try
|
||||
CheckEquals('Daniele', P.FirstName);
|
||||
CheckEquals('àòùèéì', P.LastName);
|
||||
CheckEquals(true, P.Married);
|
||||
CheckEquals(EncodeDate(1979, 1, 1), P.DOB);
|
||||
finally
|
||||
P.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TServerTest.TestPOSTWithParamsAndJSONBody;
|
||||
var
|
||||
r: IRESTResponse;
|
||||
@ -326,7 +354,7 @@ end;
|
||||
|
||||
procedure TBaseServerTest.DoLoginWith(UserName: string);
|
||||
var
|
||||
p: TJSONObject;
|
||||
P: TJSONObject;
|
||||
res: IRESTResponse;
|
||||
begin
|
||||
res := RESTClient.doGET('/login', [UserName]);
|
||||
|
@ -24,7 +24,8 @@ uses
|
||||
RTTIUtilsU in '..\..\sources\RTTIUtilsU.pas',
|
||||
ObjectsMappers in '..\..\sources\ObjectsMappers.pas',
|
||||
DuckListU in '..\..\sources\DuckListU.pas',
|
||||
MVCFramework.BUSController in '..\..\sources\MVCFramework.BUSController.pas';
|
||||
MVCFramework.BUSController in '..\..\sources\MVCFramework.BUSController.pas',
|
||||
BusinessObjectsU in '..\..\samples\commons\BusinessObjectsU.pas';
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
@ -107,6 +107,7 @@
|
||||
<DCCReference Include="..\..\sources\ObjectsMappers.pas"/>
|
||||
<DCCReference Include="..\..\sources\DuckListU.pas"/>
|
||||
<DCCReference Include="..\..\sources\MVCFramework.BUSController.pas"/>
|
||||
<DCCReference Include="..\..\samples\commons\BusinessObjectsU.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
|
@ -59,7 +59,10 @@ type
|
||||
[MVCProduces('text/plain')]
|
||||
procedure TestConsumesProducesText(ctx: TWebContext);
|
||||
|
||||
|
||||
[MVCPath('/objects')]
|
||||
[MVCHTTPMethod([httpPOST, httpPUT])]
|
||||
[MVCProduces('application/json')]
|
||||
procedure TestPOSTObject(ctx: TWebContext);
|
||||
|
||||
end;
|
||||
|
||||
@ -68,7 +71,7 @@ implementation
|
||||
uses
|
||||
Data.DBXJSON,
|
||||
MVCFramework.Commons,
|
||||
Web.HTTPApp;
|
||||
Web.HTTPApp, BusinessObjectsU;
|
||||
|
||||
{ TTestServerController }
|
||||
|
||||
@ -198,4 +201,12 @@ begin
|
||||
Render(Obj);
|
||||
end;
|
||||
|
||||
procedure TTestServerController.TestPOSTObject(ctx: TWebContext);
|
||||
var
|
||||
Person: TPerson;
|
||||
begin
|
||||
Person := ctx.Request.BodyAs<TPerson>();
|
||||
Render(Person);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user