Files
Marc SchierandCopilot bc4c30034d Fix CTT conformance issues #3719, #3720, #3723, #3841 (#3851)
# Description

Fixes four CTT (OPC UA Compliance Test Tool) conformance gaps that the
existing NUnit parity suite was silently passing while the CTT JS
scripts kept failing:

| Issue | Area | Failing CTT script |
|---|---|---|
| #3719 | Base Info Core Structure 2 | `001.js` |
| #3720 | Base Info FiniteStateMachine + StateMachine Instance |
`initialize.js` + `001.js` |
| #3723 | Security None | `007.js` (DoS, partially used channels) |
| #3841 | Alarms & Conditions | Acknowledge Test_003, Alarm Test_002,
Confirm Test_001 / Test_003 / Err_004, Enable Test_002, Non-Exclusive
Limit Test_002 |

Across all four, the underlying pattern was the same — the NUnit parity
tests were checking weaker invariants (DataType attribute instead of
encoded Variant BuiltInType; `Assert.Ignore` instead of `Assert.Fail`;
stub `GetEndpoints` instead of the real DoS scenario; method-call + Read
instead of subscribe-and-validate-event-payload). So the suite gave
false confidence on changes that would have failed CTT. Each commit
below both **strengthens the NUnit parity test** to encode the same
invariant CTT verifies, **and** fixes the server/model defect that the
strengthened test surfaces.

## Commits

### `a1db2984c` Fix #3719 (BaseInfoCoreStructure)

- **Test**: `BaseInfoServerTests.ReadConformanceUnitsAsync` now reads
the **value** of `i=24101` and asserts
`WrappedValue.TypeInfo.BuiltInType == BuiltInType.QualifiedName` AND
`ValueRank == ValueRanks.OneDimension` — not just the DataType
attribute.
- **Test**: `BaseInformationTests.BrowseRequiresMandatoryMethodsAsync`
now `Assert.Fail`s (not `Assert.Ignore`) when an expected mandatory
method is missing on `i=15443` / `i=25440`.
- **Server**: `Server_ServerCapabilities_ConformanceUnits` initialised
with `Array.Empty<QualifiedName>().ToArrayOf()` so the encoded Variant
carries QualifiedName type info even when empty.
- **Server**: Added `AddSecurityGroup` / `RemoveSecurityGroup` (on
`i=15443`) and `AddPushTarget` / `RemovePushTarget` (on `i=25440`)
method nodes with input/output argument metadata and in-memory handlers
in `Quickstarts.Servers/ReferenceServerConfigurationNodeManager`.

### `86d3041e5` Fix #3723 (Security None DoS off-by-one)

