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

View File

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

View File

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

View File

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

View File

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

View File

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