mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 16:52:07 +08:00
61edaa1ed0
# Description Drops support for **netstandard2.1** and **.NET Framework 4.7.2**. Libraries now target `net48`, `net8.0`, `net9.0` and `net10.0`. `Opc.Ua.Types` and `Opc.Ua.SourceGeneration.Core` still also target `netstandard2.0`, but only because the Roslyn source generators load them. There is no general netstandard2.0 support. **Preprocessor directives** (112 files) - Every `#if`/`#elif` mentioning `NETSTANDARD2_1*`, `NET472*`, `NET_STANDARD_TESTS`, `SKIP_ECC_CERTIFICATE_REQUEST_SIGNING` or `NETSTANDARD*` was evaluated against the remaining TFM set (net48, net8/9/10, plus netstandard2.0 inside `Opc.Ua.Types`/`tools`) and simplified. Dead branches were removed. - Example: `NETSTANDARD2_1 || NET8_0_OR_GREATER` → `NET8_0_OR_GREATER`. - Example: `NET8_0_OR_GREATER || NET472_OR_GREATER` → removed (always true). - Netstandard-only code was removed: `UnixFileModeShim`, the CRDT reflection path in `ReplicatedGossipOptions.CreateReaderOptions`, and the netstandard2.1-only test variants. **Custom test logic** - `targets.props` drops the `net472`, `netstandard2.0` and `netstandard2.1` `CustomTestTarget` profiles, `NetStandardTests` and `SKIP_ECC_CERTIFICATE_REQUEST_SIGNING`. Supported values are now `net48`, `net8.0`, `net9.0`, `net10.0`. - The `NET_STANDARD_TESTS` define is removed from 29 test projects. - The "build netstandard shells as net10.0" overrides are removed from 18 projects. - `RestrictForLegacyTfm` now only applies to `net48`. - `tests/customtest.bat` is updated to the new values. **Build / packaging / CI** - MSBuild TFM conditions are simplified: Kestrel package choice, MQTTnet v4 (net48 only), BouncyCastle, Di/OpenUsd/Vision/Stress test excludes, and `System.IO.FileSystem.AccessControl` (dropped from Core). - The MigrationAnalyzer nuspec drops its net472/netstandard2.1 lib groups. The Azure signing lists are updated. - `get-ci-matrix.ps1` removes the net472/netstandard test profiles (including the PR-gating `linux-netstandard2.1`) and the matching build legs. **Breaking API change (2.0 preview):** removed `HttpsTransportListener.IsWssTransportSupported` and `ReplicatedGossipOptions.IsGossipStateDecodingSupported`. They only returned `false` on netstandard2.1 and are now always `true`. The test guards that used them were removed as well. **Docs** - NuGet READMEs, `README.md`, `DeveloperGuide.md`, `PubSub.md`, the certificate/ECC/identity docs and the 2.0 migration guide (plus its `.agents` skill mirror) are updated. - The migration guide notes that 4.7.2 consumers must move to 4.8 and netstandard2.1 consumers to net8.0+. ### Reviewer notes - The `System.IO.FileSystem.AccessControl` `PackageVersion` pin is left in `Directory.Packages.props`. It has no direct reference any more, but transitive pinning is on, so it was kept to avoid shifting resolved versions. - The `#if` rewrite was done mechanically by a truth-table evaluator. The diff in the `.cs` files is limited to directive lines, removed dead branches, and stale-comment updates. ### Verified locally - `dotnet build UA.slnx -p:CustomTestTarget=net48`: 0 errors. - `dotnet build UA.slnx -p:CustomTestTarget=net10.0`: 0 errors. - Default multi-target builds (no `CustomTestTarget`) of Opc.Ua.Types, Bindings.Https, PubSub.Mqtt and Redundancy.Server succeeded. - net10.0 tests: - Opc.Ua.Redundancy.Server.Tests: 840/840 passed. - Opc.Ua.Types.Tests: 11363 passed, 1 skipped. - ModelDependencyScanner tests: 20/20 passed. - The full test suite was **not** run locally. ## Related Issues - None ## 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. - [ ] 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
213 lines
8.6 KiB
C#
213 lines
8.6 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.IO;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Di.Server.SoftwareUpdate;
|
|
|
|
namespace Opc.Ua.Di.Tests
|
|
{
|
|
/// <summary>
|
|
/// Tests for <see cref="MemorySoftwareFolder"/> — multi-version
|
|
/// software repository for a single device.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("DI")]
|
|
[Category("SoftwareUpdate")]
|
|
public sealed class MemorySoftwareFolderTests
|
|
{
|
|
private static NodeId ElementId => new("Device", 2);
|
|
|
|
private static SoftwarePackage MakePackage(string version, string description = "")
|
|
{
|
|
return new SoftwarePackage(
|
|
Id: $"pkg-{version}",
|
|
Version: version,
|
|
Vendor: "Acme",
|
|
Description: description,
|
|
SizeBytes: 0,
|
|
CreatedAt: default,
|
|
Hash: string.Empty);
|
|
}
|
|
|
|
private static MemoryStream Payload(string text)
|
|
{
|
|
return new MemoryStream(System.Text.Encoding.UTF8.GetBytes(text));
|
|
}
|
|
|
|
[Test]
|
|
public void ConstructorRejectsNullElementId()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => new MemorySoftwareFolder(NodeId.Null));
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddVersionStoresPackageAndPayload()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
using MemoryStream payload = Payload("firmware-v1");
|
|
|
|
SoftwarePackage stored = await folder.AddVersionAsync(
|
|
MakePackage("1.0.0"), payload).ConfigureAwait(false);
|
|
|
|
Assert.That(stored.Version, Is.EqualTo("1.0.0"));
|
|
Assert.That(stored.SizeBytes, Is.EqualTo(payload.Length));
|
|
Assert.That(stored.SizeBytes, Is.GreaterThan(0L));
|
|
Assert.That(stored.CreatedAt, Is.Not.Default);
|
|
|
|
SoftwarePackage? fetched = await folder.GetVersionAsync("1.0.0").ConfigureAwait(false);
|
|
Assert.That(fetched, Is.Not.Null);
|
|
Assert.That(fetched!.Version, Is.EqualTo("1.0.0"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task OpenVersionReturnsPayloadContent()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
using MemoryStream payload = Payload("expected-content");
|
|
await folder.AddVersionAsync(MakePackage("1.0.0"), payload).ConfigureAwait(false);
|
|
|
|
using Stream reader = await folder.OpenVersionAsync("1.0.0").ConfigureAwait(false);
|
|
byte[] buffer = new byte[100];
|
|
#if NET
|
|
int read = await reader.ReadAsync(buffer.AsMemory()).ConfigureAwait(false);
|
|
#else
|
|
int read = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
|
|
#endif
|
|
string content = System.Text.Encoding.UTF8.GetString(buffer, 0, read);
|
|
|
|
Assert.That(content, Is.EqualTo("expected-content"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ListVersionsReturnsAllAddedVersions()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
await folder.AddVersionAsync(MakePackage("1.0.0"), Payload("v1")).ConfigureAwait(false);
|
|
await folder.AddVersionAsync(MakePackage("1.0.1"), Payload("v1.1")).ConfigureAwait(false);
|
|
await folder.AddVersionAsync(MakePackage("1.0.2-rc"), Payload("v1.2rc")).ConfigureAwait(false);
|
|
|
|
var versions = new List<string>();
|
|
await foreach (SoftwarePackage pkg in folder.ListVersionsAsync())
|
|
{
|
|
versions.Add(pkg.Version);
|
|
}
|
|
|
|
Assert.That(versions, Has.Count.EqualTo(3));
|
|
Assert.That(versions, Does.Contain("1.0.0").And.Contain("1.0.1").And.Contain("1.0.2-rc"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetVersionForUnknownReturnsNull()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
SoftwarePackage? result = await folder.GetVersionAsync("never").ConfigureAwait(false);
|
|
Assert.That(result, Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void OpenVersionForUnknownThrowsFileNotFound()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
Assert.ThrowsAsync<FileNotFoundException>(
|
|
async () => await folder.OpenVersionAsync("never").ConfigureAwait(false));
|
|
}
|
|
|
|
[Test]
|
|
public async Task RemoveVersionReturnsTrueWhenPresent()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
await folder.AddVersionAsync(MakePackage("1.0.0"), Payload("v1")).ConfigureAwait(false);
|
|
|
|
Assert.That(await folder.RemoveVersionAsync("1.0.0").ConfigureAwait(false), Is.True);
|
|
Assert.That(await folder.RemoveVersionAsync("1.0.0").ConfigureAwait(false), Is.False);
|
|
Assert.That(await folder.GetVersionAsync("1.0.0").ConfigureAwait(false), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SetCurrentVersionMarksActive()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
await folder.AddVersionAsync(MakePackage("1.0.0"), Payload("v1")).ConfigureAwait(false);
|
|
await folder.AddVersionAsync(MakePackage("1.0.1"), Payload("v1.1")).ConfigureAwait(false);
|
|
|
|
await folder.SetCurrentVersionAsync("1.0.1").ConfigureAwait(false);
|
|
|
|
SoftwarePackage? current = await folder.GetCurrentVersionAsync().ConfigureAwait(false);
|
|
Assert.That(current, Is.Not.Null);
|
|
Assert.That(current!.Version, Is.EqualTo("1.0.1"));
|
|
}
|
|
|
|
[Test]
|
|
public void SetCurrentVersionUnknownThrowsArgumentException()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
Assert.ThrowsAsync<ArgumentException>(
|
|
async () => await folder.SetCurrentVersionAsync("missing").ConfigureAwait(false));
|
|
}
|
|
|
|
[Test]
|
|
public async Task RemovingCurrentVersionClearsCurrentMarker()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
await folder.AddVersionAsync(MakePackage("1.0.0"), Payload("v1")).ConfigureAwait(false);
|
|
await folder.SetCurrentVersionAsync("1.0.0").ConfigureAwait(false);
|
|
|
|
Assert.That(await folder.GetCurrentVersionAsync().ConfigureAwait(false), Is.Not.Null);
|
|
|
|
await folder.RemoveVersionAsync("1.0.0").ConfigureAwait(false);
|
|
|
|
Assert.That(await folder.GetCurrentVersionAsync().ConfigureAwait(false), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AddVersionWithSameVersionIdReplaces()
|
|
{
|
|
var folder = new MemorySoftwareFolder(ElementId);
|
|
await folder.AddVersionAsync(
|
|
MakePackage("1.0.0", "original"), Payload("v1-orig")).ConfigureAwait(false);
|
|
await folder.AddVersionAsync(
|
|
MakePackage("1.0.0", "replacement"), Payload("v1-new")).ConfigureAwait(false);
|
|
|
|
int count = 0;
|
|
await foreach (SoftwarePackage _ in folder.ListVersionsAsync())
|
|
{
|
|
count++;
|
|
}
|
|
Assert.That(count, Is.EqualTo(1));
|
|
|
|
SoftwarePackage? fetched = await folder.GetVersionAsync("1.0.0").ConfigureAwait(false);
|
|
Assert.That(fetched!.Description, Is.EqualTo("replacement"));
|
|
}
|
|
}
|
|
}
|