test(commons): decouple serializer tests from JSON whitespace and verify defaults symmetrically
This commit is contained in:
@@ -58,22 +58,23 @@ public class OpcUaEndpointConfigSerializerTests
|
|||||||
{
|
{
|
||||||
var config = new OpcUaEndpointConfig { SecurityMode = OpcUaSecurityMode.SignAndEncrypt };
|
var config = new OpcUaEndpointConfig { SecurityMode = OpcUaSecurityMode.SignAndEncrypt };
|
||||||
var json = OpcUaEndpointConfigSerializer.Serialize(config);
|
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]
|
[Theory]
|
||||||
public void Deserialize_NullOrEmpty_ReturnsDefaults()
|
[InlineData(null)]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData(" ")]
|
||||||
|
public void Deserialize_NullOrEmpty_ReturnsDefaults(string? input)
|
||||||
{
|
{
|
||||||
var (config1, legacy1) = OpcUaEndpointConfigSerializer.Deserialize(null);
|
var (config, isLegacy) = OpcUaEndpointConfigSerializer.Deserialize(input);
|
||||||
var (config2, legacy2) = OpcUaEndpointConfigSerializer.Deserialize("");
|
|
||||||
var (config3, legacy3) = OpcUaEndpointConfigSerializer.Deserialize(" ");
|
|
||||||
|
|
||||||
Assert.False(legacy1);
|
Assert.False(isLegacy);
|
||||||
Assert.False(legacy2);
|
Assert.Equal("", config.EndpointUrl);
|
||||||
Assert.False(legacy3);
|
Assert.Equal(60000, config.SessionTimeoutMs);
|
||||||
Assert.Equal("", config1.EndpointUrl);
|
Assert.Null(config.Heartbeat);
|
||||||
Assert.Equal(60000, config1.SessionTimeoutMs);
|
|
||||||
Assert.Null(config1.Heartbeat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user