mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-21 09:06:37 +08:00
9b034f8291
# Description Nullable reference types are now enabled once, in `common.props`, and every project in the repository builds warning-clean with them. **Configuration** - `<Nullable>enable</Nullable>` lives in `common.props`. All per-project `<Nullable>` settings are removed: 178 project files (enable, annotations, and the `disable` in the three Aot test projects). - 419 per-file `#nullable enable`/`restore` directives and the 4 `#nullable disable` directives are removed. - Kept on purpose: - The 5 `<auto-generated>` schema files (`UANodeSet.cs`, `UA Type Dictionary.cs`, `OPCBinarySchema.cs`, `SecuredApplication.cs`, `PInvokeHelper.cs`) keep `#nullable enable`. The compiler ignores the project setting in generated code, so the directive is required there. - `tests/Opc.Ua.Interop.LegacyPeer` keeps `disable`. It builds against the 1.5.378 packages and does not import the repository props. - `docs/DeveloperGuide.md` and `.github/copilot-instructions.md` now describe the central setting. **Migration** (the 43 unset and 13 annotations-only projects, roughly 10k diagnostics) - **Production code: annotated at the declarations.** Covers `tools/Opc.Ua.SourceGeneration.Core`, `src/Opc.Ua.Lds.Server` and the LDS sample. - Members, parameters and returns are nullable where null actually flows. - Null-check helpers carry `[NotNullWhen]` (`IsNull`, `IsValidXmlName`, `IsMethodTypeDesign`). - `CoreUtils.Format`, `Utils.Format`, `ITemplateWriter.WriteLine` take `params object?[]`. `Template.AddReplacement` takes `string?` (rendering already skips null replacements). - `IRegisteredServerStore.RegisterAsync` returns `Task<RegistrationEntry?>`: it returns null when a registration is removed. - Dereferences backed by an invariant (for example, the validated model) use `!`, so runtime behaviour is unchanged. - **Behavioural changes in production code** (small, deliberate): - `NodeSetToModelDesign` throws `InvalidOperationException` when the file is not a NodeSet. Before, it threw a NullReferenceException on the next line. - `ModelDesignValidator` starts its lookup tables empty instead of null. A redundant `if (m_nodes == null) return;` guard is gone. - **Test code: minimal annotations.** - `?` on values that can be null, `!` where the test asserts non-null. - `= null!` for fixture members assigned in SetUp. - `TryGetStructure<T>(out T? x)` where the inferred `T?` broke the `IEncodeable` constraint. - A few redundant `== null` checks on structs (`NodeId`, `ArrayOf<T>`) folded into the adjacent `IsNull`/`Count` checks. **Notes for reviewers** - The diff is large (~1,500 files) but almost entirely mechanical: `?`, `!` and directive removal. The non-annotation changes are listed above. - Known follow-up, not done here: `IModelDesign.Namespaces/TargetNamespace/NamespaceUris` stay non-nullable even though the validator returns null before it loads a dictionary. Making them nullable would ripple through every generator call site. ## Related Issues - Fixes #4439 ## 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. - [ ] 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. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. The "no new warnings" box covers net10.0 and net48: full non-incremental builds of `UA.slnx`, `tools/SourceGeneration.slnx`, `tools/MigrationAnalyzer.slnx` and the Aot test projects finished with 0 warnings and 0 errors under the repository's warnings-as-errors settings. net9.0 and net8.0 also had no nullable diagnostics, but they were not rebuilt after the final fixes. Tests have not been run locally yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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.");
|
|
}
|
|
}
|
|
}
|