Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Tests/Island.Tests.Shared.elements
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0" DefaultTargets="Build">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup Label="Globals">
<ProjectGuid>{8BC0E3A8-C6B3-4FCC-AC6B-D80EE04F2628}</ProjectGuid>
<RootNamespace>RemObjects.Elements.Island.Tests</RootNamespace>
<DefaultLanguage>Oxygene</DefaultLanguage>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>Island.Tests.Shared</RootNamespace>
</PropertyGroup>
<Import Project="Island.Tests.Shared.projitems" Label="Shared" />
Expand Down
2 changes: 2 additions & 0 deletions Tests/Island.Tests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@
<Compile Include="$(MSBuildThisFileDirectory)String_Trim.pas" />
<Compile Include="$(MSBuildThisFileDirectory)Math_Power.pas" />
<Compile Include="$(MSBuildThisFileDirectory)TextConvert_utf_tests.pas" />
<Compile Include="$(MSBuildThisFileDirectory)Ling_TestData.pas" />
<Compile Include="$(MSBuildThisFileDirectory)Ling_Tests.pas" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion Tests/Island.Tests.Windows.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# RemObjects Fire
# RemObjects Water
Project("{656346D9-4656-40DA-A068-22D5425D4639}") = "Island.Tests.Shared", "Island.Tests.Shared.elements", "{8BC0E3A8-C6B3-4FCC-AC6B-D80EE04F2628}"
EndProject
Project("{656346D9-4656-40DA-A068-22D5425D4639}") = "Island.Tests.Windows", "Island.Tests.Windows.elements", "{768B2414-B89A-492C-B5A9-2115A89B557C}"
EndProject
Global
Expand Down
75 changes: 75 additions & 0 deletions Tests/Ling_TestData.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace RemObjects.Elements.Island.Tests;
type
TUser = public class
public
property ID : Integer;
property Name : String;
property Age : Integer;
property HomeCountry : String;
property Company : Integer;

constructor (aID : Integer; aName : String; aAge : Integer; aHomeCountry : String; aCompany : Integer);
begin
ID := aID;
Name := aName;
Age := aAge;
HomeCountry := aHomeCountry;
Company := aCompany;
end;

[ToString]
method ToString : String;
begin
exit $"ID: {ID}, Name: {Name}, Age: {Age}, Country : {HomeCountry}, CompanyId: {Company}";
end;

end;

TCompany = public class
public
property ID : Integer;
property Name : String;
property HomeCountry : String;



constructor (aID : Integer; aName : String; aHomeCountry : String);
begin
Name := aName;
ID := aID;
HomeCountry := aHomeCountry;
end;
end;


Test_Data = static class
public
method PrepareUsers : List<TUser>;
begin
exit new List<TUser>([
new TUser(1,'John Doe', 42, 'USA',1),
new TUser(2,'Jane Doe', 38, 'USA',2),
new TUser(3,'Joe Doe', 20, 'Germany',3),
new TUser(4,'Jenna Doe', 19, 'Germany',4),
new TUser(5,'Marc Hofmann', 32, 'Curacao',1),
new TUser(6,'James Doe', 8, 'USA',6)
]);

end;

method PrepareCompanies : List<TCompany>;
begin
exit new List<TCompany>([
new TCompany(1,'Remobjects', 'USA'),
new TCompany(2,'Apple', 'USA'),
new TCompany(3,'Microsoft', 'USA'),
new TCompany(4,'Huawei', 'China'),
new TCompany(5,'Nixdorf', 'Germany'),
new TCompany(6,'SAP', 'Germany')
]);

end;

end;

end.
115 changes: 115 additions & 0 deletions Tests/Ling_Tests.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace RemObjects.Elements.Island.Tests;
{$DEFINE COMPILEBREAK}
interface

uses
RemObjects.Elements.EUnit;

type
Linq_Tests = public class(Test)
private

public
method SingleWhere;
method MultiWhere;
method TestOrderBy;
method TestOrderByDesc;

method TestOrderByMulti;
method TestJoin;
end;


implementation

method Linq_Tests.SingleWhere;
begin
var Users :=
from User in Test_Data.PrepareUsers
Where User.Age ≥ 20;
Assert.AreEqual(Users.Count, 4);

end;

method Linq_Tests.MultiWhere;
begin
var Users :=
from User in Test_Data.PrepareUsers
Where (User.Age ≥ 20) and (User.HomeCountry = 'USA');
Assert.AreEqual(Users.Count, 2);
Var UserArray := Users.ToArray;
Assert.AreEqual(UserArray[0].ID, 1);
Assert.AreEqual(UserArray[1].ID, 2);
end;

method Linq_Tests.TestOrderBy;
begin
var Users :=
from User in Test_Data.PrepareUsers
Order by User.Age;
for each User in Users index i do
begin
case i of
0 : Assert.AreEqual(User.Age, 8, $'Wrong Age in {i} is {User.Age}');
1 : Assert.AreEqual(User.Age, 19, $'Wrong Age in {i} is {User.Age}');
2 : Assert.AreEqual(User.Age, 20, $'Wrong Age in {i} is {User.Age}');
3 : Assert.AreEqual(User.Age, 32, $'Wrong Age in {i} is {User.Age}');
end;
end;

end;

method Linq_Tests.TestOrderByDesc;
begin
var Users :=
from User in Test_Data.PrepareUsers
Order by User.Age desc;
for each User in Users index i do
begin
case i of
0 : Assert.AreEqual(User.Age, 42, $'Wrong Age in {i} is {User.Age}');
1 : Assert.AreEqual(User.Age, 38, $'Wrong Age in {i} is {User.Age}');
2 : Assert.AreEqual(User.Age, 32, $'Wrong Age in {i} is {User.Age}');
3 : Assert.AreEqual(User.Age, 20, $'Wrong Age in {i} is {User.Age}');
end;
end;

end;

method Linq_Tests.TestOrderByMulti;
begin
var Users :=
from User in Test_Data.PrepareUsers
Order by User.HomeCountry, User.Age;

for each User in Users index i do
begin
case i of
0 : Assert.AreEqual(User.Age, 32, $'Wrong Age in {i} is {User.ToString}');
1 : Assert.AreEqual(User.Age, 19, $'Wrong Age in {i} is {User.ToString}');
2 : Assert.AreEqual(User.Age, 20, $'Wrong Age in {i} is {User.ToString}');
3 : Assert.AreEqual(User.Age, 8, $'Wrong Age in {i} is {User.ToString}');
end;
end;

end;

method Linq_Tests.TestJoin;
begin
{$IFDEF COMPILEBREAK}
var lJoinList :=
from User in Test_Data.PrepareUsers
order by User.HomeCountry
join Company in Test_Data.PrepareCompanies on User.Company equals Company.ID
select new class (CompanyName := Company.Name , Employe := User)// into P
// where P.CompanyName = 'USA'
;

for each entry in lJoinList index i do begin
case i of
0 : Assert.AreEqual(entry.CompanyName, 'Remobjects');
end;
end;
{$ENDIF}
end;
end.