mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 07:07:24 +08:00
# Description The CTT AliasName conformance units skip or fail against the ConsoleReferenceServer. `AliasName Base` skips with *"No instance of AliasNameType has been found in the address space"*; `Category Tags`, `Category Topics` and `Hierarchy` fail. Part 17 support landed in #3779, but aliases live only inside the `IAliasNameStore` — nothing is browsable, no `AliasNameCategoryType` is nested under another, and the Topics aliases point at the Server object rather than at a `PublishedDataSetType` instance. Part 17 §6.2 clients — the CTT among them — discover aliases by browsing, not only by calling `FindAlias`. This PR materializes the store contents as real nodes and fills the three gaps. ### SDK — `Opc.Ua.Server` * **`DiagnosticsNodeManager.MaterializeRegisteredAliasNameNodesAsync`** (new, opt-in) walks every registered `IAliasNameStore` and creates one `AliasNameType` instance per alias — BrowseName carrying the alias name, `AliasFor` references to its targets, and the inverse `HasAlias` reference on each local target (via `externalReferences`, since targets usually live in another node manager) — plus an `AliasNameCategoryType` instance for every store category the standard NodeSet does not already ship. Categories whose NodeId belongs to another node manager are skipped, so an `AliasNameNodeManager` that also registers its store with the server-wide registry does not get its NodeIds claimed twice. Opt-in: servers that only need the well-known `FindAlias` to answer from their store pay nothing. The nodes are a snapshot taken at address-space creation — later mutations change what `FindAlias` returns but do not add or remove nodes. * **Optional Part 17 methods on the well-known categories.** The same pass instantiates whatever a category declares through `AliasNameCapabilities`: `FindAliasVerbose` (§6.3.3), `AddAliasesToCategory` (§6.3.4), `DeleteAliasesFromCategory` (§6.3.5) and `LastChange` (§6.3.1). Mutations require a `SecurityAdmin` caller on a `SignAndEncrypt` channel; the gate previously private to `AliasNameNodeManager` moved to `AliasNameMethodDispatcher` so both paths share one implementation. * **`LastChange`** is now tracked per category rather than only for the standard `Aliases` node, and the duplicated seeding logic collapsed into one helper. ### Reference server * A nested **`Devices`** category under `TagVariables` holds `Pump1_Status` and `Heater_Power`. `FindAlias` on `TagVariables` still returns all six names through subtree recursion, while `FindAlias` on `Devices` returns exactly two — which is what the Hierarchy unit checks. * `ReferenceServerConfigurationNodeManager` creates three **`PublishedDataSet` instances** under `PublishedDataSets` (`i=17371`) and the Topics aliases now target them, satisfying the *"is a Dataset"* check. These are address-space instances only — no PubSub runtime is added, and the CTT only inspects the target's type definition. ## Note for reviewers — the reserved NodeIds The optional children are created at the NodeIds the OPC Foundation reserves for them (`Aliases.FindAliasVerbose` = `i=24054`, `TagVariables.LastChange` = `i=32854`, …). Those identifiers are allocated in `StandardTypes.csv` but are **not** declared in the ModelDesign and **not** present in the published NodeSet, because the standard address space does not instantiate optional children. The source generator therefore emits no parent-to-instance mapping and no `MethodIds` constants for them, so `DiagnosticsNodeManager.ReservedChildIds` supplies the nine method ids and the two missing `LastChange` ids explicitly, each traceable to its registry row. The 18 argument-property ids do have generated `VariableIds` constants and are referenced through those. I deliberately did **not** "fix" this by declaring the children in `tools/Opc.Ua.SourceGeneration.Core/Design/StandardTypes.xml`: that file is a verbatim copy of upstream `UA-ModelCompiler/Design.v105/StandardTypes.xml` (the only differences today are upstream being newer), so a local edit is lost on the next sync and the NodeIds would silently revert to factory-minted ones. `docs/AliasNames.md` records this. Worth raising upstream separately: `StandardTypes.csv` allocates `Aliases_FindAliasVerbose` and siblings while the ModelDesign never declares those children, so the ModelCompiler cannot emit ids it has itself reserved. If that is ever reconciled, `ReservedChildIds` becomes redundant and deletes cleanly. ## Related Issues - Fixes #4012 ## Checklist - [x] 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. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [ ] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. — **not done: verified on net8.0 only** (Server 4710, InformationModel 1099, Core 4443, plus the client and features alias suites; AOT build clean). Needs a run against net framework and net10 before this leaves draft. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. ### Tests `tests/Opc.Ua.InformationModel.Tests/Aliasname*Tests.cs` mirror the four CTT conformance units and no longer `Assert.Ignore` where the CTT reported failures — the alias suite is 37 tests with no skips. New `AliasnameOptionalMethodsTests` covers the optional methods, their reserved NodeIds, the anonymous-caller denial, an add/find/delete round trip and `LastChange` advancing on mutation. One pre-existing test changed premise: `EnumerateSubCategoriesAsyncOnLeafReturnsEmptyAsync` asserted that `TagVariables` has no sub-categories, which this PR deliberately makes false. It now targets `Topics` (still a leaf) and a new test guards the nesting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: romanett <7413710+romanett@users.noreply.github.com> Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
516 lines
23 KiB
C#
516 lines
23 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.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Server.AliasNames;
|
|
|
|
namespace Opc.Ua.Server.Tests.AliasNames
|
|
{
|
|
/// <summary>
|
|
/// Coverage tests for <see cref="InMemoryAliasNameStore"/> — including
|
|
/// per-entry status codes, mismatched-input handling,
|
|
/// <c>LastChange</c> monotonicity (Part 17 §6.3.1) and sub-category
|
|
/// cascading on FindAlias (Part 17 §6.3.2).
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("AliasNames")]
|
|
[Parallelizable]
|
|
public class InMemoryAliasNameStoreTests
|
|
{
|
|
private static readonly NodeId s_root = new("Root", 2);
|
|
private static readonly NodeId s_child = new("Child", 2);
|
|
private static readonly ExpandedNodeId s_t1 = new("T1", 2);
|
|
private static readonly ExpandedNodeId s_t2 = new("T2", 2);
|
|
private static readonly ExpandedNodeId s_t3 = new("T3", 2);
|
|
|
|
private static InMemoryAliasNameStore CreateStore(
|
|
bool withSubCategory = false,
|
|
AliasNameCapabilities capabilities =
|
|
AliasNameCapabilities.AddAliasesToCategory |
|
|
AliasNameCapabilities.DeleteAliasesFromCategory |
|
|
AliasNameCapabilities.LastChange)
|
|
{
|
|
AliasNameCategoryDescriptor[] subs = withSubCategory
|
|
?
|
|
[
|
|
new AliasNameCategoryDescriptor(
|
|
s_child,
|
|
new QualifiedName("Child", 2),
|
|
capabilities)
|
|
]
|
|
: null;
|
|
var root = new AliasNameCategoryDescriptor(
|
|
s_root,
|
|
new QualifiedName("Root", 2),
|
|
capabilities,
|
|
subs);
|
|
return new InMemoryAliasNameStore([root]);
|
|
}
|
|
|
|
private static TypeTable EmptyTypeTree()
|
|
{
|
|
return new(new NamespaceTable());
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddAndFindRoundTripAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest("Temp", s_t1, null,
|
|
ReferenceTypeIds.AliasFor)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
IReadOnlyList<AliasNameDataType> result = await store
|
|
.FindAliasAsync(s_root, "Temp", NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].AliasName.Name, Is.EqualTo("Temp"));
|
|
Assert.That(result[0].ReferencedNodes.Count, Is.EqualTo(1));
|
|
Assert.That(result[0].ReferencedNodes[0], Is.EqualTo(s_t1));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DuplicateAddReturnsBadBrowseNameDuplicatedAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] first = await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest("X", s_t1, null,
|
|
ReferenceTypeIds.AliasFor)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(first[0].Code, Is.EqualTo(StatusCodes.Good));
|
|
|
|
StatusCode[] second = await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest("X", s_t1, null,
|
|
ReferenceTypeIds.AliasFor)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(second[0].Code, Is.EqualTo(StatusCodes.BadBrowseNameDuplicated));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteMissingReturnsBadNotFoundAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("Ghost", s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadNotFound));
|
|
}
|
|
|
|
[Test]
|
|
public async Task LastChangeAdvancesMonotonicallyPerBatchAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)0));
|
|
|
|
await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest("A", s_t1, null, ReferenceTypeIds.AliasFor),
|
|
new AliasAddRequest("B", s_t2, null, ReferenceTypeIds.AliasFor)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)1),
|
|
"Batch with two successes must bump LastChange exactly once.");
|
|
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("C", s_t3, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)2));
|
|
|
|
await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("Missing", s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)2),
|
|
"All-fail batch must NOT bump LastChange.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task ChangedEventCarriesCategoryAndVersionAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
AliasStoreChangedEventArgs captured = null;
|
|
store.Changed += (_, e) => captured = e;
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(captured, Is.Not.Null);
|
|
Assert.That(captured.CategoryId, Is.EqualTo(s_root));
|
|
Assert.That(captured.LastChange, Is.EqualTo(1u));
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubCategoryMutationBumpsAncestorLastChangeAsync()
|
|
{
|
|
// Part 17 §6.3.1/§9.2: a category's LastChange reflects the
|
|
// most recent change anywhere in its subtree, and the root
|
|
// value reflects any change at all — so a mutation on a nested
|
|
// category advances the parent's LastChange too, with a
|
|
// Changed notification per bumped category.
|
|
using InMemoryAliasNameStore store = CreateStore(withSubCategory: true);
|
|
var events = new List<AliasStoreChangedEventArgs>();
|
|
store.Changed += (_, e) => events.Add(e);
|
|
|
|
await store.AddAliasesAsync(s_child,
|
|
[new AliasAddRequest("SubX", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(store.GetLastChange(s_child), Is.EqualTo((uint?)1),
|
|
"The mutated category bumps.");
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)1),
|
|
"The ancestor category bumps as well.");
|
|
Assert.That(events, Has.Count.EqualTo(2));
|
|
Assert.That(events[0].CategoryId, Is.EqualTo(s_child),
|
|
"The mutated category notifies first.");
|
|
Assert.That(events[1].CategoryId, Is.EqualTo(s_root));
|
|
}
|
|
|
|
private static readonly string[] s_rootAndSub = ["RootA", "SubA"];
|
|
|
|
[Test]
|
|
public async Task SubCategoryMatchesCascadeFromParentAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore(withSubCategory: true);
|
|
await store.AddAliasesAsync(s_child,
|
|
[new AliasAddRequest("SubA", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("RootA", s_t2, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
// Find on root with wildcard returns BOTH the root- and
|
|
// child-category aliases.
|
|
IReadOnlyList<AliasNameDataType> result = await store
|
|
.FindAliasAsync(s_root, "%", NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
var names = new HashSet<string>();
|
|
foreach (AliasNameDataType a in result)
|
|
{
|
|
names.Add(a.AliasName.Name!);
|
|
}
|
|
Assert.That(names, Is.EquivalentTo(s_rootAndSub));
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAliasWithEmptyPatternReturnsEmptyAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("A", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
IReadOnlyList<AliasNameDataType> result = await store
|
|
.FindAliasAsync(s_root, string.Empty, NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAliasWithUnknownCategoryReturnsEmptyAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
IReadOnlyList<AliasNameDataType> result = await store
|
|
.FindAliasAsync(new NodeId("Unknown", 2),
|
|
"%", NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(result, Is.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddOnUnsupportedCategoryThrowsBadNotSupportedAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore(
|
|
capabilities: AliasNameCapabilities.None);
|
|
|
|
ServiceResultException ex = null;
|
|
try
|
|
{
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
}
|
|
catch (ServiceResultException sre)
|
|
{
|
|
ex = sre;
|
|
}
|
|
|
|
Assert.That(ex, Is.Not.Null);
|
|
Assert.That(ex.StatusCode, Is.EqualTo((uint)StatusCodes.BadNotSupported));
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAliasVerboseProducesServerUrisAndCategoryIdAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
store.Seed(s_root, "S1", s_t1, serverUri: "urn:other-server",
|
|
referenceTypeId: ReferenceTypeIds.AliasFor);
|
|
|
|
IReadOnlyList<AliasNameVerboseDataType> result = await store
|
|
.FindAliasVerboseAsync(s_root, "%", NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(result, Has.Count.EqualTo(1));
|
|
Assert.That(result[0].AliasName.Name, Is.EqualTo("S1"));
|
|
Assert.That(result[0].AliasNameCategoryId, Is.EqualTo(s_root));
|
|
Assert.That(result[0].ServerUris.Count, Is.EqualTo(1));
|
|
Assert.That(result[0].ServerUris[0], Is.EqualTo("urn:other-server"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task OwnsCategoryReflectsRegisteredTreeAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore(withSubCategory: true);
|
|
Assert.That(store.OwnsCategory(s_root), Is.True);
|
|
Assert.That(store.OwnsCategory(s_child), Is.True);
|
|
Assert.That(store.OwnsCategory(new NodeId("Other", 2)), Is.False);
|
|
// Suppress async warning on a synchronous fixture
|
|
await Task.CompletedTask.ConfigureAwait(false);
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteExistingAliasRoundTripsAndBumpsLastChangeAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)1));
|
|
|
|
StatusCode[] result = await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("X", s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(result, Has.Length.EqualTo(1));
|
|
Assert.That(result[0].Code, Is.EqualTo(StatusCodes.Good),
|
|
"Successful delete must return Good.");
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)2),
|
|
"LastChange must bump exactly once on a successful delete batch.");
|
|
|
|
IReadOnlyList<AliasNameDataType> find = await store
|
|
.FindAliasAsync(s_root, "X", NodeId.Null, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(find, Is.Empty,
|
|
"Deleted alias must no longer be findable.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteFiresChangedEventWithCategoryAndVersionAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
var captured = new List<AliasStoreChangedEventArgs>();
|
|
store.Changed += (_, e) => captured.Add(e);
|
|
|
|
await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("X", s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(captured, Has.Count.EqualTo(1),
|
|
"Successful delete must fire Changed exactly once.");
|
|
Assert.That(captured[0].CategoryId, Is.EqualTo(s_root));
|
|
Assert.That(captured[0].LastChange, Is.EqualTo(2u),
|
|
"Changed event must carry the new LastChange value.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteRemovesEmptyAliasGroupSoReAddSucceedsAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("X", s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
// The (name, target) tuple must not survive as a stale BadBrowseNameDuplicated
|
|
// poison entry — re-adding the same alias must succeed.
|
|
StatusCode[] result = await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(result[0].Code, Is.EqualTo(StatusCodes.Good),
|
|
"Re-adding a deleted (name,target) must succeed (group cleanup).");
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteAllFailBatchDoesNotBumpLastChangeAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
uint? before = store.GetLastChange(s_root);
|
|
|
|
// All entries fail (wrong target node).
|
|
StatusCode[] result = await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("X", s_t2)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(result[0].Code, Is.EqualTo(StatusCodes.BadNotFound));
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo(before),
|
|
"All-fail delete batch must NOT bump LastChange.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddWithEmptyNameReturnsBadBrowseNameInvalidAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest(string.Empty, s_t1, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadBrowseNameInvalid));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddWithNullTargetNodeReturnsBadNodeIdInvalidAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", ExpandedNodeId.Null, null, ReferenceTypeIds.AliasFor)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadNodeIdInvalid));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddWithNullReferenceTypeReturnsBadReferenceTypeIdInvalidAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.AddAliasesAsync(s_root,
|
|
[new AliasAddRequest("X", s_t1, null, NodeId.Null)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadReferenceTypeIdInvalid));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteWithEmptyNameReturnsBadBrowseNameInvalidAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest(string.Empty, s_t1)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadBrowseNameInvalid));
|
|
}
|
|
|
|
[Test]
|
|
public async Task DeleteWithNullTargetNodeReturnsBadNodeIdInvalidAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
StatusCode[] r = await store.DeleteAliasesAsync(s_root,
|
|
[new AliasDeleteRequest("X", ExpandedNodeId.Null)],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadNodeIdInvalid));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddBatchAccumulatesPerEntryFailuresWithoutBumpAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
// All three rows fail individually — none should bump LastChange.
|
|
StatusCode[] r = await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest(string.Empty, s_t1, null, ReferenceTypeIds.AliasFor),
|
|
new AliasAddRequest("X", ExpandedNodeId.Null, null, ReferenceTypeIds.AliasFor),
|
|
new AliasAddRequest("Y", s_t1, null, NodeId.Null)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
Assert.That(r, Has.Length.EqualTo(3));
|
|
Assert.That(r[0].Code, Is.EqualTo(StatusCodes.BadBrowseNameInvalid));
|
|
Assert.That(r[1].Code, Is.EqualTo(StatusCodes.BadNodeIdInvalid));
|
|
Assert.That(r[2].Code, Is.EqualTo(StatusCodes.BadReferenceTypeIdInvalid));
|
|
Assert.That(store.GetLastChange(s_root), Is.EqualTo((uint?)0),
|
|
"All-fail add batch must NOT bump LastChange.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAliasFiltersByReferenceTypeSubtypeViaTypeTreeAsync()
|
|
{
|
|
// Seed an alias whose ReferenceTypeId is a *subtype* of AliasFor
|
|
// (a synthetic 'SpecialAliasFor' from a custom namespace).
|
|
// FindAlias with a filter equal to AliasFor must return the alias
|
|
// because ITypeTable.IsTypeOf(subtype, base) returns true (Part 17
|
|
// §6.3.2 reference-type filter semantics: include subtypes).
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
var specialAliasFor = new NodeId("SpecialAliasFor", 2);
|
|
store.Seed(s_root, "Tagged", s_t1, serverUri: null,
|
|
referenceTypeId: specialAliasFor);
|
|
|
|
var typeTree = new Mock<ITypeTable>();
|
|
typeTree
|
|
.Setup(t => t.IsTypeOf(specialAliasFor, ReferenceTypeIds.AliasFor))
|
|
.Returns(true);
|
|
// Anything else NOT in the subtype chain returns false.
|
|
typeTree
|
|
.Setup(t => t.IsTypeOf(specialAliasFor, ReferenceTypeIds.Organizes))
|
|
.Returns(false);
|
|
|
|
// Filter on the base type — subtype alias should match.
|
|
IReadOnlyList<AliasNameDataType> match = await store
|
|
.FindAliasAsync(s_root, "%", ReferenceTypeIds.AliasFor, typeTree.Object)
|
|
.ConfigureAwait(false);
|
|
Assert.That(match, Has.Count.EqualTo(1),
|
|
"Alias with subtype ReferenceType must match filter on its base type.");
|
|
|
|
// Filter on an unrelated type — no match.
|
|
IReadOnlyList<AliasNameDataType> miss = await store
|
|
.FindAliasAsync(s_root, "%", ReferenceTypeIds.Organizes, typeTree.Object)
|
|
.ConfigureAwait(false);
|
|
Assert.That(miss, Is.Empty,
|
|
"Alias with subtype ReferenceType must NOT match filter on an unrelated type.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindAliasWithReferencesAsFilterMatchesAllAsync()
|
|
{
|
|
using InMemoryAliasNameStore store = CreateStore();
|
|
await store.AddAliasesAsync(s_root,
|
|
[
|
|
new AliasAddRequest("A", s_t1, null, ReferenceTypeIds.AliasFor),
|
|
new AliasAddRequest("B", s_t2, null, ReferenceTypeIds.HasProperty)
|
|
],
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
IReadOnlyList<AliasNameDataType> result = await store
|
|
.FindAliasAsync(s_root, "%", ReferenceTypeIds.References, EmptyTypeTree())
|
|
.ConfigureAwait(false);
|
|
Assert.That(result, Has.Count.EqualTo(2),
|
|
"Filter == References must short-circuit and match every alias regardless of refType.");
|
|
}
|
|
}
|
|
}
|