From 90b252047e20b089337064ec96cce804c166d8aa Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 12 May 2026 00:41:55 -0400 Subject: [PATCH] test(commons): decouple serializer tests from JSON whitespace and verify defaults symmetrically --- .../OpcUaEndpointConfigSerializerTests.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/ScadaLink.Commons.Tests/Types/DataConnections/OpcUaEndpointConfigSerializerTests.cs b/tests/ScadaLink.Commons.Tests/Types/DataConnections/OpcUaEndpointConfigSerializerTests.cs index bd1aefe..9edfd7f 100644 --- a/tests/ScadaLink.Commons.Tests/Types/DataConnections/OpcUaEndpointConfigSerializerTests.cs +++ b/tests/ScadaLink.Commons.Tests/Types/DataConnections/OpcUaEndpointConfigSerializerTests.cs @@ -58,22 +58,23 @@ public class OpcUaEndpointConfigSerializerTests { var config = new OpcUaEndpointConfig { SecurityMode = OpcUaSecurityMode.SignAndEncrypt }; var json = OpcUaEndpointConfigSerializer.Serialize(config); - Assert.Contains("\"securityMode\":\"signAndEncrypt\"", json); + + using var doc = System.Text.Json.JsonDocument.Parse(json); + Assert.Equal("signAndEncrypt", doc.RootElement.GetProperty("securityMode").GetString()); } - [Fact] - public void Deserialize_NullOrEmpty_ReturnsDefaults() + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + public void Deserialize_NullOrEmpty_ReturnsDefaults(string? input) { - var (config1, legacy1) = OpcUaEndpointConfigSerializer.Deserialize(null); - var (config2, legacy2) = OpcUaEndpointConfigSerializer.Deserialize(""); - var (config3, legacy3) = OpcUaEndpointConfigSerializer.Deserialize(" "); + var (config, isLegacy) = OpcUaEndpointConfigSerializer.Deserialize(input); - Assert.False(legacy1); - Assert.False(legacy2); - Assert.False(legacy3); - Assert.Equal("", config1.EndpointUrl); - Assert.Equal(60000, config1.SessionTimeoutMs); - Assert.Null(config1.Heartbeat); + Assert.False(isLegacy); + Assert.Equal("", config.EndpointUrl); + Assert.Equal(60000, config.SessionTimeoutMs); + Assert.Null(config.Heartbeat); } [Fact]