using System.Runtime.Versioning; using AVEVA.Historian.Client; using AVEVA.Historian.Client.Models; using AVEVA.Historian.Client.Wcf; using Xunit.Abstractions; namespace AVEVA.Historian.Client.Tests; /// /// Probes the SDK-direct WCF revision-write path (D2 new path). Calls /// AddNonStreamValuesBegin through /// 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. /// [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. } }