fix(r2-06): RED repro — misconfigured ServerHistorian:Endpoint should fail with a named error, not UriFormatException (06/S-11)

This commit is contained in:
Joseph Doherty
2026-07-13 09:51:31 -04:00
parent 1676c8f40f
commit 3a049a13a4
2 changed files with 34 additions and 1 deletions
@@ -5,7 +5,7 @@
{
"id": "T1",
"subject": "RED: misconfig repro test — HistorianGatewayClientAdapter.Create with empty/malformed Endpoint must throw a named InvalidOperationException (currently UriFormatException; test MUST fail on current code)",
"status": "pending",
"status": "completed",
"blockedBy": []
},
{
@@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
@@ -21,6 +22,38 @@ public sealed class HistorianGatewayClientAdapterTests
Assert.NotNull(adapter);
}
/// <summary>
/// archreview 06/S-11 — an enabled historian with an empty <c>Endpoint</c> must fail with a
/// named, config-key-carrying <see cref="InvalidOperationException"/> (defense-in-depth for any
/// caller that bypasses the Host's <c>ServerHistorianOptionsValidator</c>), not the raw
/// <see cref="UriFormatException"/> that <c>new Uri("")</c> throws deep in the factory. Current
/// code throws <see cref="UriFormatException"/> → this is the failing-first (RED) repro.
/// </summary>
[Fact]
public void Create_with_empty_endpoint_throws_named_config_error()
{
var opts = new ServerHistorianOptions { Enabled = true, Endpoint = "", ApiKey = "histgw_x_y" };
var ex = Should.Throw<InvalidOperationException>(
() => HistorianGatewayClientAdapter.Create(opts, NullLoggerFactory.Instance));
ex.Message.ShouldContain("ServerHistorian:Endpoint");
}
/// <summary>
/// archreview 06/S-11 companion — a non-empty but unparseable / non-absolute <c>Endpoint</c> must
/// also fail with the same named <see cref="InvalidOperationException"/>, not a raw
/// <see cref="UriFormatException"/>. RED on current code.
/// </summary>
[Fact]
public void Create_with_malformed_endpoint_throws_named_config_error()
{
var opts = new ServerHistorianOptions { Enabled = true, Endpoint = "not a uri", ApiKey = "histgw_x_y" };
var ex = Should.Throw<InvalidOperationException>(
() => HistorianGatewayClientAdapter.Create(opts, NullLoggerFactory.Instance));
ex.Message.ShouldContain("ServerHistorian:Endpoint");
}
[Fact]
public void Factory_builds_GatewayHistorianDataSource()
{