Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve InvalidCastException #799

Merged
merged 10 commits into from
Nov 1, 2024
41 changes: 41 additions & 0 deletions BusinessCentral.LinterCop.Test/Rule0044.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace BusinessCentral.LinterCop.Test;

public class Rule0044
{
private string _testCaseDir = "";

[SetUp]
public void Setup()
{
_testCaseDir = Path.Combine(Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName,
"TestCases", "Rule0044");
}

#if !LessThenSpring2024
[Test]
[TestCase("1")]
[TestCase("2")]
#endif
public async Task HasDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "HasDiagnostic", $"{testCase}.al"))
.ConfigureAwait(false);

var fixture = RoslynFixtureFactory.Create<Rule0044AnalyzeTransferFields>();
fixture.HasDiagnostic(code, DiagnosticDescriptors.Rule0044AnalyzeTransferFields.Id);
}

#if !LessThenSpring2024
[Test]
[TestCase("1")]
[TestCase("2")]
#endif
public async Task NoDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "NoDiagnostic", $"{testCase}.al"))
.ConfigureAwait(false);

var fixture = RoslynFixtureFactory.Create<Rule0044AnalyzeTransferFields>();
fixture.NoDiagnosticAtMarker(code, DiagnosticDescriptors.Rule0044AnalyzeTransferFields.Id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tableextension 50100 Customer extends Customer
{
fields
{
[|field(50100; MyField; Code[20]) { }|]
}
}

tableextension 50101 Contact extends Contact
{
fields
{
field(50100; MyField; Integer) { }
}
}

table 18 Customer
{
fields
{
field(1; "No."; Code[20]) { }
}
}
table 5050 Contact
{
fields
{
field(1; "No."; Code[20]) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTableA: Record MyTableA;
MyTableB: Record MyTableB;
begin
[|MyTableA.TransferFields(MyTableB)|];
end;
}

table 50100 MyTableA
{
fields
{
field(1; "No."; Code[10]) { }
}
}
table 50101 MyTableB
{
fields
{
field(1; "No."; Code[20]) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tableextension 50100 Customer extends Customer
{
fields
{
[|field(50100; MyField; Integer) { }|]
}
}

tableextension 50101 Contact extends Contact
{
fields
{
field(50100; MyField; Integer) { }
}
}

table 18 Customer
{
fields
{
field(1; "No."; Code[20]) { }
}
}
table 5050 Contact
{
fields
{
field(1; "No."; Code[20]) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTableA: Record MyTableA;
MyTableB: Record MyTableB;
begin
[|MyTableA.TransferFields(MyTableB)|];
end;
}

table 50100 MyTableA
{
fields
{
field(1; "No."; Code[20]) { }
}
}
table 50101 MyTableB
{
fields
{
field(1; "No."; Code[20]) { }
}
}
Loading