-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Rule0075: Record Get Procedure Arguments (#826)
* New Rule0075: Record Get Procedure Arguments * Exclude AL version below 13.0 * Move GetTypeSymbol() to ArgumentExtension * Remove conversion Integer to Enum * Fix test
- Loading branch information
Showing
33 changed files
with
869 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#if !LessThenSpring2024 | ||
namespace BusinessCentral.LinterCop.Test; | ||
|
||
public class Rule0075 | ||
{ | ||
private string _testCaseDir = ""; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
_testCaseDir = Path.Combine(Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName, | ||
"TestCases", "Rule0075"); | ||
} | ||
|
||
[Test] | ||
[TestCase("ImplicitConversiontCodeToEnum")] | ||
[TestCase("ImplicitConversiontEnumToAnotherEnum")] | ||
[TestCase("RecordGetGlobalVariable")] | ||
[TestCase("RecordGetLocalVariable")] | ||
[TestCase("RecordGetMethod")] | ||
[TestCase("RecordGetParameter")] | ||
[TestCase("RecordGetReportDataItem")] | ||
[TestCase("RecordGetReturnValue")] | ||
[TestCase("RecordGetSetupTableIncorrectArgumentsProvided")] | ||
[TestCase("RecordGetSetupTableNoArgumentsProvided")] | ||
[TestCase("RecordGetXmlPortTableElement")] | ||
public async Task HasDiagnostic(string testCase) | ||
{ | ||
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "HasDiagnostic", $"{testCase}.al")) | ||
.ConfigureAwait(false); | ||
|
||
var fixture = RoslynFixtureFactory.Create<Rule0075RecordGetProcedureArguments>(); | ||
fixture.HasDiagnostic(code, Rule0075RecordGetProcedureArguments.DiagnosticDescriptors.Rule0075RecordGetProcedureArguments.Id); | ||
} | ||
|
||
[Test] | ||
[TestCase("ImplicitConversiontIntegerToEnum")] | ||
[TestCase("RecordGetBuiltInMethodRecordId")] | ||
[TestCase("RecordGetFieldRecordId")] | ||
[TestCase("RecordGetGlobalVariable")] | ||
[TestCase("RecordGetLocalVariable")] | ||
[TestCase("RecordGetLocalVariableRecordId")] | ||
[TestCase("RecordGetMethod")] | ||
[TestCase("RecordGetMethodRecordId")] | ||
[TestCase("RecordGetParameter")] | ||
[TestCase("RecordGetParameterRecordId")] | ||
[TestCase("RecordGetReportDataItem")] | ||
[TestCase("RecordGetReturnValue")] | ||
[TestCase("RecordGetReturnValueRecordId")] | ||
[TestCase("RecordGetSetupTableCorrectArgumentsProvided")] | ||
[TestCase("RecordGetSetupTableNoArgumentsProvided")] | ||
[TestCase("RecordGetXmlPortTableElement")] | ||
public async Task NoDiagnostic(string testCase) | ||
{ | ||
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "NoDiagnostic", $"{testCase}.al")) | ||
.ConfigureAwait(false); | ||
|
||
var fixture = RoslynFixtureFactory.Create<Rule0075RecordGetProcedureArguments>(); | ||
fixture.NoDiagnosticAtMarker(code, Rule0075RecordGetProcedureArguments.DiagnosticDescriptors.Rule0075RecordGetProcedureArguments.Id); | ||
} | ||
} | ||
#endif |
25 changes: 25 additions & 0 deletions
25
...sCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/ImplicitConversiontCodeToEnum.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
SalesHeader: Record "Sales Header"; | ||
DocumentNo: Code[20]; | ||
begin | ||
[|SalesHeader.Get(DocumentNo, DocumentNo)|]; | ||
end; | ||
} | ||
|
||
table 50100 "Sales Header" | ||
{ | ||
fields | ||
{ | ||
field(1; "Document Type"; Enum "Sales Document Type") { } | ||
field(2; "No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Document Type", "No.") { } | ||
} | ||
} | ||
|
||
enum 50100 "Sales Document Type" { } |
27 changes: 27 additions & 0 deletions
27
...l.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/ImplicitConversiontEnumToAnotherEnum.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
SalesHeader: Record "Sales Header"; | ||
PurchaseDocumentType: Enum "Purchase Document Type"; | ||
DocumentNo: Code[20]; | ||
begin | ||
[|SalesHeader.Get(PurchaseDocumentType, DocumentNo)|]; | ||
end; | ||
} | ||
|
||
table 50100 "Sales Header" | ||
{ | ||
fields | ||
{ | ||
field(1; "Document Type"; Enum "Sales Document Type") { } | ||
field(2; "No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Document Type", "No.") { } | ||
} | ||
} | ||
|
||
enum 50100 "Sales Document Type" { } | ||
enum 50101 "Purchase Document Type" { } |
23 changes: 23 additions & 0 deletions
23
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetGlobalVariable.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
var | ||
ItemVariant: Record "Item Variant"; | ||
|
||
procedure MyProcedure() | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetLocalVariable.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
ItemVariant: Record "Item Variant"; | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetMethod.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
begin | ||
[|RecordReturnValue().Get('10000')|]; | ||
end; | ||
|
||
procedure RecordReturnValue() ItemVariant: Record "Item Variant" | ||
begin | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetParameter.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure(var ItemVariant: Record "Item Variant") | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetReportDataItem.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
report 50100 MyReport | ||
{ | ||
dataset | ||
{ | ||
dataitem(ItemVariant; "Item Variant") { } | ||
} | ||
|
||
trigger OnPreReport() | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
BusinessCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetReturnValue.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() ItemVariant: Record "Item Variant" | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...op.Test/TestCases/Rule0075/HasDiagnostic/RecordGetSetupTableIncorrectArgumentsProvided.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
CompanyInformation: Record "Company Information"; | ||
begin | ||
[|CompanyInformation.Get('', 12345)|]; | ||
end; | ||
} | ||
|
||
table 79 "Company Information" | ||
{ | ||
fields | ||
{ | ||
field(1; "Primary Key"; Code[10]) { } | ||
} | ||
|
||
keys | ||
{ | ||
key(Key1; "Primary Key") { } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetSetupTableNoArgumentsProvided.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
ItemVariant: Record "Item Variant"; | ||
begin | ||
[|ItemVariant.Get()|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ssCentral.LinterCop.Test/TestCases/Rule0075/HasDiagnostic/RecordGetXmlPortTableElement.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
xmlport 50100 MyXmlport | ||
{ | ||
schema | ||
{ | ||
tableelement(ItemVariant; "Item Variant") { } | ||
} | ||
|
||
trigger OnPreXmlPort() | ||
begin | ||
[|ItemVariant.Get('10000')|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...entral.LinterCop.Test/TestCases/Rule0075/NoDiagnostic/ImplicitConversiontIntegerToEnum.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
SalesHeader: Record "Sales Header"; | ||
myInteger: Integer; | ||
DocumentNo: Code[20]; | ||
begin | ||
[|SalesHeader.Get("Sales Document Type".FromInteger(myInteger), DocumentNo)|]; | ||
end; | ||
} | ||
|
||
table 50100 "Sales Header" | ||
{ | ||
fields | ||
{ | ||
field(1; "Document Type"; Enum "Sales Document Type") { } | ||
field(2; "No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Document Type", "No.") { } | ||
} | ||
} | ||
|
||
enum 50100 "Sales Document Type" { } |
22 changes: 22 additions & 0 deletions
22
...sCentral.LinterCop.Test/TestCases/Rule0075/NoDiagnostic/RecordGetBuiltInMethodRecordId.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
codeunit 50100 MyCodeunit | ||
{ | ||
procedure MyProcedure() | ||
var | ||
ItemVariant: Record "Item Variant"; | ||
begin | ||
[|ItemVariant.Get(ItemVariant.RecordId())|]; | ||
end; | ||
} | ||
|
||
table 50100 "Item Variant" | ||
{ | ||
fields | ||
{ | ||
field(1; "Code"; Code[10]) { } | ||
field(2; "Item No."; Code[20]) { } | ||
} | ||
keys | ||
{ | ||
key(Key1; "Item No.", "Code") { } | ||
} | ||
} |
Oops, something went wrong.