Files
scadaproj/ZB.MOM.WW.SPHistorianClient/tests/ZB.MOM.WW.SPHistorianClient.Tests/HistorianWcfRevisionProbeTests.cs
T

62 lines
2.8 KiB
C#

using System.Runtime.Versioning;
using ZB.MOM.WW.SPHistorianClient;
using ZB.MOM.WW.SPHistorianClient.Models;
using ZB.MOM.WW.SPHistorianClient.Wcf;
using Xunit.Abstractions;
namespace ZB.MOM.WW.SPHistorianClient.Tests;
/// <remarks>
/// Probes the SDK-direct WCF revision-write path (D2 new path). Calls
/// <c>AddNonStreamValuesBegin</c> through <see cref="HistorianWcfRevisionOrchestrator"/>
/// against the live local Historian and surfaces what the server returns. The
/// underlying native wrapper is gated client-side by err 129 TagNotFoundInCache;
/// this test bypasses the wrapper entirely and asks the SERVER directly. Gated on
/// HISTORIAN_HOST=localhost; skips otherwise.
/// </remarks>
[SupportedOSPlatform("windows")]
public sealed class HistorianWcfRevisionProbeTests
{
private readonly ITestOutputHelper _output;
public HistorianWcfRevisionProbeTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public async Task AddNonStreamValuesBegin_ProbeReturnsServerResult()
{
string? host = Environment.GetEnvironmentVariable("HISTORIAN_HOST");
if (string.IsNullOrWhiteSpace(host) || !string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase) || !OperatingSystem.IsWindows())
{
return;
}
HistorianClientOptions options = new()
{
Host = host,
IntegratedSecurity = true,
Transport = HistorianTransport.LocalPipe,
};
HistorianWcfRevisionOrchestrator orchestrator = new(options);
HistorianRevisionProbeResult result = await orchestrator.ProbeBeginAsync(CancellationToken.None);
_output.WriteLine($"OpenSucceeded: {result.OpenSucceeded}");
_output.WriteLine($"ClientHandle: {result.ClientHandle}");
_output.WriteLine($"StorageSessionId: {result.StorageSessionId}");
_output.WriteLine($"TrxInterfaceVersion: {result.TrxInterfaceVersion} (rc={result.TrxInterfaceVersionReturnCode}) ex={result.TrxInterfaceVersionException}");
_output.WriteLine($"RTag2Succeeded: {result.RTag2Succeeded} OutHex={result.RTag2OutHex} ErrHex={result.RTag2ErrorHex} Ex={result.RTag2Exception}");
_output.WriteLine($"BeginSucceeded: {result.BeginSucceeded}");
_output.WriteLine($"BeginTransactionId: {result.BeginTransactionId}");
foreach (HistorianRevisionBeginAttempt attempt in result.BeginAttempts)
{
_output.WriteLine($" attempt[{attempt.HandleLabel}] handle={attempt.HandleSent} ok={attempt.Succeeded} tx={attempt.TransactionId} err={attempt.ErrorHex} ex={attempt.Exception}");
}
Assert.True(result.OpenSucceeded, "Auth chain failed; revision probe never reached the Trx endpoint.");
// Don't assert BeginSucceeded — we're surfacing whatever the server says, not requiring success.
}
}