Changes in unit tests

This commit is contained in:
Ezequiel Juliano Müller 2017-03-20 17:42:28 -03:00
parent b9b7e1f3e9
commit 611f297425
6 changed files with 23 additions and 13 deletions

View File

@ -3,10 +3,12 @@ unit BusinessObjectsU;
interface interface
uses uses
MVCFramework.Serializer.Commons,
ObjectsMappers, Generics.Collections; ObjectsMappers, Generics.Collections;
type type
[MVCNameCase(MVCNameLowerCase)]
[MapperJSONNaming(JSONNameLowerCase)] [MapperJSONNaming(JSONNameLowerCase)]
TPerson = class TPerson = class
private private
@ -20,18 +22,19 @@ type
procedure SetMarried(const Value: boolean); procedure SetMarried(const Value: boolean);
public public
function Equals(Obj: TObject): boolean; override; function Equals(Obj: TObject): boolean; override;
// [MapperJsonSer('nome')]
property FirstName: string read FFirstName write SetFirstName; property FirstName: string read FFirstName write SetFirstName;
// [DoNotSerialize]
property LastName: string read FLastName write SetLastName; property LastName: string read FLastName write SetLastName;
property DOB: TDate read FDOB write SetDOB; property DOB: TDate read FDOB write SetDOB;
property Married: boolean read FMarried write SetMarried; property Married: boolean read FMarried write SetMarried;
class function GetNew(AFirstName, ALastName: string; ADOB: TDate; AMarried: boolean): TPerson; class function GetNew(AFirstName, ALastName: string; ADOB: TDate; AMarried: boolean): TPerson;
class function GetList: TObjectList<TPerson>; class function GetList: TObjectList<TPerson>;
end; end;
TPeople = class(TObjectList<TPerson>); TPeople = class(TObjectList<TPerson>);
[MVCNameCase(MVCNameLowerCase)]
[MapperJSONNaming(JSONNameLowerCase)] [MapperJSONNaming(JSONNameLowerCase)]
TCustomer = class TCustomer = class
private private
@ -50,8 +53,10 @@ type
public public
property name: string read FName write SetName; property name: string read FName write SetName;
[MapperTransient] [MapperTransient]
[MVCDoNotSerialize]
property ContactFirst: string read FContactFirst write SetContactFirst; property ContactFirst: string read FContactFirst write SetContactFirst;
[MapperTransient] [MapperTransient]
[MVCDoNotSerialize]
property ContactLast: string read FContactLast write SetContactLast; property ContactLast: string read FContactLast write SetContactLast;
property AddressLine1: string read FAddressLine1 write SetAddressLine1; property AddressLine1: string read FAddressLine1 write SetAddressLine1;
property AddressLine2: string read FAddressLine2 write SetAddressLine2; property AddressLine2: string read FAddressLine2 write SetAddressLine2;
@ -60,6 +65,7 @@ type
end; end;
[MapperJSONNaming(JSONNameLowerCase)] [MapperJSONNaming(JSONNameLowerCase)]
[MVCNameCase(MVCNameLowerCase)]
TProgrammer = class(TPerson) TProgrammer = class(TPerson)
private private
FSkills: string; FSkills: string;
@ -69,6 +75,7 @@ type
end; end;
[MapperJSONNaming(JSONNameLowerCase)] [MapperJSONNaming(JSONNameLowerCase)]
[MVCNameCase(MVCNameLowerCase)]
TPhilosopher = class(TPerson) TPhilosopher = class(TPerson)
private private
FMentors: string; FMentors: string;

View File

