Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using ALCops.LinterCop.CodeFixes;
using RoslynTestKit;

namespace ALCops.LinterCop.Test
{
public class BuiltInDateTimeMethod : NavCodeAnalysisBase
{
private AnalyzerTestFixture _fixture;
private static readonly Analyzers.BuiltInDateTimeMethod _analyzer = new();
private string _testCasePath;

[SetUp]
public void Setup()
{
_fixture = RoslynFixtureFactory.Create<Analyzers.BuiltInDateTimeMethod>();

_testCasePath = Path.Combine(
Directory.GetParent(
Environment.CurrentDirectory)!.Parent!.Parent!.FullName,
Path.Combine("Rules", nameof(BuiltInDateTimeMethod)));
}

[Test]
[TestCase("Date2DMY")]
[TestCase("Date2DWY")]
[TestCase("DT2Date")]
[TestCase("DT2Time")]
[TestCase("FormatHour")]
[TestCase("FormatMillisecond")]
[TestCase("FormatMinute")]
[TestCase("FormatSecond")]
public async Task HasDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(HasDiagnostic), $"{testCase}.al"))
.ConfigureAwait(false);

_fixture.HasDiagnosticAtAllMarkers(code, DiagnosticIds.BuiltInDateTimeMethod);
}

// [Test]
// public async Task NoDiagnostic(string testCase)
// {
// var code = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(NoDiagnostic), $"{testCase}.al"))
// .ConfigureAwait(false);

// _fixture.NoDiagnosticAtAllMarkers(code, DiagnosticIds.BuiltInDateTimeMethod);
// }

[Test]
[TestCase("Date2DMY_Day")]
[TestCase("Date2DMY_Month")]
[TestCase("Date2DMY_Year")]
[TestCase("Date2DWY_DayOfWeek")]
[TestCase("Date2DWY_WeekNo")]
[TestCase("DT2Date")]
[TestCase("DT2Time")]
[TestCase("Format_Hour")]
[TestCase("Format_Minute")]
[TestCase("Format_Second")]
[TestCase("Format_Millisecond")]
public async Task HasFix(string testCase)
{
var currentCode = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(HasFix), testCase, "current.al"))
.ConfigureAwait(false);

var expectedCode = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(HasFix), testCase, "expected.al"))
.ConfigureAwait(false);

var fixture = RoslynFixtureFactory.Create<BuiltInDateTimeMethodCodeFixProvider>(
new CodeFixTestFixtureConfig
{
AdditionalAnalyzers = [_analyzer]
});

fixture.TestCodeFix(currentCode, expectedCode, DiagnosticDescriptors.BuiltInDateTimeMethod);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
MyDate: Date;
begin
MyDate := [|DT2Date(MyDateTime)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
MyTime: Time;
begin
MyTime := [|DT2Time(MyDateTime)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
MyInteger: Integer;
begin
MyInteger := [|Date2DMY(MyDate, 1)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
MyInteger: Integer;
begin
MyInteger := [|Date2DMY(MyDate, 1)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
i: Integer;
begin
Evaluate(i, [|Format(MyTime, 2, '<HOURS24>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
i: Integer;
begin
Evaluate(i, [|Format(MyTime, 2, '<THOUSANDS>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
i: Integer;
begin
Evaluate(i, [|Format(MyTime, 2, '<MINUTES>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
i: Integer;
begin
Evaluate(i, [|Format(MyTime, 2, '<SECONDS>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
DateValue: Date;
begin
DateValue := [|DT2Date(MyDateTime)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
DateValue: Date;
begin
DateValue := MyDateTime.Date();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
TimeValue: Time;
begin
TimeValue := [|DT2Time(MyDateTime)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDateTime: DateTime;
TimeValue: Time;
begin
TimeValue := MyDateTime.Time();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
DayValue: Integer;
begin
DayValue := [|Date2DMY(MyDate, 1)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
DayValue: Integer;
begin
DayValue := MyDate.Day();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
MonthValue: Integer;
begin
MonthValue := [|Date2DMY(MyDate, 2)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
MonthValue: Integer;
begin
MonthValue := MyDate.Month();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
YearValue: Integer;
begin
YearValue := [|Date2DMY(MyDate, 3)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
YearValue: Integer;
begin
YearValue := MyDate.Year();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
DayOfWeekValue: Integer;
begin
DayOfWeekValue := [|Date2DWY(MyDate, 1)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
DayOfWeekValue: Integer;
begin
DayOfWeekValue := MyDate.DayOfWeek();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
WeekNoValue: Integer;
begin
WeekNoValue := [|Date2DWY(MyDate, 2)|];
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyDate: Date;
WeekNoValue: Integer;
begin
WeekNoValue := MyDate.WeekNo();
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
HourValue: Integer;
begin
Evaluate(HourValue, [|Format(MyTime, 2, '<HOURS24>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
HourValue: Integer;
begin
Evaluate(HourValue, MyTime.Hour());
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
MillisecondValue: Integer;
begin
Evaluate(MillisecondValue, [|Format(MyTime, 3, '<THOUSANDS>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
MillisecondValue: Integer;
begin
Evaluate(MillisecondValue, MyTime.Millisecond());
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
MinuteValue: Integer;
begin
Evaluate(MinuteValue, [|Format(MyTime, 2, '<MINUTES>')|]);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTime: Time;
MinuteValue: Integer;
begin
Evaluate(MinuteValue, MyTime.Minute());
end;
}
Loading
Loading