Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests/GatewayErrorReasonsTests.cs
T
Joseph Doherty 76e73e7dbf
v2-ci / unit-tests (push) Has been cancelled
chore(historian): HistorianGateway Client/Contracts 1.1.0, typed error reason (#900)
Bump ZB.MOM.WW.HistorianGateway.Client + Contracts 1.0.0 -> 1.1.0 (historiangw#135,
release 6365f34). GatewayErrorReasons now reads Client 1.1.0's typed
HistorianGatewayException.StatusCode / ErrorReason / ErrorDomain (constants from
HistorianGatewayErrorReasons) instead of parsing grpc-status-details-bin itself; the
direct Grpc.StatusProto pin and reference are dropped (the client brings it). The
published client maps every RpcException to a HistorianGatewayException, so the
trailer fallback is not needed. Behaviour unchanged: FailedPrecondition +
AGGREGATE_NOT_SUPPORTED_FOR_TAG (domain historian_gateway.v1) ->
BadAggregateNotSupported, everything else keeps its handling.

Adds GatewayErrorReasonsTests (typed-property-only exceptions, so they fail against
the old trailer implementation); wire tests and docs/Historian.md updated.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
2026-11-13 07:17:10 -05:00

64 lines
3.1 KiB
C#

using Grpc.Core;
using Shouldly;
using Xunit;
using ZB.MOM.WW.HistorianGateway.Client;
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests;
/// <summary>
/// lmxopcua#900 on Client 1.1.0: <see cref="GatewayErrorReasons"/> classifies by the client's typed
/// <see cref="HistorianGatewayException.StatusCode"/> / <see cref="HistorianGatewayException.ErrorReason"/> /
/// <see cref="HistorianGatewayException.ErrorDomain"/>. These exceptions carry the reason ONLY on the typed properties
/// (no inner <see cref="RpcException"/>, no trailer), so they pin that the typed accessor is what is read. The on-the-wire
/// path through the published client is <see cref="GatewayAggregateNotSupportedWireTests"/>.
/// </summary>
public sealed class GatewayErrorReasonsTests
{
private static HistorianGatewayException Gw(StatusCode? code, string? reason, string? domain) =>
new("x") { StatusCode = code, ErrorReason = reason, ErrorDomain = domain };
[Fact]
public void FailedPrecondition_with_the_gateways_aggregate_reason_is_the_refusal()
{
var ex = Gw(StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain);
GatewayErrorReasons.IsAggregateNotSupportedForTag(ex).ShouldBeTrue();
GatewayErrorReasons.ReasonOf(ex).ShouldBe("AGGREGATE_NOT_SUPPORTED_FOR_TAG");
}
[Fact]
public void The_refusal_is_found_when_wrapped()
{
var ex = new InvalidOperationException("outer",
Gw(StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain));
GatewayErrorReasons.IsAggregateNotSupportedForTag(ex).ShouldBeTrue();
}
public static TheoryData<StatusCode?, string?, string?> NotTheRefusal() => new()
{
{ StatusCode.Internal, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain },
{ null, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain },
{ StatusCode.FailedPrecondition, null, null },
{ StatusCode.FailedPrecondition, "LIVE_WRITES_DISABLED", HistorianGatewayErrorReasons.Domain },
{ StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, "example.com" },
{ StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, null },
};
[Theory]
[MemberData(nameof(NotTheRefusal))]
public void Every_other_shape_is_not_the_refusal(StatusCode? code, string? reason, string? domain) =>
GatewayErrorReasons.IsAggregateNotSupportedForTag(Gw(code, reason, domain)).ShouldBeFalse();
[Fact]
public void A_foreign_domains_reason_is_no_reason() =>
GatewayErrorReasons.ReasonOf(Gw(StatusCode.FailedPrecondition, "AGGREGATE_NOT_SUPPORTED_FOR_TAG", "example.com")).ShouldBeNull();
[Fact]
public void A_non_gateway_exception_is_not_the_refusal()
{
GatewayErrorReasons.IsAggregateNotSupportedForTag(new IOException("x")).ShouldBeFalse();
GatewayErrorReasons.ReasonOf(new IOException("x")).ShouldBeNull();
}
}