2013-11-19 18:17:06 +01:00
|
|
|
|
unit BOs;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2014-05-22 23:37:13 +02:00
|
|
|
|
FrameworkTestsU, system.TimeSpan, system.SysUtils, generics.collections,
|
|
|
|
|
ObjectsMappers;
|
2013-11-19 18:17:06 +01:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TMyObject = class
|
|
|
|
|
private
|
|
|
|
|
FPropString: string;
|
|
|
|
|
FPropAnsiString: AnsiString;
|
|
|
|
|
FPropInt64: Int64;
|
|
|
|
|
FPropUInt32: cardinal;
|
|
|
|
|
FPropUInt64: UInt64;
|
|
|
|
|
FPropUInt16: word;
|
|
|
|
|
FPropInt16: smallint;
|
|
|
|
|
FPropBoolean: boolean;
|
|
|
|
|
FPropDateTime: TDateTime;
|
|
|
|
|
FPropDate: TDate;
|
|
|
|
|
FPropInteger: Integer;
|
|
|
|
|
FPropTimeStamp: TTimeStamp;
|
|
|
|
|
FPropTime: TTime;
|
2014-05-30 11:29:58 +02:00
|
|
|
|
FPropCurrency: Currency;
|
2013-11-19 18:17:06 +01:00
|
|
|
|
procedure SetPropAnsiString(const Value: AnsiString);
|
|
|
|
|
procedure SetPropString(const Value: string);
|
|
|
|
|
procedure SetPropInt64(const Value: Int64);
|
|
|
|
|
procedure SetPropUInt32(const Value: cardinal);
|
|
|
|
|
procedure SetPropUInt64(const Value: UInt64);
|
|
|
|
|
procedure SetPropInt16(const Value: smallint);
|
|
|
|
|
procedure SetPropUInt16(const Value: word);
|
|
|
|
|
procedure SetPropBoolean(const Value: boolean);
|
|
|
|
|
procedure SetPropDate(const Value: TDate);
|
|
|
|
|
procedure SetPropDateTime(const Value: TDateTime);
|
|
|
|
|
procedure SetPropInteger(const Value: Integer);
|
|
|
|
|
procedure SetPropTimeStamp(const Value: TTimeStamp);
|
|
|
|
|
procedure SetPropTime(const Value: TTime);
|
2014-05-30 11:29:58 +02:00
|
|
|
|
procedure SetPropCurrency(const Value: Currency);
|
2013-11-19 18:17:06 +01:00
|
|
|
|
public
|
|
|
|
|
function Equals(Obj: TMyObject): boolean;
|
|
|
|
|
property PropString: string read FPropString write SetPropString;
|
|
|
|
|
property PropAnsiString: AnsiString read FPropAnsiString write SetPropAnsiString;
|
|
|
|
|
property PropInteger: Integer read FPropInteger write SetPropInteger;
|
|
|
|
|
property PropUInt32: cardinal read FPropUInt32 write SetPropUInt32;
|
|
|
|
|
property PropInt64: Int64 read FPropInt64 write SetPropInt64;
|
|
|
|
|
property PropUInt64: UInt64 read FPropUInt64 write SetPropUInt64;
|
|
|
|
|
property PropUInt16: word read FPropUInt16 write SetPropUInt16;
|
|
|
|
|
property PropInt16: smallint read FPropInt16 write SetPropInt16;
|
|
|
|
|
property PropBoolean: boolean read FPropBoolean write SetPropBoolean;
|
|
|
|
|
property PropDate: TDate read FPropDate write SetPropDate;
|
|
|
|
|
property PropTime: TTime read FPropTime write SetPropTime;
|
|
|
|
|
property PropDateTime: TDateTime read FPropDateTime write SetPropDateTime;
|
|
|
|
|
property PropTimeStamp: TTimeStamp read FPropTimeStamp write SetPropTimeStamp;
|
2014-05-30 11:29:58 +02:00
|
|
|
|
property PropCurrency: Currency read FPropCurrency write SetPropCurrency;
|
2013-11-19 18:17:06 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-22 23:37:13 +02:00
|
|
|
|
TMyChildObject = class
|
|
|
|
|
private
|
|
|
|
|
FMyChildProperty1: string;
|
|
|
|
|
procedure SetMyChildProperty1(const Value: string);
|
|
|
|
|
public
|
|
|
|
|
property MyChildProperty1: string read FMyChildProperty1 write SetMyChildProperty1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MapperListOf(TMyChildObject)]
|
|
|
|
|
TMyChildObjectList = class(TObjectList<TMyChildObject>)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyComplexObject = class
|
|
|
|
|
private
|
|
|
|
|
FProp1: string;
|
|
|
|
|
FChildObjectList: TMyChildObjectList;
|
|
|
|
|
FChildObject: TMyChildObject;
|
|
|
|
|
procedure SetChildObject(const Value: TMyChildObject);
|
|
|
|
|
procedure SetChildObjectList(const Value: TMyChildObjectList);
|
|
|
|
|
procedure SetProp1(const Value: string);
|
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function Equals(Obj: TObject): boolean; override;
|
|
|
|
|
|
|
|
|
|
property Prop1: string read FProp1 write SetProp1;
|
|
|
|
|
property ChildObject: TMyChildObject read FChildObject write SetChildObject;
|
|
|
|
|
property ChildObjectList: TMyChildObjectList read FChildObjectList write SetChildObjectList;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-11-19 18:17:06 +01:00
|
|
|
|
function GetMyObject: TMyObject;
|
2014-05-22 23:37:13 +02:00
|
|
|
|
function GetMyComplexObject: TMyComplexObject;
|
2013-11-19 18:17:06 +01:00
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
system.DateUtils;
|
|
|
|
|
|
2014-05-22 23:37:13 +02:00
|
|
|
|
function GetMyComplexObject: TMyComplexObject;
|
|
|
|
|
var
|
|
|
|
|
co: TMyChildObject;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyComplexObject.Create;
|
|
|
|
|
Result.Prop1 := 'property1';
|
|
|
|
|
Result.ChildObject.MyChildProperty1 := 'MySingleChildProperty1';
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty1';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty2';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty3';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty4';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
end;
|
|
|
|
|
|
2013-11-19 18:17:06 +01:00
|
|
|
|
function GetMyObject: TMyObject;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyObject.Create;
|
|
|
|
|
Result.PropString := 'Some text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
|
|
|
|
Result.PropAnsiString := 'This is an ANSI text';
|
|
|
|
|
Result.PropInteger := -1234;
|
|
|
|
|
Result.PropUInt32 := 1234;
|
|
|
|
|
Result.PropInt64 := -1234567890;
|
|
|
|
|
Result.PropUInt64 := 1234567890;
|
|
|
|
|
Result.PropUInt16 := 12345;
|
|
|
|
|
Result.PropInt16 := -12345;
|
2014-05-30 11:29:58 +02:00
|
|
|
|
Result.PropCurrency := 1234.5678;
|
2013-11-19 18:17:06 +01:00
|
|
|
|
Result.PropBoolean := true;
|
|
|
|
|
Result.PropDate := EncodeDate(2010, 10, 20);
|
|
|
|
|
Result.PropTime := EncodeTime(10, 20, 30, 40);
|
|
|
|
|
Result.PropDateTime := Result.PropDate + Result.PropTime;
|
|
|
|
|
Result.PropTimeStamp := DateTimeToTimeStamp(Result.PropDateTime + 1);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMyObject.Equals(Obj: TMyObject): boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := true;
|
|
|
|
|
Result := Result and (Self.PropString = Obj.PropString);
|
|
|
|
|
Result := Result and (Self.PropAnsiString = Obj.PropAnsiString);
|
|
|
|
|
Result := Result and (Self.PropInteger = Obj.PropInteger);
|
|
|
|
|
Result := Result and (Self.PropUInt32 = Obj.PropUInt32);
|
|
|
|
|
Result := Result and (Self.PropInt64 = Obj.PropInt64);
|
|
|
|
|
Result := Result and (Self.PropUInt64 = Obj.PropUInt64);
|
|
|
|
|
Result := Result and (Self.PropUInt16 = Obj.PropUInt16);
|
|
|
|
|
Result := Result and (Self.PropInt16 = Obj.PropInt16);
|
|
|
|
|
Result := Result and (Self.PropBoolean = Obj.PropBoolean);
|
|
|
|
|
Result := Result and (Self.PropDate = Obj.PropDate);
|
2014-05-30 11:29:58 +02:00
|
|
|
|
Result := Result and (Self.PropCurrency = Obj.PropCurrency);
|
2013-11-19 18:17:06 +01:00
|
|
|
|
Result := Result and (SecondsBetween(Self.PropTime, Obj.PropTime) = 0);
|
|
|
|
|
Result := Result and (SecondsBetween(Self.PropDateTime, Obj.PropDateTime) = 0);
|
|
|
|
|
Result := Result and (Self.PropTimeStamp.Date = Obj.PropTimeStamp.Date) and
|
|
|
|
|
(Self.PropTimeStamp.Time = Obj.PropTimeStamp.Time);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropAnsiString(const Value: AnsiString);
|
|
|
|
|
begin
|
|
|
|
|
FPropAnsiString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropBoolean(const Value: boolean);
|
|
|
|
|
begin
|
|
|
|
|
FPropBoolean := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-30 11:29:58 +02:00
|
|
|
|
procedure TMyObject.SetPropCurrency(const Value: Currency);
|
|
|
|
|
begin
|
|
|
|
|
FPropCurrency := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-11-19 18:17:06 +01:00
|
|
|
|
procedure TMyObject.SetPropDate(const Value: TDate);
|
|
|
|
|
begin
|
|
|
|
|
FPropDate := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropDateTime(const Value: TDateTime);
|
|
|
|
|
begin
|
|
|
|
|
FPropDateTime := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInt16(const Value: smallint);
|
|
|
|
|
begin
|
|
|
|
|
FPropInt16 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInt64(const Value: Int64);
|
|
|
|
|
begin
|
|
|
|
|
FPropInt64 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInteger(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
FPropInteger := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropString(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FPropString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropTime(const Value: TTime);
|
|
|
|
|
begin
|
|
|
|
|
FPropTime := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropTimeStamp(const Value: TTimeStamp);
|
|
|
|
|
begin
|
|
|
|
|
FPropTimeStamp := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt16(const Value: word);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt16 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt32(const Value: cardinal);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt32 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt64(const Value: UInt64);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt64 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-22 23:37:13 +02:00
|
|
|
|
{ TMyComplexObject }
|
|
|
|
|
|
|
|
|
|
constructor TMyComplexObject.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FChildObjectList := TMyChildObjectList.Create(true);
|
|
|
|
|
FChildObject := TMyChildObject.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMyComplexObject.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
FChildObjectList.Free;
|
|
|
|
|
FChildObject.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMyComplexObject.Equals(Obj: TObject): boolean;
|
|
|
|
|
var
|
|
|
|
|
co: TMyComplexObject;
|
|
|
|
|
begin
|
|
|
|
|
co := Obj as TMyComplexObject;
|
|
|
|
|
|
|
|
|
|
Result := co.Prop1 = Self.Prop1;
|
|
|
|
|
Result := Result and (co.ChildObject.MyChildProperty1 = Self.ChildObject.MyChildProperty1);
|
|
|
|
|
Result := Result and (co.ChildObjectList.Count = Self.ChildObjectList.Count);
|
|
|
|
|
Result := Result and (co.ChildObjectList[0].MyChildProperty1 = Self.ChildObjectList[0].MyChildProperty1);
|
|
|
|
|
Result := Result and (co.ChildObjectList[1].MyChildProperty1 = Self.ChildObjectList[1].MyChildProperty1);
|
|
|
|
|
Result := Result and (co.ChildObjectList[2].MyChildProperty1 = Self.ChildObjectList[2].MyChildProperty1);
|
|
|
|
|
Result := Result and (co.ChildObjectList[3].MyChildProperty1 = Self.ChildObjectList[3].MyChildProperty1);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetChildObject(const Value: TMyChildObject);
|
|
|
|
|
begin
|
|
|
|
|
FChildObject := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetChildObjectList(const Value: TMyChildObjectList);
|
|
|
|
|
begin
|
|
|
|
|
FChildObjectList := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetProp1(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FProp1 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMyChildObject }
|
|
|
|
|
|
|
|
|
|
procedure TMyChildObject.SetMyChildProperty1(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FMyChildProperty1 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-11-19 18:17:06 +01:00
|
|
|
|
end.
|