Skip to content

Commit

Permalink
Refactoring of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TKapitan committed Dec 15, 2020
1 parent 1f123f6 commit bcee522
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 41 deletions.
88 changes: 48 additions & 40 deletions Test/Src/Tests/AssignableRangeTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ codeunit 79000 "C4BC Assignable Range Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
TempInt := C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table);
Assert.IsTrue(TempInt = 30000, StrSubstNo(BadNewIDErr, 30000, TempInt));

TempInt := C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::"XML Port");
Assert.IsTrue(TempInt = 99000, StrSubstNo(BadNewIDErr, 99000, TempInt));

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_02());
asserterror C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table);
Assert.AssertNothingInsideFilter();

asserterror C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::"Table Extension");
Assert.AssertNothingInsideFilter();
end;

[Test]
Expand All @@ -45,20 +49,25 @@ codeunit 79000 "C4BC Assignable Range Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
TempInt := C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table);
Assert.IsTrue(TempInt = 30000, StrSubstNo(BadNewIDErr, 30000, TempInt));

TempInt := C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table, 'IGNORED_BCINSTANCE');
Assert.IsTrue(TempInt = 30000, StrSubstNo(BadNewIDErr, 30000, TempInt));

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_03());
asserterror C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table);
Assert.ExpectedError('instance ID and the value must not be empty');

TempInt := C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table, 'IGNORED_BCINSTANCE');
Assert.IsTrue(TempInt = 40000, StrSubstNo(BadNewIDErr, 40000, TempInt));

asserterror C4BCAssignableRangeHeader.GetNewObjectID("C4BC Object Type"::Table);
Assert.ExpectedError('instance ID and the value must not be empty');
end;

[Test]
Expand All @@ -72,6 +81,7 @@ codeunit 79000 "C4BC Assignable Range Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Expand All @@ -81,9 +91,9 @@ codeunit 79000 "C4BC Assignable Range Tests"

[Test]
/// <summary>
/// Test behavior when the field Range per BC Instances is changed
/// Test behavior when the field Range per BC Instances is changed on ranges that are not in use
/// </summary>
procedure TestChangeRangePerBCInstances()
procedure TestChangeRangePerBCInstancesThatAreNotInUse()
var
C4BCAssignableRangeHeader: Record "C4BC Assignable Range Header";
C4BCObjectRangeTestLibrary: Codeunit "C4BC Object Range Test Library";
Expand All @@ -93,36 +103,55 @@ codeunit 79000 "C4BC Assignable Range Tests"

//[WHEN] when
// No Extension Lines for Assignable Range exists
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", true);
C4BCAssignableRangeHeader.Modify(true);

C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", false);
C4BCAssignableRangeHeader.Modify(true);

C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", true);
C4BCAssignableRangeHeader.Modify(true);
end;

[Test]
/// <summary>
/// Test behavior when the field Range per BC Instances is changed on ranges that are already in use
/// </summary>
procedure TestChangeRangePerBCInstancesThatAreInUse()
var
C4BCAssignableRangeHeader: Record "C4BC Assignable Range Header";
C4BCObjectRangeTestLibrary: Codeunit "C4BC Object Range Test Library";
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();

//[WHEN] when
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_02());
C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", true);
C4BCAssignableRangeHeader.Modify(true);
C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", false);
C4BCAssignableRangeHeader.Modify(true);

C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
asserterror C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", true);
Assert.ExpectedError('due to the existing extensions');

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_03());
asserterror C4BCAssignableRangeHeader.Validate("Ranges per BC Instance", false);
Assert.ExpectedError('due to the existing extensions');
end;


[Test]
/// <summary>
/// Test condition when the assignable range default range could be deleted.
Expand All @@ -135,34 +164,19 @@ codeunit 79000 "C4BC Assignable Range Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());

