parent
f0aed6f1e4
commit
2395700495
|
@ -34,6 +34,6 @@ requires
|
|||
|
||||
contains
|
||||
Dainty in '..\Source\Dainty.pas',
|
||||
Dainty.ValueSetter.Default in '..\Source\Dainty.ValueSetter.Default.pas';
|
||||
Dainty.Converter.Default in '..\Source\Dainty.Converter.Default.pas';
|
||||
|
||||
end.
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<DCCReference Include="rtl.dcp"/>
|
||||
<DCCReference Include="dbrtl.dcp"/>
|
||||
<DCCReference Include="..\Source\Dainty.pas"/>
|
||||
<DCCReference Include="..\Source\Dainty.ValueSetter.Default.pas"/>
|
||||
<DCCReference Include="..\Source\Dainty.Converter.Default.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
{
|
||||
Dainty
|
||||
Simple object mapper for Delphi
|
||||
|
||||
Copyright (c) 2020 M. van Renswoude
|
||||
https://github.com/MvRens/Dainty
|
||||
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
}
|
||||
unit Dainty.Converter.Default;
|
||||
|
||||
interface
|
||||
implementation
|
||||
uses
|
||||
Data.DB,
|
||||
System.Rtti,
|
||||
System.TypInfo,
|
||||
|
||||
Dainty;
|
||||
|
||||
|
||||
type
|
||||
TDaintyDefaultConverterFactory = class(TDaintyRttiConverterFactory)
|
||||
public
|
||||
class function Construct(AMember: TDaintyRttiMember; out AConverter: TDaintyConverter): Boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
{ TDaintyDefaultConverterFactory }
|
||||
class function TDaintyDefaultConverterFactory.Construct(AMember: TDaintyRttiMember; out AConverter: TDaintyConverter): Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
|
||||
case AMember.RttiType.TypeKind of
|
||||
tkString,
|
||||
tkLString,
|
||||
tkWString,
|
||||
tkUString,
|
||||
tkChar,
|
||||
tkWChar:
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsString);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsString := AMember.GetValue(AInstance).AsString;
|
||||
end;
|
||||
end;
|
||||
|
||||
tkInteger:
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsInteger);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsInteger := AMember.GetValue(AInstance).AsInteger;
|
||||
end;
|
||||
end;
|
||||
|
||||
tkEnumeration:
|
||||
if AMember.RttiType.Handle = TypeInfo(Boolean) then
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsBoolean);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsBoolean := AMember.GetValue(AInstance).AsBoolean;
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsInteger);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsInteger := AMember.GetValue(AInstance).AsInteger;
|
||||
end;
|
||||
end;
|
||||
|
||||
tkInt64:
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsLargeInt);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsLargeInt := AMember.GetValue(AInstance).AsInt64;
|
||||
end;
|
||||
end;
|
||||
|
||||
tkFloat:
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsFloat);
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.AsFloat := AMember.GetValue(AInstance).AsExtended;
|
||||
end;
|
||||
end;
|
||||
|
||||
tkVariant:
|
||||
begin
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, TValue.FromVariant(AField.Value));
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
begin
|
||||
AParam.Value := AMember.GetValue(AInstance).AsVariant;
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
TDaintyRttiMapperFactory.RegisterConverterFactory(TDaintyDefaultConverterFactory);
|
||||
|
||||
end.
|
|
@ -1,118 +0,0 @@
|
|||
{
|
||||
Dainty
|
||||
Simple object mapper for Delphi
|
||||
|
||||
Copyright (c) 2020 M. van Renswoude
|
||||
https://github.com/MvRens/Dainty
|
||||
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
}
|
||||
unit Dainty.ValueSetter.Default;
|
||||
|
||||
interface
|
||||
implementation
|
||||
uses
|
||||
Data.DB,
|
||||
System.Rtti,
|
||||
System.TypInfo,
|
||||
|
||||
Dainty;
|
||||
|
||||
|
||||
type
|
||||
TDaintyDefaultValueSetterFactory = class(TDaintyAbstractValueSetterFactory)
|
||||
public
|
||||
class function Construct(AMember: TDaintyRttiMember): TDaintyValueSetter; override;
|
||||
end;
|
||||
|
||||
|
||||
{ TDaintyDefaultValueSetterFactory }
|
||||
class function TDaintyDefaultValueSetterFactory.Construct(AMember: TDaintyRttiMember): TDaintyValueSetter;
|
||||
begin
|
||||
Result := nil;
|
||||
|
||||
case AMember.RttiType.TypeKind of
|
||||
tkString,
|
||||
tkLString,
|
||||
tkWString,
|
||||
tkUString,
|
||||
tkChar,
|
||||
tkWChar:
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsString);
|
||||
end;
|
||||
|
||||
tkInteger:
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsInteger);
|
||||
end;
|
||||
|
||||
tkEnumeration:
|
||||
if AMember.RttiType.Handle = TypeInfo(Boolean) then
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsBoolean);
|
||||
end
|
||||
else
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsInteger);
|
||||
end;
|
||||
|
||||
tkInt64:
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsLargeInt);
|
||||
end;
|
||||
|
||||
tkFloat:
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, AField.AsFloat);
|
||||
end;
|
||||
|
||||
tkVariant:
|
||||
Result :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
begin
|
||||
AMember.SetValue(AInstance, TValue.FromVariant(AField.Value));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
TDaintyRttiMapperFactory.RegisterValueSetterFactory(TDaintyDefaultValueSetterFactory);
|
||||
|
||||
end.
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
unit DaintyValueSetterTests;
|
||||
unit DaintyConverterTests;
|
||||
|
||||
interface
|
||||
uses
|
||||
|
@ -11,7 +11,7 @@ uses
|
|||
|
||||
|
||||
type
|
||||
TDaintyValueSetterTest = class(TTestCase)
|
||||
TDaintyConverterTest = class(TTestCase)
|
||||
private
|
||||
FDataSet: TClientDataSet;
|
||||
protected
|
||||
|
@ -33,8 +33,8 @@ uses
|
|||
System.Variants;
|
||||
|
||||
|
||||
{ TDaintyValueSetterTest }
|
||||
procedure TDaintyValueSetterTest.SetUp;
|
||||
{ TDaintyConverterTest }
|
||||
procedure TDaintyConverterTest.SetUp;
|
||||
begin
|
||||
inherited SetUp;
|
||||
|
||||
|
@ -42,7 +42,7 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyValueSetterTest.TearDown;
|
||||
procedure TDaintyConverterTest.TearDown;
|
||||
begin
|
||||
FreeAndNil(FDataSet);
|
||||
|
||||
|
@ -71,21 +71,24 @@ type
|
|||
end;
|
||||
|
||||
|
||||
TCustomRecordValueSetterFactory = class(TDaintyAbstractValueSetterFactory)
|
||||
TCustomRecordValueSetterFactory = class(TDaintyRttiConverterFactory)
|
||||
public
|
||||
class function Construct(AMember: TDaintyRttiMember): TDaintyValueSetter; override;
|
||||
class function Construct(AMember: TDaintyRttiMember; out AConverter: TDaintyConverter): Boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
{ TCustomRecordValueSetterFactory }
|
||||
class function TCustomRecordValueSetterFactory.Construct(AMember: TDaintyRttiMember): TDaintyValueSetter;
|
||||
class function TCustomRecordValueSetterFactory.Construct(AMember: TDaintyRttiMember; out AConverter: TDaintyConverter): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
if AMember.RttiType.TypeKind <> tkRecord then
|
||||
Exit(nil);
|
||||
Exit;
|
||||
|
||||
if AMember.RttiType.Handle = TypeInfo(TCustomRecord) then
|
||||
begin
|
||||
Result :=
|
||||
Result := True;
|
||||
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
var
|
||||
customRecord: TCustomRecord;
|
||||
|
@ -95,12 +98,24 @@ begin
|
|||
AMember.SetValue(AInstance, TValue.From(customRecord));
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
var
|
||||
customRecord: TCustomRecord;
|
||||
|
||||
begin
|
||||
customRecord := AMember.GetValue(AInstance).AsType<TCustomRecord>;
|
||||
AParam.AsString := customRecord.Value;
|
||||
end;
|
||||
|
||||
{ Unfortunately I have not found a way to make this generic, if you do let me know!
|
||||
The workaround is to handle all types you want to support explicitly, which is
|
||||
good enough for our use case with nullable implementations. }
|
||||
end else if AMember.RttiType.Handle = TypeInfo(TGenericCustomRecord<string>) then
|
||||
begin
|
||||
Result :=
|
||||
Result := True;
|
||||
|
||||
AConverter.FieldReader :=
|
||||
procedure(AInstance: TObject; AField: TField)
|
||||
var
|
||||
value: TGenericCustomRecord<string>;
|
||||
|
@ -109,11 +124,21 @@ begin
|
|||
value.Value := AField.AsString;
|
||||
AMember.SetValue(AInstance, TValue.From(value));
|
||||
end;
|
||||
|
||||
AConverter.ParamWriter :=
|
||||
procedure(AInstance: TObject; AParam: TParam)
|
||||
var
|
||||
value: TGenericCustomRecord<string>;
|
||||
|
||||
begin
|
||||
value := AMember.GetValue(AInstance).AsType<TGenericCustomRecord<string>>;
|
||||
AParam.AsString := value.Value;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyValueSetterTest.CustomRecordMapping;
|
||||
procedure TDaintyConverterTest.CustomRecordMapping;
|
||||
var
|
||||
row: TCustomRecordRow;
|
||||
|
||||
|
@ -127,19 +152,22 @@ begin
|
|||
DataSet.Post;
|
||||
|
||||
|
||||
TDaintyRttiMapperFactory.RegisterValueSetterFactory(TCustomRecordValueSetterFactory, 1);
|
||||
TDaintyRttiMapperFactory.RegisterConverterFactory(TCustomRecordValueSetterFactory, 1);
|
||||
try
|
||||
DataSet.First;
|
||||
row := DataSet.GetFirst<TCustomRecordRow>;
|
||||
|
||||
CheckEquals('Hello world!', row.StringField.Value);
|
||||
try
|
||||
CheckEquals('Hello world!', row.StringField.Value);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
finally
|
||||
TDaintyRttiMapperFactory.UnregisterValueSetterFactory(TCustomRecordValueSetterFactory);
|
||||
TDaintyRttiMapperFactory.UnregisterConverterFactory(TCustomRecordValueSetterFactory);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyValueSetterTest.GenericCustomRecordMapping;
|
||||
procedure TDaintyConverterTest.GenericCustomRecordMapping;
|
||||
var
|
||||
row: TGenericCustomRecordRow;
|
||||
|
||||
|
@ -153,19 +181,22 @@ begin
|
|||
DataSet.Post;
|
||||
|
||||
|
||||
TDaintyRttiMapperFactory.RegisterValueSetterFactory(TCustomRecordValueSetterFactory, 1);
|
||||
TDaintyRttiMapperFactory.RegisterConverterFactory(TCustomRecordValueSetterFactory, 1);
|
||||
try
|
||||
DataSet.First;
|
||||
row := DataSet.GetFirst<TGenericCustomRecordRow>;
|
||||
|
||||
CheckEquals('Hello world!', row.StringField.Value);
|
||||
try
|
||||
CheckEquals('Hello world!', row.StringField.Value);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
finally
|
||||
TDaintyRttiMapperFactory.UnregisterValueSetterFactory(TCustomRecordValueSetterFactory);
|
||||
TDaintyRttiMapperFactory.UnregisterConverterFactory(TCustomRecordValueSetterFactory);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
RegisterTest(TDaintyValueSetterTest.Suite);
|
||||
RegisterTest(TDaintyConverterTest.Suite);
|
||||
|
||||
end.
|
|
@ -1,4 +1,4 @@
|
|||
unit DaintyTests;
|
||||
unit DaintyFieldsTests;
|
||||
|
||||
interface
|
||||
uses
|
||||
|
@ -11,7 +11,7 @@ uses
|
|||
|
||||
|
||||
type
|
||||
TDaintyTest = class(TTestCase)
|
||||
TDaintyFieldsTest = class(TTestCase)
|
||||
private
|
||||
FDataSet: TClientDataSet;
|
||||
protected
|
||||
|
@ -45,8 +45,8 @@ uses
|
|||
System.SysUtils;
|
||||
|
||||
|
||||
{ TDaintyTest }
|
||||
procedure TDaintyTest.SetUp;
|
||||
{ TDaintyFieldsTest }
|
||||
procedure TDaintyFieldsTest.SetUp;
|
||||
begin
|
||||
inherited SetUp;
|
||||
|
||||
|
@ -54,7 +54,7 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.TearDown;
|
||||
procedure TDaintyFieldsTest.TearDown;
|
||||
begin
|
||||
FreeAndNil(FDataSet);
|
||||
|
||||
|
@ -73,7 +73,7 @@ type
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.SimpleTypes;
|
||||
procedure TDaintyFieldsTest.SimpleTypes;
|
||||
|
||||
procedure AddRow(const AStringValue: string; AIntegerValue: Integer; ADateTimeValue: TDateTime; ABooleanValue: Boolean; AFloatValue: Double);
|
||||
begin
|
||||
|
@ -140,7 +140,7 @@ type
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.FillTestData(ARowCount: Integer);
|
||||
procedure TDaintyFieldsTest.FillTestData(ARowCount: Integer);
|
||||
var
|
||||
rowNumber: Integer;
|
||||
|
||||
|
@ -160,31 +160,37 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetFirst;
|
||||
procedure TDaintyFieldsTest.GetFirst;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(1);
|
||||
row := DataSet.GetFirst<TTestRow>;
|
||||
|
||||
CheckEquals(1, row.RowNumber);
|
||||
try
|
||||
CheckEquals(1, row.RowNumber);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetFirstMultipleRows;
|
||||
procedure TDaintyFieldsTest.GetFirstMultipleRows;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(2);
|
||||
row := DataSet.GetFirst<TTestRow>;
|
||||
|
||||
CheckEquals(1, row.RowNumber);
|
||||
try
|
||||
CheckEquals(1, row.RowNumber);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetFirstNoData;
|
||||
procedure TDaintyFieldsTest.GetFirstNoData;
|
||||
begin
|
||||
FillTestData(0);
|
||||
ExpectedException := EDatabaseError;
|
||||
|
@ -192,29 +198,33 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetFirstOrDefault;
|
||||
procedure TDaintyFieldsTest.GetFirstOrDefault;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(0);
|
||||
row := DataSet.GetFirstOrDefault<TTestRow>(nil);
|
||||
row := DataSet.GetFirstOrDefault<TTestRow>;
|
||||
CheckNull(row);
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetSingle;
|
||||
procedure TDaintyFieldsTest.GetSingle;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(1);
|
||||
row := DataSet.GetSingle<TTestRow>;
|
||||
CheckEquals(1, row.RowNumber);
|
||||
try
|
||||
CheckEquals(1, row.RowNumber);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetSingleMultipleRows;
|
||||
procedure TDaintyFieldsTest.GetSingleMultipleRows;
|
||||
begin
|
||||
ExpectedException := EDatabaseError;
|
||||
FillTestData(2);
|
||||
|
@ -222,7 +232,7 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetSingleNoData;
|
||||
procedure TDaintyFieldsTest.GetSingleNoData;
|
||||
begin
|
||||
ExpectedException := EDatabaseError;
|
||||
FillTestData(0);
|
||||
|
@ -230,24 +240,28 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetSingleOrDefaultMultipleRows;
|
||||
procedure TDaintyFieldsTest.GetSingleOrDefaultMultipleRows;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(2);
|
||||
row := DataSet.GetSingleOrDefault<TTestRow>(nil);
|
||||
CheckNull(row);
|
||||
row := DataSet.GetSingleOrDefault<TTestRow>;
|
||||
try
|
||||
CheckNull(row);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.GetSingleOrDefaultNoData;
|
||||
procedure TDaintyFieldsTest.GetSingleOrDefaultNoData;
|
||||
var
|
||||
row: TTestRow;
|
||||
|
||||
begin
|
||||
FillTestData(0);
|
||||
row := DataSet.GetSingleOrDefault<TTestRow>(nil);
|
||||
row := DataSet.GetSingleOrDefault<TTestRow>;
|
||||
CheckNull(row);
|
||||
end;
|
||||
|
||||
|
@ -260,7 +274,7 @@ type
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.FieldNameAttribute;
|
||||
procedure TDaintyFieldsTest.FieldNameAttribute;
|
||||
var
|
||||
row: TAttributeTestRow;
|
||||
|
||||
|
@ -274,7 +288,11 @@ begin
|
|||
DataSet.Post;
|
||||
|
||||
row := DataSet.GetFirst<TAttributeTestRow>;
|
||||
CheckEquals('Hello world!', row.StringField);
|
||||
try
|
||||
CheckEquals('Hello world!', row.StringField);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -289,7 +307,7 @@ type
|
|||
end;
|
||||
|
||||
|
||||
procedure TDaintyTest.FieldNameAttributeProperty;
|
||||
procedure TDaintyFieldsTest.FieldNameAttributeProperty;
|
||||
var
|
||||
row: TPropertyAttributeTestRow;
|
||||
|
||||
|
@ -303,14 +321,18 @@ begin
|
|||
DataSet.Post;
|
||||
|
||||
row := DataSet.GetFirst<TPropertyAttributeTestRow>;
|
||||
CheckEquals('Hello world!', row.StringField);
|
||||
try
|
||||
CheckEquals('Hello world!', row.StringField);
|
||||
finally
|
||||
FreeAndNil(row);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
initialization
|
||||
RegisterTest(TDaintyTest.Suite);
|
||||
RegisterTest(TDaintyFieldsTest.Suite);
|
||||
|
||||
end.
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
unit DaintyParamsTests;
|
||||
|
||||
interface
|
||||
uses
|
||||
Data.DB,
|
||||
TestFramework,
|
||||
|
||||
Dainty;
|
||||
|
||||
|
||||
type
|
||||
TDaintyParamsTest = class(TTestCase)
|
||||
private
|
||||
FParams: TParams;
|
||||
protected
|
||||
procedure SetUp; override;
|
||||
procedure TearDown; override;
|
||||
|
||||
property Params: TParams read FParams;
|
||||
published
|
||||
procedure SimpleTypes;
|
||||
|
||||
// #ToDo1 -oMvR: 10-9-2020: tests for various matching types
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
uses
|
||||
System.SysUtils;
|
||||
|
||||
|
||||
{ TDaintyParamsTest }
|
||||
procedure TDaintyParamsTest.SetUp;
|
||||
begin
|
||||
inherited SetUp;
|
||||
|
||||
FParams := TParams.Create();
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyParamsTest.TearDown;
|
||||
begin
|
||||
FreeAndNil(FParams);
|
||||
|
||||
inherited TearDown;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
type
|
||||
TSimpleTypesParams = class
|
||||
StringParam: string;
|
||||
IntegerParam: Integer;
|
||||
DateTimeParam: TDateTime;
|
||||
BooleanParam: Boolean;
|
||||
FloatParam: Double;
|
||||
end;
|
||||
|
||||
|
||||
procedure TDaintyParamsTest.SimpleTypes;
|
||||
var
|
||||
simpleTypesParams: TSimpleTypesParams;
|
||||
|
||||
begin
|
||||
Params.AddParameter.Name := 'STRINGPARAM';
|
||||
Params.AddParameter.Name := 'INTEGERPARAM';
|
||||
Params.AddParameter.Name := 'DATETIMEPARAM';
|
||||
Params.AddParameter.Name := 'BOOLEANPARAM';
|
||||
Params.AddParameter.Name := 'FLOATPARAM';
|
||||
|
||||
simpleTypesParams := TSimpleTypesParams.Create;
|
||||
try
|
||||
simpleTypesParams.StringParam := 'Hello world!';
|
||||
simpleTypesParams.IntegerParam := 42;
|
||||
simpleTypesParams.DateTimeParam := EncodeDate(2020, 9, 7);
|
||||
simpleTypesParams.BooleanParam := True;
|
||||
simpleTypesParams.FloatParam := 3.1415;
|
||||
|
||||
Params.Apply(simpleTypesParams);
|
||||
|
||||
CheckEquals('Hello world!', Params.ParamByName('STRINGPARAM').AsString, 'StringParam');
|
||||
CheckEquals(42, Params.ParamByName('INTEGERPARAM').AsInteger, 'IntegerParam');
|
||||
CheckEquals(EncodeDate(2020, 9, 7), Params.ParamByName('DATETIMEPARAM').AsDate, 0.9, 'DateTimeParam');
|
||||
CheckEquals(True, Params.ParamByName('BOOLEANPARAM').AsBoolean, 'BooleanParam');
|
||||
CheckEquals(3.1415, Params.ParamByName('FLOATPARAM').AsFloat, 0.0001, 'FloatParam');
|
||||
finally
|
||||
FreeAndNil(simpleTypesParams);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
RegisterTest(TDaintyParamsTest.Suite);
|
||||
|
||||
end.
|
||||
|
|
@ -5,10 +5,12 @@ program DaintyUnitTests;
|
|||
uses
|
||||
GUITestRunner,
|
||||
Dainty in '..\Source\Dainty.pas',
|
||||
DaintyTests in 'DaintyTests.pas',
|
||||
Dainty.ValueSetter.Default in '..\Source\Dainty.ValueSetter.Default.pas',
|
||||
DaintyValueSetterTests in 'DaintyValueSetterTests.pas';
|
||||
DaintyFieldsTests in 'DaintyFieldsTests.pas',
|
||||
Dainty.Converter.Default in '..\Source\Dainty.Converter.Default.pas',
|
||||
DaintyConverterTests in 'DaintyConverterTests.pas',
|
||||
DaintyParamsTests in 'DaintyParamsTests.pas';
|
||||
|
||||
begin
|
||||
ReportMemoryLeaksOnShutdown := True;
|
||||
RunRegisteredTests;
|
||||
end.
|
||||
|
|
|
@ -40,6 +40,9 @@
|
|||
<Base>true</Base>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Base)'!=''">
|
||||
<Manifest_File>None</Manifest_File>
|
||||
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
|
||||
<VerInfo_Locale>1043</VerInfo_Locale>
|
||||
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
|
||||
<DCC_UsePackage>DBXInterBaseDriver;DataSnapServer;DataSnapCommon;DbxCommonDriver;dbxcds;CustomIPTransport;dsnap;IndyCore;FmxTeeUI;IPIndyImpl;bindcompfmx;dbrtl;bindcomp;inetdb;xmlrtl;ibxpress;soaprtl;FMXTee;bindengine;DBXInformixDriver;DBXFirebirdDriver;inet;DBXSybaseASADriver;dbexpress;fmx;IndySystem;DataSnapClient;DataSnapProviderClient;DBXOracleDriver;inetdbxpress;rtl;DbxClientDriver;IndyProtocols;DBXMySQLDriver;DataSnapIndy10ServerTransport;$(DCC_UsePackage)</DCC_UsePackage>
|
||||
<DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
|
||||
|
@ -62,8 +65,6 @@
|
|||
<DCC_RemoteDebug>true</DCC_RemoteDebug>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
|
||||
<DCC_DebugDCUs>true</DCC_DebugDCUs>
|
||||
<Manifest_File>None</Manifest_File>
|
||||
<VerInfo_Locale>1033</VerInfo_Locale>
|
||||
<DCC_RemoteDebug>false</DCC_RemoteDebug>
|
||||
</PropertyGroup>
|
||||
|
@ -78,9 +79,10 @@
|
|||
<MainSource>MainSource</MainSource>
|
||||
</DelphiCompile>
|
||||
<DCCReference Include="..\Source\Dainty.pas"/>
|
||||
<DCCReference Include="DaintyTests.pas"/>
|
||||
<DCCReference Include="..\Source\Dainty.ValueSetter.Default.pas"/>
|
||||
<DCCReference Include="DaintyValueSetterTests.pas"/>
|
||||
<DCCReference Include="DaintyFieldsTests.pas"/>
|
||||
<DCCReference Include="..\Source\Dainty.Converter.Default.pas"/>
|
||||
<DCCReference Include="DaintyConverterTests.pas"/>
|
||||
<DCCReference Include="DaintyParamsTests.pas"/>
|
||||
<BuildConfiguration Include="Release">
|
||||
<Key>Cfg_2</Key>
|
||||
<CfgParent>Base</CfgParent>
|
||||
|
|
Loading…
Reference in New Issue