- **Server**: Correct off-by-one in
`Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs` channel eviction:
- Condition was `MaxChannelCount == channelCount` (only triggered at
exact equality); now `MaxChannelCount > 0 && channelCount >=
MaxChannelCount` with a loop that evicts idle channels until the count
is below the limit or no more idle channels remain.
- **Server**: `UsedBySession` now properly tracks active sessions and
clears on `CloseSession` (`TcpServerChannel`, `TcpListenerChannel`).
- **Note**: the NUnit reproducer for this issue (`SecurityNoneDosTests`)
stays on the `cttunit` branch (PR #3750) because it depends on the
`TestFixture.CloseSharedFixtureSessionAsync` helper that only exists in
`Tests/Opc.Ua.Conformance.Tests/`. The server fix on this branch is
sufficient to make the CTT JS script pass.

### `2c98390c9` Fix #3720 (BaseInfoStateMachine GeneratesEvent)

- **Model**: Add `GeneratesEvent` forward reference on
`StateMachineType` (i=2299) and `FiniteStateMachineType` (i=2771) →
`AuditUpdateStateEventType` (i=2315) in the design XML
(`Tools/Opc.Ua.SourceGeneration.Core/Design/StandardTypes.xml`);
regenerated `Stack/Opc.Ua.Core/Schema/Opc.Ua.NodeSet2.xml`.
- **Server**: Remove the runtime workaround in `DiagnosticsNodeManager`
that previously injected this reference at load time — now redundant
because the reference ships in the NodeSet at compile time.
- **Test**: New
`BaseInfoStateMachineInstanceTests.StateMachineTypeHasGeneratesEventReferenceAsync`
walks the type hierarchy looking for `GeneratesEvent` with
`IncludeSubtypes=true` and asserts the target resolves to a
`BaseEventType` subtype (matches the CTT walk).
- Per OPC UA Part 16 §4.4.5 / Part 5 §6.4.2.

### `09f551449` Strengthen A&C conformance event tests (#3841)

- **Test fixture**: New `AlarmEventCollector` (476 LOC) — subscribes to
events on `i=Server` with a full A&C event filter (`Comment`, `Retain`,
transition times, all condition-state Ids); per-condition event log;
`WaitForEventAsync(conditionId, predicate, timeout)` for
synchronisation. Uses async `IAsyncDisposable` cleanup.
- **Tests rewritten** to subscribe to events and validate event payload
(`Comment.Text`, `Retain`, `TransitionTime`):
- `Acknowledge Test_003` — empty comment + locale propagates to event
payload; `Retain=false` afterwards
- `Alarm Test_002` — full `ActiveState` cycle Active → Normal with
Acknowledge + Confirm; every transition event validated
- `Confirm Test_001` — unique comment reaches event payload;
`ConfirmedState/Id=true`
- `Confirm Test_003` — Acknowledge → wait event → Confirm with empty
comment
- `Confirm Err_004` — **two concurrent sessions**; second Confirm
asserts specifically `BadConditionBranchAlreadyConfirmed` (not a generic
`BadInvalidState`)
- `Enable Test_002` — Disable + Enable via both type method and
discovered instance method; NO events during disabled period;
`TransitionTime` within call window; `Retain` flips
- `Non-Exclusive Limit Test_002` — mirror for
`NonExclusiveLimitAlarmType`
- **Server fixes** in
`Stack/Opc.Ua.Core.Types/State/AcknowledgeableConditionState.cs`,
`Quickstarts.Servers/Alarms/AlarmHolders/*`, and `AlarmNodeManager` for:
Comment propagation, Retain clearing, TransitionTime updates, and a
dedicated ack-only condition instance
(`AcknowledgeableConditionHolder`).

## Verification

- `dotnet build UA.slnx` — **0 errors**, 42 pre-existing warnings.
- `dotnet test Tests/Opc.Ua.InformationModel.Tests` filtered for the new
+ master `StateMachineGeneratesEvent` / `BaseInfoServer` /
`BaseInformation` tests — **6/6 pass**.
- `dotnet test Tests/Opc.Ua.History.Tests --filter AlarmsAndConditions`
— **141/144 pass**; the 3 occasional failures in
`DisableEnableViaTypeAndInstanceMethodNoEventsDuringDisabledAsync` pass
when re-run in isolation, consistent with the known A&C suite CI
flakiness pattern.

## Related Issues

- Fixes #3719
- Fixes #3720
- Fixes #3723
- Fixes #3841

Related: PR #3750 (`cttunit`) carries the same fixes plus the
conformance-test-project versions of the strengthened NUnit tests.
Either this PR or that one will land first; the other should be rebased
afterwards.

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [x] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [ ] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [x] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-08 07:47:48 +02:00

1136 lines
43 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Opc.Ua.Client.TestFramework;
namespace Opc.Ua.InformationModel.Tests
{
/// <summary>
/// compliance tests for Base Information server-level features:
/// server capabilities, server objects, views, namespaces, system status,
/// and other server-level conformance units.
/// </summary>
[TestFixture]
[Category("Conformance")]
[Category("BaseInfoServer")]
public class BaseInfoServerTests : TestFixture
{
[Test]
public async Task BrowseViewsFolderExistsAsync()
{
DataValue result = await ReadAttributeAsync(
ObjectIds.ViewsFolder, Attributes.BrowseName)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True,
"Views folder should exist.");
}
[Test]
public async Task BrowseTypesFolderSubfoldersAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
ObjectIds.TypesFolder).ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "ObjectTypes"), Is.True,
"ObjectTypes subfolder should exist.");
Assert.That(
HasChildWithName(refs, "VariableTypes"), Is.True,
"VariableTypes subfolder should exist.");
Assert.That(
HasChildWithName(refs, "DataTypes"), Is.True,
"DataTypes subfolder should exist.");
Assert.That(
HasChildWithName(refs, "ReferenceTypes"), Is.True,
"ReferenceTypes subfolder should exist.");
Assert.That(
HasChildWithName(refs, "EventTypes"), Is.True,
"EventTypes subfolder should exist.");
}
[Test]
public async Task VerifyTypeFolderContentsAsync()
{
List<ReferenceDescription> objectTypes = await BrowseForwardAsync(
ObjectIds.ObjectTypesFolder).ConfigureAwait(false);
Assert.That(
HasChildWithName(objectTypes, "BaseObjectType"), Is.True,
"BaseObjectType should be under ObjectTypes.");
List<ReferenceDescription> variableTypes = await BrowseForwardAsync(
ObjectIds.VariableTypesFolder).ConfigureAwait(false);
Assert.That(
HasChildWithName(variableTypes, "BaseVariableType"), Is.True,
"BaseVariableType should be under VariableTypes.");
List<ReferenceDescription> dataTypes = await BrowseForwardAsync(
ObjectIds.DataTypesFolder).ConfigureAwait(false);
Assert.That(
HasChildWithName(dataTypes, "BaseDataType"), Is.True,
"BaseDataType should be under DataTypes.");
List<ReferenceDescription> refTypes = await BrowseForwardAsync(
ObjectIds.ReferenceTypesFolder).ConfigureAwait(false);
Assert.That(
HasChildWithName(refTypes, "References"), Is.True,
"References should be under ReferenceTypes.");
}
[Test]
public async Task BrowseDataTypesFolderAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
ObjectIds.DataTypesFolder).ConfigureAwait(false);
Assert.That(refs, Is.Not.Empty,
"DataTypes folder should contain nodes.");
}
[Test]
public async Task ReadServerProfileArrayAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_ServerProfileArray)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
string[] profiles = result.GetValue<string[]>(null);
Assert.That(profiles, Is.Not.Null,
"ServerProfileArray should be a string array.");
}
[Test]
public async Task ReadLocaleIdArrayAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_LocaleIdArray)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMinSupportedSampleRateAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MinSupportedSampleRate)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxBrowseContinuationPointsAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxBrowseContinuationPoints)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
ushort val = result.WrappedValue.GetUInt16();
Assert.That(val, Is.GreaterThan((ushort)0));
}
[Test]
public async Task ReadMaxQueryContinuationPointsAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxQueryContinuationPoints)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxHistoryContinuationPointsAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MaxHistoryContinuationPoints)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadSoftwareCertificatesAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_SoftwareCertificates)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("SoftwareCertificates not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxArrayLengthAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxArrayLength)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("MaxArrayLength not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxStringLengthAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxStringLength)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("MaxStringLength not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxByteStringLengthAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxByteStringLength)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("MaxByteStringLength not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadOperationLimitsObjectExistsAsync()
{
await AssertNodeExistsAsync(
ObjectIds.Server_ServerCapabilities_OperationLimits,
"OperationLimits").ConfigureAwait(false);
}
[Test]
public async Task ReadMaxSessionsAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerCapabilities_MaxSessions)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("MaxSessions not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxSubscriptionsPerSessionAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MaxSubscriptionsPerSession)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"MaxSubscriptionsPerSession not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxMonitoredItemsPerSubscriptionAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MaxMonitoredItemsPerSubscription)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"MaxMonitoredItemsPerSubscription not supported.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadConformanceUnitsAsync()
{
DataValue result = await ReadAttributeAsync(
new NodeId(24101),
Attributes.BrowseName).ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("ConformanceUnits not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
// Per OPC UA Part 5 §6.3.36, ServerCapabilitiesType.ConformanceUnits
// must be an array of QualifiedName. Issue #3719 surfaced this when
// the DataType attribute wasn't reported as QualifiedName (i=20).
DataValue dataType = await ReadAttributeAsync(
new NodeId(24101),
Attributes.DataType).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(dataType.StatusCode), Is.True,
"DataType attribute should be readable.");
Assert.That(
dataType.WrappedValue.GetNodeId(),
Is.EqualTo(DataTypeIds.QualifiedName),
"ConformanceUnits DataType must be QualifiedName per Part 5 §6.3.36.");
DataValue value = await ReadNodeValueAsync(new NodeId(24101)).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(value.StatusCode), Is.True,
"ConformanceUnits Value should be readable.");
TypeInfo valueTypeInfo = value.WrappedValue.TypeInfo;
Assert.That(valueTypeInfo.BuiltInType, Is.EqualTo(BuiltInType.QualifiedName),
"ConformanceUnits Value Variant must be encoded as QualifiedName[].");
Assert.That(valueTypeInfo.ValueRank, Is.EqualTo(ValueRanks.OneDimension),
"ConformanceUnits Value Variant must be a one-dimensional array.");
}
[Test]
public async Task ReadMaxMonitoredItemsQueueSize()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MaxMonitoredItemsQueueSize)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxMonitoredItemsPerCallCreate()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxMonitoredItemsPerCallModify()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
uint val = result.WrappedValue.GetUInt32();
Assert.That(val, Is.GreaterThanOrEqualTo((uint)0));
}
[Test]
public async Task ReadMaxMonitoredItemsPerCallSetMode()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxMonitoredItemsPerCallDelete()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxMonitoredItemsPerCallSetTriggering()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifyLimitsEnforcement()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
uint limit = result.WrappedValue.GetUInt32();
Assert.That(limit, Is.GreaterThanOrEqualTo((uint)0),
"Limit should be defined.");
}
[Test]
public async Task VerifySetTriggeringLinksToAddLimits()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifySetTriggeringLinksToRemoveLimits()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxMonitoredItemsPerCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseNamespacesAndReadUaMetadataAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
ObjectIds.Server_Namespaces).ConfigureAwait(false);
Assert.That(refs, Is.Not.Empty,
"Namespaces folder should have children.");
ReferenceDescription uaNs = refs.FirstOrDefault(
r => r.BrowseName.Name == "http://opcfoundation.org/UA/");
if (uaNs == null)
{
Assert.Fail(
"UA namespace entry not found in Namespaces.");
}
var uaNsId = ExpandedNodeId.ToNodeId(
uaNs.NodeId, Session.NamespaceUris);
List<ReferenceDescription> children =
await BrowseForwardAsync(uaNsId).ConfigureAwait(false);
Assert.That(children, Is.Not.Empty);
}
[Test]
public async Task BrowseNamespacesFolderTypeIsNamespacesTypeAsync()
{
DataValue result = await ReadAttributeAsync(
ObjectIds.Server_Namespaces,
Attributes.BrowseName).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseNamespaceEntriesHaveNamespaceUriAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
ObjectIds.Server_Namespaces).ConfigureAwait(false);
Assert.That(refs, Is.Not.Empty);
var firstNsId = ExpandedNodeId.ToNodeId(
refs[0].NodeId, Session.NamespaceUris);
List<ReferenceDescription> props =
await BrowseForwardAsync(firstNsId).ConfigureAwait(false);
Assert.That(
HasChildWithName(props, "NamespaceUri"), Is.True,
"Namespace entry should have NamespaceUri property.");
}
[Test]
public async Task ReadServerStatusStateIsRunningAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus_State)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
int state = result.WrappedValue.GetInt32();
Assert.That(state,
Is.EqualTo((int)ServerState.Running));
}
[Test]
public async Task ReadServerStatusStartTimeAndCurrentTimeAsync()
{
DataValue startResult = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus_StartTime)
.ConfigureAwait(false);
Assert.That(
StatusCode.IsGood(startResult.StatusCode), Is.True);
DateTime startTime;
if (startResult.WrappedValue.TryGetValue(out DateTimeUtc dtuStart))
{
startTime = dtuStart.ToDateTime();
}
else
{
startTime = startResult.WrappedValue.GetDateTime().ToDateTime();
}
Assert.That(startTime, Is.Not.EqualTo(DateTime.MinValue));
DataValue currentResult = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus_CurrentTime)
.ConfigureAwait(false);
Assert.That(
StatusCode.IsGood(currentResult.StatusCode), Is.True);
DateTime currentTime;
if (currentResult.WrappedValue.TryGetValue(out DateTimeUtc dtuCurrent))
{
currentTime = dtuCurrent.ToDateTime();
}
else
{
currentTime = currentResult.WrappedValue.GetDateTime().ToDateTime();
}
Assert.That(currentTime, Is.GreaterThanOrEqualTo(startTime));
}
[Test]
public async Task ReadServerStatusSecondsTillShutdownAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus_SecondsTillShutdown)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadBuildInfoProductName()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerStatus_BuildInfo_ProductName)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
string productName = result.GetValue<string>(null);
Assert.That(productName, Is.Not.Null.And.Not.Empty);
}
[Test]
public async Task ReadBuildInfoManufacturerName()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerStatus_BuildInfo_ManufacturerName)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
string manufacturerName = result.GetValue<string>(null);
Assert.That(manufacturerName, Is.Not.Null.And.Not.Empty);
}
[Test]
public async Task BrowseServerTypeChildrenAsync()
{
List<ReferenceDescription> refs =
await BrowseForwardAsync(ServerTypeId)
.ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "ServerCapabilities"), Is.True,
"ServerType should have ServerCapabilities.");
Assert.That(
HasChildWithName(refs, "ServerDiagnostics"), Is.True,
"ServerType should have ServerDiagnostics.");
Assert.That(
HasChildWithName(refs, "ServerStatus"), Is.True,
"ServerType should have ServerStatus.");
Assert.That(
HasChildWithName(refs, "ServerRedundancy"), Is.True,
"ServerType should have ServerRedundancy.");
}
[Test]
public async Task BrowseFiniteStateMachineTypeForStatesAndTransitions()
{
List<ReferenceDescription> refs =
await BrowseForwardAsync(FiniteStateMachineTypeId)
.ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "AvailableStates"), Is.True,
"FiniteStateMachineType should have AvailableStates.");
Assert.That(
HasChildWithName(refs, "AvailableTransitions"), Is.True,
"FiniteStateMachineType should have AvailableTransitions.");
}
[Test]
public async Task DeprecatedPropertyExistsAsync()
{
await AssertNodeExistsAsync(DeprecatedId, "Deprecated")
.ConfigureAwait(false);
}
[Test]
public async Task EUInformationStructureExistsAsync()
{
await AssertNodeExistsAsync(EUInformationId, "EUInformation")
.ConfigureAwait(false);
}
[Test]
public async Task BrowseAnalogItemTypeForEngineeringUnitsAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
VariableTypeIds.AnalogItemType).ConfigureAwait(false);
if (!HasChildWithName(refs, "EngineeringUnits"))
{
Assert.Ignore("AnalogItemType EngineeringUnits not available in ReferenceServer.");
}
}
[Test]
public async Task ReadEngineeringUnitsValueAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
VariableTypeIds.AnalogItemType).ConfigureAwait(false);
ReferenceDescription euRef = refs.FirstOrDefault(
r => r.BrowseName.Name == "EngineeringUnits");
if (euRef == null)
{
Assert.Ignore("AnalogItemType EngineeringUnits not available in ReferenceServer.");
}
var euId = ExpandedNodeId.ToNodeId(
euRef.NodeId, Session.NamespaceUris);
DataValue result = await ReadNodeValueAsync(euId)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadEURangeAndVerifyStructureAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
VariableTypeIds.AnalogItemType).ConfigureAwait(false);
ReferenceDescription rangeRef = refs.FirstOrDefault(
r => r.BrowseName.Name == "EURange");
Assert.That(rangeRef, Is.Not.Null,
"EURange not found on AnalogItemType.");
var rangeId = ExpandedNodeId.ToNodeId(
rangeRef.NodeId, Session.NamespaceUris);
DataValue result = await ReadNodeValueAsync(rangeId)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseServerTypeForEstimatedReturnTimeAsync()
{
List<ReferenceDescription> refs =
await BrowseForwardAsync(ServerTypeId)
.ConfigureAwait(false);
bool found = HasChildWithName(
refs, "EstimatedReturnTime");
if (!found)
{
Assert.Fail(
"EstimatedReturnTime not found on ServerType.");
}
}
[Test]
public async Task ReadEstimatedReturnTimeValueAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_EstimatedReturnTime)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"EstimatedReturnTime not available.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseServerCapabilitiesForEventPropertiesAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
ObjectIds.Server_ServerCapabilities)
.ConfigureAwait(false);
Assert.That(refs, Is.Not.Empty,
"ServerCapabilities should have children.");
}
[Test]
public async Task ExportNamespaceMethodExistsAsync()
{
await AssertNodeExistsAsync(ExportNsId, "ExportNamespace")
.ConfigureAwait(false);
}
[Test]
public async Task ImportNamespaceMethodExistsAsync()
{
await AssertNodeExistsAsync(ImportNsId, "ImportNamespace")
.ConfigureAwait(false);
}
[Test]
public async Task BrowseFiniteStateMachineTypeForCurrentState()
{
List<ReferenceDescription> refs =
await BrowseForwardAsync(FiniteStateMachineTypeId)
.ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "CurrentState"), Is.True,
"FiniteStateMachineType should have CurrentState.");
}
[Test]
public async Task ReadMinSupportedSampleRateFixedAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MinSupportedSampleRate)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task HistoryServerCapabilitiesNodeExists()
{
await AssertNodeExistsAsync(
HistoryCapsId, "HistoryServerCapabilities")
.ConfigureAwait(false);
}
[Test]
public async Task ReadAccessHistoryDataCapability()
{
DataValue result = await ReadNodeValueAsync(AccessHistDataId)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadAccessHistoryEventsCapability()
{
DataValue result = await ReadNodeValueAsync(
AccessHistEventsId).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadInsertDataCapability()
{
DataValue result = await ReadNodeValueAsync(InsertDataCapId)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadInsertEventCapability()
{
DataValue result = await ReadNodeValueAsync(InsertEventCapId)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseServerForLocationsObjectAsync()
{
// Per Part 5 §8.2.12 the standard "Locations" object (i=31915)
// is organized from the Objects folder (i=85), not from the
// Server node (i=2253). Browse the Objects folder forward to
// locate it.
List<ReferenceDescription> refs =
await BrowseForwardAsync(ObjectIds.ObjectsFolder)
.ConfigureAwait(false);
if (!HasChildWithName(refs, "Locations"))
{
Assert.Ignore("Locations object not found.");
}
}
[Test]
public async Task ReadMaxNodesPerMethodCallAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxNodesPerMethodCall)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifyModelChangeStructureDataTypeExistsAsync()
{
DataValue result = await ReadAttributeAsync(
new NodeId(DataTypes.ModelChangeStructureDataType),
Attributes.BrowseName).ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"ModelChangeStructureDataType not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifyGeneralModelChangeEventTypeExistsAsync()
{
DataValue result = await ReadAttributeAsync(
ObjectTypeIds.GeneralModelChangeEventType,
Attributes.BrowseName).ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"GeneralModelChangeEventType not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifyOrderedListTypeExists()
{
DataValue result = await ReadAttributeAsync(
OrderedListTypeId, Attributes.BrowseName)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("OrderedListType not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxNodesPerNodeManagement()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxNodesPerNodeManagement)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadAddNodesLimit()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxNodesPerNodeManagement)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadDeleteReferencesLimit()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxNodesPerNodeManagement)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadDeleteNodesLimit()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_OperationLimits_MaxNodesPerNodeManagement)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ReadMaxQueryContinuationPointsQueryAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds
.Server_ServerCapabilities_MaxQueryContinuationPoints)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseStateMachineTypeForCurrentStateAsync()
{
List<ReferenceDescription> refs =
await BrowseForwardAsync(StateMachineTypeId)
.ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "CurrentState"), Is.True,
"StateMachineType should have CurrentState.");
}
[Test]
public async Task ReadServerStatusSubvariablesExist()
{
DataValue statusResult = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus)
.ConfigureAwait(false);
Assert.That(
StatusCode.IsGood(statusResult.StatusCode), Is.True);
List<ReferenceDescription> refs = await BrowseForwardAsync(
VariableIds.Server_ServerStatus)
.ConfigureAwait(false);
Assert.That(refs, Is.Not.Empty,
"ServerStatus should have subvariables.");
Assert.That(
HasChildWithName(refs, "StartTime"), Is.True,
"ServerStatus should have StartTime.");
Assert.That(
HasChildWithName(refs, "CurrentTime"), Is.True,
"ServerStatus should have CurrentTime.");
Assert.That(
HasChildWithName(refs, "State"), Is.True,
"ServerStatus should have State.");
}
[Test]
public async Task SemanticChangeEventTypeExistsAsync()
{
await AssertNodeExistsAsync(
SemanticChangeEventTypeId, "SemanticChangeEventType")
.ConfigureAwait(false);
}
[Test]
public async Task VerifySemanticChangeBitAsync()
{
DataValue result = await ReadAttributeAsync(
SemanticChangeEventTypeId, Attributes.BrowseName)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"SemanticChangeEventType not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ChoiceStateTypeExistsAsync()
{
DataValue result = await ReadAttributeAsync(
ObjectTypeIds.ChoiceStateType, Attributes.BrowseName)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail("ChoiceStateType not found.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task TimeZoneDataTypeExistsAsync()
{
await AssertNodeExistsAsync(
new NodeId(DataTypes.TimeZoneDataType),
"TimeZoneDataType").ConfigureAwait(false);
}
[Test]
public async Task ReadServerStatusCurrentTimeAndCheckTimeZoneAsync()
{
DataValue result = await ReadNodeValueAsync(
VariableIds.Server_ServerStatus_CurrentTime)
.ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task VerifyLocalTimeEventFieldAvailableAsync()
{
DataValue result = await ReadAttributeAsync(
ObjectTypeIds.BaseEventType, Attributes.BrowseName)
.ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Fail(
"LocalTime event field not available.");
}
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task BrowseMultiStateDiscreteTypeForValueAsTextAsync()
{
// ValueAsText is a mandatory property of MultiStateValueDiscreteType
// (i=11238) per Part 8 §5.3.3.4. The plain MultiStateDiscreteType
// (i=2376) only declares EnumStrings. The test name is historical;
// the conformance unit "Base Info ValueAsText" targets the
// MultiStateValueDiscreteType. The previous hardcoded NodeId 2688
// does not exist in the standard nodeset.
List<ReferenceDescription> refs =
await BrowseForwardAsync(VariableTypeIds.MultiStateValueDiscreteType)
.ConfigureAwait(false);
if (!HasChildWithName(refs, "ValueAsText"))
{
Assert.Ignore("MultiStateValueDiscreteType ValueAsText not available in ReferenceServer.");
}
}
[Test]
public async Task VerifyMultiStateValueDiscreteTypeEnumValuesAsync()
{
List<ReferenceDescription> refs = await BrowseForwardAsync(
VariableTypeIds.MultiStateValueDiscreteType)
.ConfigureAwait(false);
Assert.That(
HasChildWithName(refs, "EnumValues"), Is.True,
"MultiStateValueDiscreteType should have EnumValues.");
}
[Test]
public async Task ModellingRuleMandatoryPlaceholderExists()
{
DataValue result = await ReadAttributeAsync(
ObjectIds.ModellingRule_MandatoryPlaceholder,
Attributes.BrowseName).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
[Test]
public async Task ModellingRuleOptionalPlaceholderExists()
{
DataValue result = await ReadAttributeAsync(
ObjectIds.ModellingRule_OptionalPlaceholder,
Attributes.BrowseName).ConfigureAwait(false);
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
}
private static readonly NodeId FiniteStateMachineTypeId = new(2771);
private static readonly NodeId StateMachineTypeId = new(2299);
private static readonly NodeId ServerTypeId = new(2004);
private static readonly NodeId SemanticChangeEventTypeId = new(2738);
private static readonly NodeId OrderedListTypeId = new(23518);
private static readonly NodeId DeprecatedId = new(23562);
private static readonly NodeId EUInformationId = new(887);
private static readonly NodeId ExportNsId = new(11615);
private static readonly NodeId ImportNsId = new(11616);
private static readonly NodeId HistoryCapsId = new(11192);
private static readonly NodeId AccessHistDataId = new(11193);
private static readonly NodeId AccessHistEventsId = new(11242);
private static readonly NodeId InsertDataCapId = new(11196);
private static readonly NodeId InsertEventCapId = new(11281);
private async Task<DataValue> ReadNodeValueAsync(NodeId nodeId)
{
ReadResponse response = await Session.ReadAsync(
null, 0, TimestampsToReturn.Both,
new ReadValueId[]
{
new() {
NodeId = nodeId,
AttributeId = Attributes.Value
}
}.ToArrayOf(),
CancellationToken.None).ConfigureAwait(false);
Assert.That(response.Results.Count, Is.EqualTo(1));
return response.Results[0];
}
private async Task<DataValue> ReadAttributeAsync(
NodeId nodeId, uint attributeId)
{
ReadResponse response = await Session.ReadAsync(
null, 0, TimestampsToReturn.Both,
new ReadValueId[]
{
new() {
NodeId = nodeId,
AttributeId = attributeId
}
}.ToArrayOf(),
CancellationToken.None).ConfigureAwait(false);
Assert.That(response.Results.Count, Is.EqualTo(1));
return response.Results[0];
}
private async Task<List<ReferenceDescription>> BrowseForwardAsync(
NodeId nodeId,
NodeId referenceTypeId = default)
{
NodeId refType = referenceTypeId.IsNull
? ReferenceTypeIds.HierarchicalReferences
: referenceTypeId;
BrowseResponse response = await Session.BrowseAsync(
null, null, 0,
new BrowseDescription[]
{
new() {
NodeId = nodeId,
BrowseDirection = BrowseDirection.Forward,
ReferenceTypeId = refType,
IncludeSubtypes = true,
NodeClassMask = 0,
ResultMask = (uint)BrowseResultMask.All
}
}.ToArrayOf(),
CancellationToken.None).ConfigureAwait(false);
Assert.That(response.Results.Count, Is.EqualTo(1));
var refs = new List<ReferenceDescription>();
if (response.Results[0].References != default)
{
foreach (ReferenceDescription r in response.Results[0].References)
{
refs.Add(r);
}
}
return refs;
}
private async Task AssertNodeExistsAsync(NodeId nodeId, string name)
{
DataValue result = await ReadAttributeAsync(
nodeId, Attributes.BrowseName).ConfigureAwait(false);
if (StatusCode.IsBad(result.StatusCode))
{
Assert.Ignore($"{name} not found.");
}
}
private static bool HasChildWithName(
List<ReferenceDescription> references, string name)
{
return references.Any(r => r.BrowseName.Name == name);
}
}
}