From 77eb5d8b458f5f4721f3d030457c4aca64982b9c Mon Sep 17 00:00:00 2001 From: Thom Lamb Date: Wed, 27 May 2026 12:01:34 -0500 Subject: [PATCH] chore(sonar): hoist constant arrays to static readonly fields in tests (CA1861) Two inline `new[] { ... }` literals inside TestCaseSource yield-returns get hoisted to `static readonly string[]` fields with descriptive names (`monthListValues`, `calendarRange`) matching the surrounding test-case identifiers. Avoids reconstructing the same array on each call. Only the test-file CA1861 sites are touched; the three production-code sites flagged for the same rule are out of scope for this branch and will land separately. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ExpressionTests/ExpressionFactoryFilterTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionFactoryFilterTests.cs b/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionFactoryFilterTests.cs index 25ce2f1..1fed843 100644 --- a/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionFactoryFilterTests.cs +++ b/tests/Strata.SqlTools.SqlBreakdown.Tests/ExpressionTests/ExpressionFactoryFilterTests.cs @@ -6,6 +6,8 @@ namespace Strata.SqlTools.SqlBreakdown.Tests.ExpressionTests; public class ExpressionFactoryFilterTests : ExpressionTestsBase { private static readonly string[] values = new[] { "FY2019", "FY2020", "FY2021", "FY2022" }; + private static readonly string[] monthListValues = new[] { "01-2020" }; + private static readonly string[] calendarRange = new[] { "01/01/2019", "01/01/2023" }; private static IEnumerable FilterTestCases() { @@ -23,12 +25,12 @@ public class ExpressionFactoryFilterTests : ExpressionTestsBase ).SetName("DateListFilterFiscalYear_{m}"); yield return new TestCaseData( - new Filter(4, FilterType.List, new[] { "01-2020" }, Array.Empty(), DatePart.Month, false, 0, 0), + new Filter(4, FilterType.List, monthListValues, Array.Empty(), DatePart.Month, false, 0, 0), "DEPT.DISCHARGE_DATE >= '2020-01-01' AND DEPT.DISCHARGE_DATE < '2020-02-01'" ).SetName("MonthListFilter_{m}"); yield return new TestCaseData( - new Filter(4, FilterType.Calendar, new[] { "01/01/2019", "01/01/2023" }, Array.Empty(), DatePart.Month, false, 0, 0), + new Filter(4, FilterType.Calendar, calendarRange, Array.Empty(), DatePart.Month, false, 0, 0), "DEPT.DISCHARGE_DATE >= '2019-01-01' AND DEPT.DISCHARGE_DATE < '2023-01-01'" ).SetName("CalendarFilter_{m}");