chore(sonar): cache JsonSerializerOptions in test fixture (CA1869)
SonarQube Analysis / sonarqube (pull_request) Successful in 5m12s

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) <noreply@anthropic.com>
This commit is contained in:
Thom Lamb
2026-05-27 12:02:25 -05:00
co-authored by Claude Opus 4.7
parent 77eb5d8b45
commit 470cb009b9
+11 -9
View File
@@ -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<long, IHierarchicalData>? _encounterLookup;
[OneTimeSetUp]
public void OneTimeSetup()
{
var allData = JsonSerializer.Deserialize<List<IHierarchicalData>>(File.ReadAllText(@"Data.json"), new JsonSerializerOptions
{
Converters =
{
new HierarchicalDataConverter(),
new FlatDataConverter(),
new ObjectToInferredTypesConverter()
}
});
var allData = JsonSerializer.Deserialize<List<IHierarchicalData>>(File.ReadAllText(@"Data.json"), _jsonOptions);
if (allData == null || allData.Count == 0)
{