From 470cb009b90c49ac0377cad59758099b3fb1abb5 Mon Sep 17 00:00:00 2001 From: Thom Lamb Date: Wed, 27 May 2026 12:02:25 -0500 Subject: [PATCH] chore(sonar): cache JsonSerializerOptions in test fixture (CA1869) Promote the `new JsonSerializerOptions { Converters = { ... } }` instance that `OneTimeSetup` was constructing on each fixture run to a `private static readonly JsonSerializerOptions _jsonOptions` field, so the converter list isn't rebuilt per fixture. Strictly cosmetic here (OneTimeSetup runs once) but it's the change the analyzer wants and the field is the more idiomatic JsonSerializer pattern. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Strata.SqlTools.Rules.Tests/UnitTest1.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/Strata.SqlTools.Rules.Tests/UnitTest1.cs b/tests/Strata.SqlTools.Rules.Tests/UnitTest1.cs index 382ed2d..a819250 100644 --- a/tests/Strata.SqlTools.Rules.Tests/UnitTest1.cs +++ b/tests/Strata.SqlTools.Rules.Tests/UnitTest1.cs @@ -11,20 +11,22 @@ public class Tests private static readonly Guid _pesDataTableGUID = new Guid("41639c8f-fecf-4449-b6e6-53f796c0c3e4"); private const string EncounterIDKey = "DimPatientEnEncounterID"; + private static readonly JsonSerializerOptions _jsonOptions = new() + { + Converters = + { + new HierarchicalDataConverter(), + new FlatDataConverter(), + new ObjectToInferredTypesConverter() + } + }; + public Dictionary? _encounterLookup; [OneTimeSetUp] public void OneTimeSetup() { - var allData = JsonSerializer.Deserialize>(File.ReadAllText(@"Data.json"), new JsonSerializerOptions - { - Converters = - { - new HierarchicalDataConverter(), - new FlatDataConverter(), - new ObjectToInferredTypesConverter() - } - }); + var allData = JsonSerializer.Deserialize>(File.ReadAllText(@"Data.json"), _jsonOptions); if (allData == null || allData.Count == 0) {