feat(commons): Layer B serializer + validator handle new OPC UA settings

OpcUaEndpointConfigSerializer:
- ToFlatDict emits new scalar keys (DiscardOldest, SubscriptionPriority,
  SubscriptionDisplayName, TimestampsToReturn).
- ToFlatDict emits dotted sub-object keys (UserIdentity.TokenType / Username /
  Password / CertificatePath / CertificatePassword, Deadband.Type / Value)
  when those sub-objects are non-null.
- FromFlatDict reads the same keys back; missing keys preserve POCO defaults.
- Deadband.Value uses InvariantCulture for double parsing/formatting.

OpcUaEndpointConfigValidator:
- SubscriptionDisplayName required (non-empty).
- UserIdentity.UsernamePassword requires Username.
- UserIdentity.X509Certificate requires CertificatePath.
- Deadband.Value must be > 0 when Deadband is set.
- fieldPrefix propagates through sub-object error EntityNames.

Drives the 11 previously-failing tests green; 51/51 in the suite now pass.
This commit is contained in:
Joseph Doherty
2026-05-12 02:22:51 -04:00
parent 91450ec390
commit b60a8ef409
2 changed files with 68 additions and 0 deletions
@@ -40,6 +40,10 @@ public static class OpcUaEndpointConfigValidator
if (config.MaxNotificationsPerPublish < 1)
errors.Add(Err("MaxNotificationsPerPublish", "Must be ≥ 1."));
if (string.IsNullOrWhiteSpace(config.SubscriptionDisplayName))
errors.Add(Err("SubscriptionDisplayName",
"Subscription display name is required."));
if (config.Heartbeat is { } hb)
{
if (string.IsNullOrWhiteSpace(hb.TagPath))
@@ -49,6 +53,21 @@ public static class OpcUaEndpointConfigValidator
errors.Add(Err("Heartbeat.MaxSilenceSeconds", "Must be > 0."));
}
if (config.UserIdentity is { } ui)
{
if (ui.TokenType == OpcUaUserTokenType.UsernamePassword
&& string.IsNullOrWhiteSpace(ui.Username))
errors.Add(Err("UserIdentity.Username",
"Username is required when token type is UsernamePassword."));
if (ui.TokenType == OpcUaUserTokenType.X509Certificate
&& string.IsNullOrWhiteSpace(ui.CertificatePath))
errors.Add(Err("UserIdentity.CertificatePath",
"Certificate path is required when token type is X509Certificate."));
}
if (config.Deadband is { } db && db.Value <= 0)
errors.Add(Err("Deadband.Value", "Must be > 0."));
return errors.Count == 0
? ValidationResult.Success()
: ValidationResult.FromErrors(errors.ToArray());