Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataEditorValidationTests.cs
T
2026-11-23 09:55:04 -05:00

42 lines
2.4 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.DataConnections;
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P09")]
public sealed class GrpcDataEditorValidationTests
{
[Fact]
public void New_drafts_are_disabled_and_do_not_grant_write()
{
var connection = new DataConnectionEditorModel().Value;
var mapping = new RemoteMappingEditorModel().Value;
connection.Enabled.ShouldBeFalse(); mapping.Enabled.ShouldBeFalse();
connection.AllowedOperations.HasFlag(DataOperations.Write).ShouldBeFalse();
mapping.AllowedOperations.HasFlag(DataOperations.Write).ShouldBeFalse();
mapping.WriteThrough.ShouldBeFalse();
}
[Fact]
public void Enabled_mapping_must_use_the_connection_consumer_scope_and_require_write_through()
{
var connection = new DataConnection { DataConnectionId = "peer", ClusterId = "MAIN", Enabled = true,
ConsumerNodeIds = ["A"], TargetMode = DataTargetMode.Node, ExpectedClusterId = "REMOTE", ExpectedNodeId = "B",
Endpoints = ["https://peer.example"], SecretReference = "secret:data/peer", SecretScopeClusterId = "MAIN",
AllowedOperations = DataOperations.Read | DataOperations.Write };
var mapping = new RemoteNamespaceMapping { RemoteNamespaceMappingId = "mount", ClusterId = "MAIN", Enabled = true,
DataConnectionId = "peer", ConsumerNodeIds = ["B"], AllowedOperations = DataOperations.Write, WriteThrough = false };
var snapshot = new DraftSnapshot { GenerationId = 0, ClusterId = "MAIN", DataConnections = [connection],
RemoteNamespaceMappings = [mapping], ClusterNodes = [new ClusterNode { NodeId = "A", ClusterId = "MAIN", Host = "a", ApplicationUri = "urn:a", CreatedBy = "test" }] };
var errors = DataConnectionValidator.Validate(snapshot);
errors.ShouldContain(x => x.Code == "DataMappingConsumerScopeInvalid");
errors.ShouldContain(x => x.Code == "DataMappingOperationsInvalid");
}
[Fact]
public void List_editor_trims_lines_without_changing_order() =>
DataConnectionEditorModel.Lines(" a \r\n\n b ").ShouldBe(new[] { "a", "b" });
}