513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
147 lines
6.4 KiB
C#
147 lines
6.4 KiB
C#
using System.Text.Json;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Messages;
|
|
|
|
/// <summary>
|
|
/// The additive optional <c>SiteIdentifier</c> trailing param on the
|
|
/// Browse/Verify/Cert-trust management commands. Verifies backward compatibility (legacy
|
|
/// JSON without the field deserializes to null) and round-trip survival when set.
|
|
/// </summary>
|
|
public class BrowseVerifyCertSiteIdentifierTests
|
|
{
|
|
private static readonly JsonSerializerOptions Options = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
// ── Backward compatibility: legacy JSON (no SiteIdentifier) → null ──
|
|
|
|
/// <summary>Verifies that browse node command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void BrowseNodeCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = """{"ConnectionName":"conn","ParentNodeId":"ns=2;s=Node","ContinuationToken":null}""";
|
|
var cmd = JsonSerializer.Deserialize<BrowseNodeCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
Assert.Equal("conn", cmd.ConnectionName);
|
|
}
|
|
|
|
/// <summary>Verifies that search address space command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void SearchAddressSpaceCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = """{"ConnectionName":"conn","Query":"pump","MaxDepth":5,"MaxResults":100}""";
|
|
var cmd = JsonSerializer.Deserialize<SearchAddressSpaceCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
Assert.Equal("pump", cmd.Query);
|
|
}
|
|
|
|
/// <summary>Verifies that verify endpoint command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void VerifyEndpointCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = """{"ConnectionName":"conn","Protocol":"OpcUa","ConfigJson":"{}"}""";
|
|
var cmd = JsonSerializer.Deserialize<VerifyEndpointCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
Assert.Equal("OpcUa", cmd.Protocol);
|
|
}
|
|
|
|
/// <summary>Verifies that trust server cert command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void TrustServerCertCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = """{"ConnectionName":"conn","DerBase64":"AAAA","Thumbprint":"ABCD"}""";
|
|
var cmd = JsonSerializer.Deserialize<TrustServerCertCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
Assert.Equal("ABCD", cmd.Thumbprint);
|
|
}
|
|
|
|
/// <summary>Verifies that remove server cert command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void RemoveServerCertCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = """{"Thumbprint":"ABCD"}""";
|
|
var cmd = JsonSerializer.Deserialize<RemoveServerCertCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
Assert.Equal("ABCD", cmd.Thumbprint);
|
|
}
|
|
|
|
/// <summary>Verifies that list server certs command legacy json site identifier null.</summary>
|
|
[Fact]
|
|
public void ListServerCertsCommand_LegacyJson_SiteIdentifierNull()
|
|
{
|
|
var json = "{}";
|
|
var cmd = JsonSerializer.Deserialize<ListServerCertsCommand>(json, Options)!;
|
|
Assert.Null(cmd.SiteIdentifier);
|
|
}
|
|
|
|
// ── Round-trip: SiteIdentifier set survives serialize → deserialize ──
|
|
|
|
/// <summary>Verifies that browse node command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void BrowseNodeCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new BrowseNodeCommand("conn", "ns=2;s=Node", "tok", "SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<BrowseNodeCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
|
|
/// <summary>Verifies that search address space command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void SearchAddressSpaceCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new SearchAddressSpaceCommand("conn", "pump", 5, 100, "SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<SearchAddressSpaceCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
|
|
/// <summary>Verifies that verify endpoint command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void VerifyEndpointCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new VerifyEndpointCommand("conn", "OpcUa", "{}", "SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<VerifyEndpointCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
|
|
/// <summary>Verifies that trust server cert command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void TrustServerCertCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new TrustServerCertCommand("conn", "AAAA", "ABCD", "SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<TrustServerCertCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
|
|
/// <summary>Verifies that remove server cert command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void RemoveServerCertCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new RemoveServerCertCommand("ABCD", "SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<RemoveServerCertCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
|
|
/// <summary>Verifies that list server certs command round trip site identifier survives.</summary>
|
|
[Fact]
|
|
public void ListServerCertsCommand_RoundTrip_SiteIdentifierSurvives()
|
|
{
|
|
var original = new ListServerCertsCommand("SITE-01");
|
|
var json = JsonSerializer.Serialize(original, Options);
|
|
var round = JsonSerializer.Deserialize<ListServerCertsCommand>(json, Options)!;
|
|
Assert.Equal("SITE-01", round.SiteIdentifier);
|
|
Assert.Equal(original, round);
|
|
}
|
|
}
|