asserterror C4BCAssignableRangeHeader.Validate("Default Object Range From", C4BCAssignableRangeHeader."Default Object Range From" + 10);
Assert.ExpectedError('there are extension lines with');

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
C4BCAssignableRangeHeader.Validate("Default Object Range From", C4BCAssignableRangeHeader."Default Object Range From" - 1);
C4BCAssignableRangeHeader.Validate("Default Object Range To", C4BCAssignableRangeHeader."Default Object Range To" + 10);
C4BCAssignableRangeHeader.Validate("Default Object Range To", C4BCAssignableRangeHeader."Default Object Range To" - 10);

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
asserterror C4BCAssignableRangeHeader.Validate("Default Object Range To", C4BCAssignableRangeHeader."Default Object Range From");
Assert.ExpectedError('there are extension lines with');

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_04());
C4BCAssignableRangeHeader.Validate("Default Object Range From", 0);
C4BCAssignableRangeHeader.Validate("Default Object Range To", 0);
Expand All @@ -180,29 +194,20 @@ codeunit 79000 "C4BC Assignable Range Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeLine.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01(), "C4BC Object Type"::"XML Port", 99000);
asserterror C4BCAssignableRangeLine.Validate("Object Range To", C4BCAssignableRangeLine."Object Range From");
Assert.ExpectedError('there are extension lines with');

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
C4BCAssignableRangeLine.Validate("Object Range To", C4BCAssignableRangeLine."Object Range From" + 10);
C4BCAssignableRangeLine.Validate("Object Range To", C4BCAssignableRangeLine."Object Range To" + 10);

C4BCAssignableRangeLine.Rename(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01(), "C4BC Object Type"::"XML Port", 98999);
C4BCAssignableRangeLine.Rename(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01(), "C4BC Object Type"::"XML Port", 99000);
asserterror C4BCAssignableRangeLine.Rename(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01(), "C4BC Object Type"::"XML Port", 99001);
Assert.ExpectedError('there are extension lines with');

//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();

//[THEN] then
C4BCAssignableRangeLine.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_04(), "C4BC Object Type"::Enum, 100000);
C4BCAssignableRangeLine.Validate("Object Range From", 0);
C4BCAssignableRangeLine.Validate("Object Range To", 0);
Expand All @@ -222,14 +227,14 @@ codeunit 79000 "C4BC Assignable Range Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_05());
C4BCAssignableRangeHeader.Validate("Object Name Template", 'C4BC *');
C4BCAssignableRangeHeader.Validate("Object Name Template", '');
C4BCAssignableRangeHeader.Validate("Object Name Template", 'C4BC *');

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_06());
asserterror C4BCAssignableRangeHeader.Validate("Object Name Template", 'C4BC *');
Assert.ExpectedError('extension lines that are different from');
Expand All @@ -249,6 +254,7 @@ codeunit 79000 "C4BC Assignable Range Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Expand All @@ -271,6 +277,7 @@ codeunit 79000 "C4BC Assignable Range Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_05());
Expand All @@ -293,6 +300,7 @@ codeunit 79000 "C4BC Assignable Range Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[THEN] then
C4BCAssignableRangeLine.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01(), "C4BC Object Type"::"XML Port", 99000);
Expand All @@ -316,6 +324,7 @@ codeunit 79000 "C4BC Assignable Range Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeAssignableFieldRanges();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Expand All @@ -324,7 +333,6 @@ codeunit 79000 "C4BC Assignable Range Tests"
TempInt := C4BCAssignableRangeHeader.GetNewFieldID("C4BC Object Type"::Table, 'IGNORED_BCINSTANCE');
Assert.IsTrue(TempInt = 200000, StrSubstNo(BadNewIDErr, 200000, TempInt));

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_03());
asserterror C4BCAssignableRangeHeader.GetNewFieldID("C4BC Object Type"::Table);
Assert.ExpectedError('instance ID and the value must not be empty');
Expand All @@ -345,6 +353,7 @@ codeunit 79000 "C4BC Assignable Range Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeAssignableFieldRanges();
Commit();

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Expand All @@ -353,7 +362,6 @@ codeunit 79000 "C4BC Assignable Range Tests"
TempInt := C4BCAssignableRangeHeader.GetNewFieldID("C4BC Object Type"::Table, 'IGNORED_BCINSTANCE');
Assert.IsTrue(TempInt = 200000, StrSubstNo(BadNewIDErr, 200000, TempInt));

