mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-21 09:06:37 +08:00
5b9bcedc62
# Description Adds first-class support for the OPC UA ISA-95 companion specifications: - OPC-10030 Common Model. - OPC-10031-4 Job Control V1. - OPC-10031-4 Job Control V2. The change introduces `Opc.Ua.ISA95`, `Opc.Ua.ISA95.Client`, and `Opc.Ua.ISA95.Server`, together with a NativeAOT-compatible minimal server sample and comprehensive tests. ## Highlights - Compiles the three canonical NodeSets and identifier mapping CSV files through the source generator. - Adds NodeSet identifier mapping validation, typed method arguments/results, companion event records, and generated method argument nodes. - Provides typed Common Model builders with normative relationships and an injectable `GeoSpatialLocationType` provider. - Implements lossless V1/V2 Job Control providers over a shared version-neutral store, including state paths, status events, comments, response queries, catalog changes, and cohesive DI registration. - Adds subtype-aware typed clients, standalone encodeable registration, `IIsa95ClientFactory`, and V2 status-event streaming. - Adds the `MinimalIsa95Server` sample, package documentation, and an ISA-95 guide with conformance and HA guidance. - Tracks typed RSL/GPOS integration as follow-up issue #4095. ## Validation - `Opc.Ua.ISA95.Tests`: 137/137 passed on `net10.0` and `net48`. - Source-generator suites: 81/81 model, 90/90 stack, 3718 passed / 8 skipped core. - `EventRecordFieldReaders` feedback tests: 6/6 on `net10.0` and `net48`. - `EventRecordFieldReaders` changed-method patch coverage: 100% line coverage (36/36) and 100% branch coverage (22/22). - `Opc.Ua.ISA95`, `.Client`, and `.Server` build across all configured target frameworks without new diagnostics. - Cobertura line coverage: 88.08% model, 90.04% client, 91.19% server. - NativeAOT sample publishes and passes a live typed V2 Store/status-event validation. - The ISA-95 NativeAOT smoke test passes in the source-generated native test executable. - OPC UA KB NodeSet validation reports zero errors for Common, V1, and V2. The broader NativeAOT executable still reports unrelated existing GDS and complex-type test failures; the ISA-95-specific native test passes. ## Node state generator fixes Generating method arguments inline for imported nodesets regressed every model that already emits `InputArguments` / `OutputArguments` child node factories: - The inline block ran before the child factories. `MethodState.CreateOrReplaceInputArguments` keeps the property that was assigned first, so the child carrying the well-known NodeId was dropped and a NodeId-less placeholder remained in the address space. This broke browsing (reference descriptions without a target) and made method arguments unreachable at their well-known NodeIds. - The `MethodDeclarationId` fallback keyed on an autogenerated display name redirected every declared method of the standard address space to its own NodeId, which made method calls fail. The inline block is now emitted after the child factories and reduced to a value assignment when a child factory exists. The value is only re-emitted when an argument references a namespace other than OPC UA, because the value of an imported property is the verbatim XML of the source nodeset whose namespace indices do not survive the import. The `MethodDeclarationId` fallback is restricted to declarations without a resolvable NodeId. The generated OPC UA address space is byte-identical to `master` again. ## Related Issues - Fixes #4088 - Follow-up: #4095
181 lines
7.1 KiB
C#
181 lines
7.1 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/
|
|
* ======================================================================*/
|
|
|
|
#nullable enable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Client.Subscriptions;
|
|
using Opc.Ua.Client.Subscriptions.MonitoredItems;
|
|
using Opc.Ua.Client.Subscriptions.Streaming;
|
|
|
|
// Tests run on the default TaskScheduler so CA2007's sync-context risk does not apply.
|
|
#pragma warning disable CA2007
|
|
|
|
namespace Opc.Ua.Client.Tests.Streaming
|
|
{
|
|
/// <summary>
|
|
/// Deterministic null-guard tests for <see cref="StreamingSubscription"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Full lazy <c>EnsureSubscriptionAsync</c> / monitored-item routing /
|
|
/// dispose coverage requires a real <c>ISubscriptionManager</c> +
|
|
/// <c>ISubscription</c> pipeline and lives in the integration test
|
|
/// suite. Only the cheap argument-validation guards are exercised
|
|
/// here.
|
|
/// </remarks>
|
|
[TestFixture]
|
|
[Category("Client")]
|
|
[Category("StreamingExtensions")]
|
|
[Parallelizable]
|
|
public sealed class StreamingSubscriptionTests
|
|
{
|
|
[Test]
|
|
public void ConstructorWithNullSubscriptionManagerThrowsArgumentNullException()
|
|
{
|
|
Assert.That(
|
|
() => new StreamingSubscription(null!),
|
|
Throws.ArgumentNullException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubscribeDataChangesAsyncWithNullNodeIdThrowsArgumentNullException()
|
|
{
|
|
await using var sub = new StreamingSubscription(NewStubManager());
|
|
|
|
// NodeId.Null is the canonical "null" value of the INullable
|
|
// struct. The production guard checks nodeId.IsNull and throws
|
|
// synchronously before any subscription-manager interaction.
|
|
Assert.That(
|
|
() => sub.SubscribeDataChangesAsync(NodeId.Null),
|
|
Throws.ArgumentNullException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubscribeDataChangesAsyncWithNullNodeIdsListThrowsArgumentNullException()
|
|
{
|
|
await using var sub = new StreamingSubscription(NewStubManager());
|
|
|
|
Assert.That(
|
|
() => sub.SubscribeDataChangesAsync(null!),
|
|
Throws.ArgumentNullException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubscribeEventsAsyncWithNullNotifierIdThrowsArgumentNullException()
|
|
{
|
|
await using var sub = new StreamingSubscription(NewStubManager());
|
|
|
|
Assert.That(
|
|
() => sub.SubscribeEventsAsync(NodeId.Null, new EventFilter()),
|
|
Throws.ArgumentNullException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubscribeEventsAsyncWithNullFilterThrowsArgumentNullException()
|
|
{
|
|
await using var sub = new StreamingSubscription(NewStubManager());
|
|
|
|
Assert.That(
|
|
() => sub.SubscribeEventsAsync(ObjectIds.Server, null!),
|
|
Throws.ArgumentNullException);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubscribeEventsAsyncWhenMonitoredItemCannotBeAddedThrowsAsync()
|
|
{
|
|
IMonitoredItem? monitoredItem = null;
|
|
var monitoredItems = new Mock<IMonitoredItemCollection>();
|
|
monitoredItems
|
|
.Setup(items => items.TryAdd(
|
|
It.IsAny<string>(),
|
|
It.IsAny<IOptionsMonitor<
|
|
Subscriptions.MonitoredItems.MonitoredItemOptions>>(),
|
|
out monitoredItem))
|
|
.Returns(false);
|
|
var subscription = new Mock<ISubscription>();
|
|
subscription.SetupGet(value => value.MonitoredItems).Returns(monitoredItems.Object);
|
|
var manager = new Mock<ISubscriptionManager>();
|
|
IOptionsMonitor<Subscriptions.SubscriptionOptions>? capturedOptions =
|
|
null;
|
|
manager
|
|
.Setup(value => value.Add(
|
|
It.IsAny<ISubscriptionNotificationHandler>(),
|
|
It.IsAny<
|
|
IOptionsMonitor<Subscriptions.SubscriptionOptions>>()))
|
|
.Callback<
|
|
ISubscriptionNotificationHandler,
|
|
IOptionsMonitor<Subscriptions.SubscriptionOptions>>(
|
|
(_, options) => capturedOptions = options)
|
|
.Returns(subscription.Object);
|
|
|
|
await using var streaming = new StreamingSubscription(
|
|
manager.Object,
|
|
new Subscriptions.SubscriptionOptions
|
|
{
|
|
PublishingInterval = TimeSpan.FromSeconds(2)
|
|
});
|
|
await using IAsyncEnumerator<EventNotification> enumerator = streaming
|
|
.SubscribeEventsAsync(ObjectIds.Server, new EventFilter())
|
|
.GetAsyncEnumerator();
|
|
|
|
InvalidOperationException? exception = null;
|
|
try
|
|
{
|
|
await enumerator.MoveNextAsync().ConfigureAwait(false);
|
|
}
|
|
catch (InvalidOperationException caught)
|
|
{
|
|
exception = caught;
|
|
}
|
|
|
|
Assert.That(exception, Is.Not.Null);
|
|
Assert.That(
|
|
capturedOptions?.CurrentValue.PublishingEnabled,
|
|
Is.True);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stub subscription manager — its methods are never invoked
|
|
/// because the argument guards trip synchronously before
|
|
/// <c>EnsureSubscriptionAsync</c> is entered. Using a loose
|
|
/// <see cref="Mock{T}"/> avoids hand-implementing every
|
|
/// member of the <see cref="ISubscriptionManager"/> surface.
|
|
/// </summary>
|
|
private static ISubscriptionManager NewStubManager()
|
|
{
|
|
return new Mock<ISubscriptionManager>(MockBehavior.Loose).Object;
|
|
}
|
|
}
|
|
}
|