@ -395,6 +395,8 @@ class function TDuckTypedList.Wrap(const AObjectAsDuck: TObject; const AOwnsObje
var var
List: IMVCList; List: IMVCList;
begin begin
if AObjectAsDuck is TDuckTypedList then
Exit(AObjectAsDuck as TDuckTypedList);
Result := nil; Result := nil;
List := TDuckTypedList.Create(AObjectAsDuck, AOwnsObject); List := TDuckTypedList.Create(AObjectAsDuck, AOwnsObject);
if List.IsWrappedList then if List.IsWrappedList then

View File

@ -1653,6 +1653,7 @@ begin
finally finally
LSelectedController.MVCControllerBeforeDestroy; LSelectedController.MVCControllerBeforeDestroy;
end; end;
ExecuteAfterControllerActionMiddleware(LContext, LRouter.MethodToCall.Name, LHandled);
except except
on E: EMVCSessionExpiredException do on E: EMVCSessionExpiredException do
begin begin

View File

@ -173,10 +173,10 @@ begin
FRESTClient.Authentication('dmvc', '123'); FRESTClient.Authentication('dmvc', '123');
// String // String
CheckEqualsString('"Hello World called with GET"', FRESTClient.doGET.BodyAsString); CheckEqualsString('Hello World called with GET', FRESTClient.doGET.BodyAsString);
// Adapter // Adapter
CheckEqualsString('"Hello World called with GET"', FAppResource.HelloWorld); CheckEqualsString('Hello World called with GET', FAppResource.HelloWorld);
end; end;
procedure TTestRESTClient.TestInformation; procedure TTestRESTClient.TestInformation;
@ -229,7 +229,7 @@ begin
LUser.Name := 'Ezequiel'; LUser.Name := 'Ezequiel';
LUser.Pass := '123'; LUser.Pass := '123';
LResp := FRESTClient.doPOST<TAppUser>(LUser); LResp := FRESTClient.doPOST<TAppUser>(LUser);
CheckTrue(('"Sucess!"' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); CheckTrue(('Sucess!' = LResp.BodyAsString) and (LResp.ResponseCode = 200));
// Adapter // Adapter
LUser := TAppUser.Create; LUser := TAppUser.Create;
@ -261,7 +261,7 @@ begin
LUsers.Add(LUser); LUsers.Add(LUser);
end; end;
LResp := FRESTClient.doPOST<TAppUser>(LUsers); LResp := FRESTClient.doPOST<TAppUser>(LUsers);
CheckTrue(('"Sucess!"' = LResp.BodyAsString) and (LResp.ResponseCode = 200)); CheckTrue(('Sucess!' = LResp.BodyAsString) and (LResp.ResponseCode = 200));
// Adapter // Adapter
LUsers := TObjectList<TAppUser>.Create(True); LUsers := TObjectList<TAppUser>.Create(True);

View File

@ -350,14 +350,14 @@ begin
CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode);
LRes := RESTClient.doGET('/private/role1session', []); LRes := RESTClient.doGET('/private/role1session', []);
CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode);
CheckEquals('"danieleteti"', LRes.BodyAsString); CheckEquals('danieleteti', LRes.BodyAsString);
// second // second
LRes := RESTClient.doGET('/private/role1session?value=johndoe', []); LRes := RESTClient.doGET('/private/role1session?value=johndoe', []);
CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode);
LRes := RESTClient.doGET('/private/role1session', []); LRes := RESTClient.doGET('/private/role1session', []);
CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode); CheckEquals(HTTP_STATUS.OK, LRes.ResponseCode);
CheckEquals('"johndoe"', LRes.BodyAsString); CheckEquals('johndoe', LRes.BodyAsString);
end; end;
procedure TServerTest.TestCookies; procedure TServerTest.TestCookies;
@ -625,10 +625,10 @@ begin
c1.Accept(TMVCMediaType.APPLICATION_JSON); c1.Accept(TMVCMediaType.APPLICATION_JSON);
c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione
res := c1.doGET('/session', []); // rileggo il valore dalla sessione res := c1.doGET('/session', []); // rileggo il valore dalla sessione
CheckEquals('"daniele teti"', res.BodyAsString); CheckEquals('daniele teti', res.BodyAsString);
c1.SessionID := ''; c1.SessionID := '';
res := c1.doGET('/session', []); // rileggo il valore dalla sessione res := c1.doGET('/session', []); // rileggo il valore dalla sessione
CheckEquals('""', res.BodyAsString); CheckEquals('', res.BodyAsString);
finally finally
c1.Free; c1.Free;
end; end;
@ -760,7 +760,7 @@ begin
.ContentEncoding('utf-8').doPOST('/testconsumes', [], .ContentEncoding('utf-8').doPOST('/testconsumes', [],
TJSONString.Create('Hello World')); TJSONString.Create('Hello World'));
CheckEquals(HTTP_STATUS.OK, res.ResponseCode); CheckEquals(HTTP_STATUS.OK, res.ResponseCode);
CheckEquals('"Hello World"', res.BodyAsJsonValue.ToString); CheckEquals('Hello World', res.BodyAsString);
CheckEquals('application/json', res.ContentType); CheckEquals('application/json', res.ContentType);
CheckEquals('utf-8', res.ContentEncoding); CheckEquals('utf-8', res.ContentEncoding);
end; end;
@ -885,7 +885,7 @@ begin
c1.Accept(TMVCMediaType.APPLICATION_JSON); c1.Accept(TMVCMediaType.APPLICATION_JSON);
c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione c1.doPOST('/session', ['daniele teti']); // imposto un valore in sessione
res := c1.doGET('/session', []); // rileggo il valore dalla sessione res := c1.doGET('/session', []); // rileggo il valore dalla sessione
CheckEquals('"daniele teti"', res.BodyAsString); CheckEquals('daniele teti', res.BodyAsString);
c1.Accept(TMVCMediaType.TEXT_PLAIN); c1.Accept(TMVCMediaType.TEXT_PLAIN);
res := c1.doGET('/session', []); res := c1.doGET('/session', []);
// rileggo il valore dalla sessione // rileggo il valore dalla sessione

View File

@ -95,7 +95,7 @@ begin
try try
LClient.UserName := 'dmvc'; LClient.UserName := 'dmvc';
LClient.Password := '123'; LClient.Password := '123';
CheckEqualsString('"Hello World called with GET"', LClient.doGET('/hello', []).BodyAsString); CheckEqualsString('Hello World called with GET', LClient.doGET('/hello', []).BodyAsString);
finally finally
FreeAndNil(LClient); FreeAndNil(LClient);
end; end;