//[THEN] then
C4BCAssignableRangeHeader.Get(C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_02());
asserterror C4BCAssignableRangeHeader.GetNewFieldID("C4BC Object Type"::Table);
Assert.ExpectedError('must have a value');
Expand Down
10 changes: 10 additions & 0 deletions Test/Src/Tests/BusCentrInstTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ codeunit 79004 "C4BC Bus. Centr. Inst. Tests"
/// </summary>
procedure TestDeleteBusinessCentralInstance()
var
C4BCExtensionUsage: Record "C4BC Extension Usage";
C4BCBusinessCentralInstance: Record "C4BC Business Central Instance";
C4BCObjectRangeTestLibrary: Codeunit "C4BC Object Range Test Library";
begin
Expand All @@ -21,12 +22,21 @@ codeunit 79004 "C4BC Bus. Centr. Inst. Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.SetExtensionUsage();
Commit();

//[THEN] then
C4BCBusinessCentralInstance.Get(C4BCObjectRangeTestLibrary.C4BCBusinessCentralInstance_Code_02());
C4BCBusinessCentralInstance.Delete(true);
C4BCBusinessCentralInstance.Get(C4BCObjectRangeTestLibrary.C4BCBusinessCentralInstance_Code_01());
asserterror C4BCBusinessCentralInstance.Delete(true);
Assert.ExpectedError('due to the existing');

//[WHEN] when
C4BCExtensionUsage.SetRange("Business Central Instance Code", C4BCObjectRangeTestLibrary.C4BCBusinessCentralInstance_Code_01());
C4BCExtensionUsage.DeleteAll(false);

//[THEN] then
C4BCBusinessCentralInstance.Get(C4BCObjectRangeTestLibrary.C4BCBusinessCentralInstance_Code_01());
C4BCBusinessCentralInstance.Delete(true);
end;
}
11 changes: 10 additions & 1 deletion Test/Src/Tests/ExtensionTests.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ codeunit 79002 "C4BC Extension Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCExtensionHeader.Init();
C4BCExtensionHeader.Validate("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Clear(C4BCExtensionHeader);

//[THEN] then
C4BCExtensionHeader.Init();
asserterror C4BCExtensionHeader.Validate("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_02());
Assert.ExpectedError('must have a value');
Expand All @@ -42,6 +42,7 @@ codeunit 79002 "C4BC Extension Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCExtensionCard.OpenNew();
Expand Down Expand Up @@ -89,6 +90,7 @@ codeunit 79002 "C4BC Extension Tests"
//[WHEN] when
C4BCObjectRangeTestLibrary.SetObjectNameTemplate();
Commit();

C4BCExtensionObject.SetRange("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCExtensionObject.FindFirst();

Expand Down Expand Up @@ -120,6 +122,8 @@ codeunit 79002 "C4BC Extension Tests"

//[WHEN] when
// No Template is set
Commit();

C4BCExtensionObject.SetRange("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCExtensionObject.FindFirst();

Expand Down Expand Up @@ -147,6 +151,8 @@ codeunit 79002 "C4BC Extension Tests"

//[WHEN] when
C4BCObjectRangeTestLibrary.SetObjectNameTemplate();
Commit();

C4BCExtensionObject.SetRange("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
C4BCExtensionObject.SetRange("Object Type", C4BCExtensionObject."Object Type"::Table);
C4BCExtensionObject.FindFirst();
Expand Down Expand Up @@ -201,6 +207,7 @@ codeunit 79002 "C4BC Extension Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[WHEN] when
C4BCExtensionHeader.SetRange("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_01());
Expand All @@ -225,6 +232,7 @@ codeunit 79002 "C4BC Extension Tests"
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
C4BCObjectRangeTestLibrary.InitializeExtensions();
Commit();

//[WHEN] when
C4BCExtensionHeader.SetRange("Assignable Range Code", C4BCObjectRangeTestLibrary.C4BCAssignableRangeHeader_Code_06());
Expand All @@ -249,6 +257,7 @@ codeunit 79002 "C4BC Extension Tests"
begin
//[GIVEN] given
C4BCObjectRangeTestLibrary.InitializeAssignableRanges();
Commit();

//[THEN] then
C4BCExtensionHeader.Init();
Expand Down
Loading

0 comments on commit bcee522

Please sign in to comment.