Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/DataConnections/GrpcDataSdkContinuationTests.cs
T

34 lines
1.8 KiB
C#

using Opc.Ua;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.OpcUaServer.Security;
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests.DataConnections;
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P08")]
public sealed class GrpcDataSdkContinuationTests
{
[Fact]
public void Cursor_is_bound_to_original_session_caller_and_parent_and_only_advances_after_commit()
{
var parent = new NodeId("parent", 2);
var firstSession = new NodeId("session-a", 1);
var secondSession = new NodeId("session-b", 1);
var caller = new RoleCarryingUserIdentity(new UserNameIdentityToken { UserName = "reader" }, [], "reader", "key", "v1", null);
var otherKey = new RoleCarryingUserIdentity(new UserNameIdentityToken { UserName = "reader" }, [], "reader", "key", "v2", null);
using var state = new ProjectedBrowseContinuation(parent, firstSession, caller, "cursor-1");
state.TryGetCursor(parent, firstSession, caller, out var original).ShouldBeTrue();
original.ShouldBe("cursor-1");
state.TryGetCursor(parent, secondSession, caller, out _).ShouldBeFalse();
state.TryGetCursor(parent, firstSession, otherKey, out _).ShouldBeFalse();
state.TryGetCursor(new NodeId("other", 2), firstSession, caller, out _).ShouldBeFalse();
state.TryAdvance("cursor-1", "cursor-2", () => false).ShouldBeFalse();
state.TryGetCursor(parent, firstSession, caller, out var stillOriginal).ShouldBeTrue();
stillOriginal.ShouldBe("cursor-1");
state.TryAdvance("cursor-1", "cursor-2", () => true).ShouldBeTrue();
state.TryAdvance("cursor-1", "cursor-3", () => true).ShouldBeFalse();
state.TryGetCursor(parent, firstSession, caller, out var next).ShouldBeTrue();
next.ShouldBe("cursor-2");
}
}