33 lines
1.7 KiB
C#
33 lines
1.7 KiB
C#
using System.Reflection;
|
|
using Opc.Ua;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
|
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests.Adapters;
|
|
|
|
public class RealOpcUaSnapshotScopeTests
|
|
{
|
|
[Fact]
|
|
public void RefreshBoundaries_PreserveSourceAndHaveDistinctEpochs()
|
|
{
|
|
var client = new RealOpcUaClient();
|
|
var events = new List<NativeAlarmTransition>();
|
|
var handler = typeof(RealOpcUaClient).GetMethod("HandleAlarmEvent", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
|
void Emit(string handle, string source, NodeId type) => handler.Invoke(client,
|
|
[handle, source, new EventFieldList { EventFields = new VariantCollection { new(type), new(), new(), new(), new(), new() } }, (Action<NativeAlarmTransition>)events.Add]);
|
|
Emit("a", "A", ObjectTypeIds.RefreshStartEventType);
|
|
Emit("b", "B", ObjectTypeIds.RefreshStartEventType);
|
|
Emit("a", "A", ObjectTypeIds.RefreshEndEventType);
|
|
Emit("b", "B", ObjectTypeIds.RefreshEndEventType);
|
|
Assert.Equal(4, events.Count);
|
|
Assert.Equal(["SnapshotStart", "SnapshotStart", "SnapshotComplete", "SnapshotComplete"], events.Select(e => e.Kind.ToString()));
|
|
Assert.Equal(["A", "B", "A", "B"], events.Select(e => e.SourceObjectReference));
|
|
var epoch = typeof(NativeAlarmTransition).GetProperty("SnapshotId")!;
|
|
Assert.NotNull(epoch);
|
|
Assert.NotNull(epoch.GetValue(events[0]));
|
|
Assert.Equal(epoch.GetValue(events[0]), epoch.GetValue(events[2]));
|
|
Assert.Equal(epoch.GetValue(events[1]), epoch.GetValue(events[3]));
|
|
Assert.NotEqual(epoch.GetValue(events[0]), epoch.GetValue(events[1]));
|
|
}
|
|
}
|