Skip to content

Commit

Permalink
New tests for IgnoreMembers config
Browse files Browse the repository at this point in the history
  • Loading branch information
paolo-rossi committed May 1, 2024
1 parent 5b723d0 commit 6ec48ef
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Tests/Neon.Tests.Framework.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ uses
Neon.Tests.Config.EnumAsInt in 'Source\Neon.Tests.Config.EnumAsInt.pas',
Neon.Tests.Config.AutoCreate in 'Source\Neon.Tests.Config.AutoCreate.pas',
Neon.Tests.Attributes.Factory in 'Source\Neon.Tests.Attributes.Factory.pas',
Neon.Tests.CustomSerializers in 'Source\Neon.Tests.CustomSerializers.pas';
Neon.Tests.CustomSerializers in 'Source\Neon.Tests.CustomSerializers.pas',
Neon.Tests.Config.IgnoreMembers in 'Source\Neon.Tests.Config.IgnoreMembers.pas';

var
LRunner : ITestRunner;
Expand Down
1 change: 1 addition & 0 deletions Tests/Neon.Tests.Framework.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<DCCReference Include="Source\Neon.Tests.Config.AutoCreate.pas"/>
<DCCReference Include="Source\Neon.Tests.Attributes.Factory.pas"/>
<DCCReference Include="Source\Neon.Tests.CustomSerializers.pas"/>
<DCCReference Include="Source\Neon.Tests.Config.IgnoreMembers.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
126 changes: 126 additions & 0 deletions Tests/Source/Neon.Tests.Config.IgnoreMembers.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{******************************************************************************}
{ }
{ Neon: Serialization Library for Delphi }
{ Copyright (c) 2018 Paolo Rossi }
{ https://github.com/paolo-rossi/neon-library }
{ }
{******************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (the "License"); }
{ you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ }
{ http://www.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{******************************************************************************}
unit Neon.Tests.Config.IgnoreMembers;

interface

uses
System.SysUtils, System.Rtti, DUnitX.TestFramework,
{$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF}

Neon.Core.Persistence,
Neon.Tests.Entities,
Neon.Tests.Utils;

type
TTestClass = class
private
FCity: string;
FCountry: string;
FName: string;
FYear: Integer;
FAddress: string;
public
property Name: string read FName write FName;
property Address: string read FAddress write FAddress;
property City: string read FCity write FCity;
property Country: string read FCountry write FCountry;
property Year: Integer read FYear write FYear;
end;



[TestFixture]
[Category('ignoremembers')]
TTestIgnoreMembers = class(TObject)
private
FDataPath: string;
FObj: TTestClass;
public
constructor Create;
destructor Destroy; override;

[Setup]
procedure Setup;
[TearDown]
procedure TearDown;

[Test]
[TestCase('TestIgnoreAll', 'Name,Address,City,Country,Year|{}', '|')]
[TestCase('TestIgnoreButYear', 'Name,Address,City,Country|{"Year":1969}', '|')]
[TestCase('TestIgnoreButName', 'Address,City,Country,Year|{"Name":"Paolo"}', '|')]
[TestCase('TestIgnoreSome', 'Address,Year|{"Name":"Paolo","City":"Piacenza","Country":"Italy"}', '|')]
procedure TestIgnore(const AMemberList, _Result: string);
end;

implementation

uses
System.IOUtils, System.DateUtils;

constructor TTestIgnoreMembers.Create;
begin
FDataPath := TDirectory.GetCurrentDirectory;
FDataPath := TDirectory.GetParent(FDataPath);
FDataPath := TPath.Combine(FDataPath, 'Data');

FObj := TTestClass.Create;
FObj.Name := 'Paolo';
FObj.City := 'Piacenza';
FObj.Country := 'Italy';
FObj.Year := 1969;
end;

destructor TTestIgnoreMembers.Destroy;
begin
FObj.Free;

inherited;
end;

procedure TTestIgnoreMembers.Setup;
begin
end;

procedure TTestIgnoreMembers.TearDown;
begin
end;

procedure TTestIgnoreMembers.TestIgnore(const AMemberList, _Result: string);
var
LIgnoreList: TArray<string>;
LConfig: INeonConfiguration;
begin
LIgnoreList := AMemberList.Split([',']);

LConfig := TNeonConfiguration.Default;
LConfig.SetIgnoreMembers(LIgnoreList);

Assert.AreEqual(TTestUtils.SerializeObject(FObj, LConfig), _Result);
end;

initialization
TDUnitX.RegisterTestFixture(TTestIgnoreMembers);

end.

0 comments on commit 6ec48ef

Please sign in to comment.