57 lines
2.8 KiB
C#
57 lines
2.8 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests.DataConnections;
|
|
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P08")]
|
|
public sealed class GrpcDataProjectedIdentityTests
|
|
{
|
|
[Fact]
|
|
public void Script_dependency_references_preserve_realm_and_do_not_alias_local_raw_paths()
|
|
{
|
|
var origin = new DataAddress("cluster-b", "urn:source", "string", "Plant/Tag");
|
|
var id = ProjectedDataIds.Identifier("mapping", origin);
|
|
var raw = ProjectedDataIds.DependencyReference(DataRealm.Raw, id);
|
|
var uns = ProjectedDataIds.DependencyReference(DataRealm.Uns, id);
|
|
raw.ShouldNotBe(uns);
|
|
raw.ShouldNotBe(origin.Identifier);
|
|
ProjectedDataIds.TryParseDependencyReference(raw, out var realm, out var decoded).ShouldBeTrue();
|
|
realm.ShouldBe(DataRealm.Raw);
|
|
decoded.ShouldBe(id);
|
|
ProjectedDataIds.TryParseDependencyReference(origin.Identifier, out _, out _).ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Projected_namespaces_are_disjoint_from_legacy_raw_and_uns_identifiers()
|
|
{
|
|
ProjectedDataIds.RawNamespaceUri.ShouldNotBe("https://zb.com/otopcua/raw");
|
|
ProjectedDataIds.UnsNamespaceUri.ShouldNotBe("https://zb.com/otopcua/uns");
|
|
ProjectedDataIds.NamespaceUri(DataRealm.Raw).ShouldNotBe(ProjectedDataIds.NamespaceUri(DataRealm.Uns));
|
|
ProjectedDataIds.IsMappedNamespace(ProjectedDataIds.RawNamespaceUri).ShouldBeTrue();
|
|
ProjectedDataIds.IsMappedNamespace(ProjectedDataIds.UnsNamespaceUri).ShouldBeTrue();
|
|
ProjectedDataIds.IsMappedNamespace("https://zb.com/otopcua/raw").ShouldBeFalse();
|
|
ProjectedDataIds.IsMappedNamespace("https://zb.com/otopcua/uns").ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Opaque_identity_preserves_exact_origin_and_mapping_without_separator_collisions()
|
|
{
|
|
var origin = new DataAddress("cluster-b", "urn:source/raw", "string", "Plant/Line/Tag");
|
|
var identifier = ProjectedDataIds.Identifier("mapping-a", origin);
|
|
identifier.ShouldNotBe(ProjectedDataIds.Identifier("mapping-b", origin));
|
|
identifier.ShouldNotBe(ProjectedDataIds.Identifier("mapping-a", origin with { NamespaceUri = "urn:source/uns" }));
|
|
ProjectedDataIds.TryDecodeIdentifier(identifier, out var mapping, out var decoded).ShouldBeTrue();
|
|
mapping.ShouldBe("mapping-a");
|
|
decoded.ShouldBe(origin);
|
|
ProjectedDataIds.Identifier(mapping, decoded!).ShouldBe(identifier);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not-a-projection")]
|
|
[InlineData("../mapping/origin")]
|
|
public void Invalid_identifiers_do_not_resolve_to_an_origin(string identifier) =>
|
|
ProjectedDataIds.TryDecodeIdentifier(identifier, out _, out _).ShouldBeFalse();
|
|
}
|