57 lines
3.2 KiB
C#
57 lines
3.2 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests.DataConnections;
|
|
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P11")]
|
|
public sealed class GrpcDataSdkSampleEvidenceTests
|
|
{
|
|
[Fact]
|
|
public void Status_match_only_normalizes_an_empty_datavalue_info_type()
|
|
{
|
|
ProjectedMonitoredItem.SameObservedStatus(0x00000400u, 0u).ShouldBeTrue();
|
|
ProjectedMonitoredItem.SameObservedStatus(0x80000400u, 0x80000000u).ShouldBeTrue();
|
|
ProjectedMonitoredItem.SameObservedStatus(0x00000480u, 0u).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameObservedStatus(0x00001400u, 0u).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameObservedStatus(0x40000400u, 0u).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameObservedStatus(0x00000800u, 0u).ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Repeat_observation_matches_the_same_source_acquisition_without_replacing_queued_evidence()
|
|
{
|
|
var identity = new object();
|
|
var timestamp = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
var sample = new ProjectedValueWrite(DataRealm.Raw, "projected", 1,
|
|
new ServingIdentity("node", "incarnation", "Primary", 1, 1, 1),
|
|
new DataValueSnapshot(new[] { 1, 2 }, 0, timestamp, timestamp),
|
|
new DataAgeBounds(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)), 123,
|
|
new Proof(identity), SourceVersion: 7);
|
|
var replay = sample with
|
|
{
|
|
Snapshot = sample.Snapshot with { Value = new[] { 1, 2 } },
|
|
Proof = new Proof(identity), IsCompleteSnapshot = true
|
|
};
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay).ShouldBeTrue();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { SourceVersion = 8 }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { SourceVersion = null }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { SourceVersion = 0 }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { Proof = new Proof(new object()) }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { ReceivedTimestamp = 124 }).ShouldBeTrue();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { OriginAgeBounds = new(TimeSpan.Zero, TimeSpan.FromSeconds(2)) }).ShouldBeTrue();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { Serving = replay.Serving with { ServingGeneration = 2 } }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { Snapshot = replay.Snapshot with { ServerTimestampUtc = timestamp.AddTicks(1) } }).ShouldBeFalse();
|
|
ProjectedMonitoredItem.SameAcquisition(sample, replay with { Snapshot = replay.Snapshot with { Value = new[] { 1, 3 } } }).ShouldBeFalse();
|
|
}
|
|
|
|
private sealed class Proof(object identity) : IProjectedSamplePublicationProof
|
|
{
|
|
public bool IsValid => true;
|
|
public object SourceIdentity => identity;
|
|
public TimeProvider Clock => TimeProvider.System;
|
|
public void Invalidate() { }
|
|
}
|
|
}
|