using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Core.Abstractions; namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests; /// /// Covers shape invariants — added to lock down the documented /// contract after Core.Abstractions-008 reworded the LastError remark. /// public sealed class DriverHealthTests { /// /// Core.Abstractions-008: DriverHealth.LastError is not constrained by the /// State enum — a Healthy driver may legitimately retain the last error from a /// recovered failure (for diagnostics), and Degraded / Reconnecting / Faulted states may /// all carry a non-null message. The old XML doc "null when state is Healthy" was wrong; /// this test makes the type's actual contract explicit so future doc churn cannot drift. /// [Theory] [InlineData(DriverState.Unknown)] [InlineData(DriverState.Initializing)] [InlineData(DriverState.Healthy)] [InlineData(DriverState.Degraded)] [InlineData(DriverState.Reconnecting)] [InlineData(DriverState.Faulted)] public void LastError_IsIndependent_OfState(DriverState state) { var healthWithError = new DriverHealth(state, LastSuccessfulRead: DateTime.UtcNow, LastError: "earlier failure"); var healthWithoutError = new DriverHealth(state, LastSuccessfulRead: DateTime.UtcNow, LastError: null); // Both shapes are constructible regardless of state — the type makes no enforcement. healthWithError.LastError.ShouldBe("earlier failure"); healthWithoutError.LastError.ShouldBeNull(); healthWithError.State.ShouldBe(state); healthWithoutError.State.ShouldBe(state); } [Fact] public void DriverState_EnumContainsExpectedMembers() { // Pins the enum so finding-008's "more than Healthy can carry an error" claim // does not bit-rot. var names = Enum.GetNames(); names.ShouldContain(nameof(DriverState.Unknown)); names.ShouldContain(nameof(DriverState.Initializing)); names.ShouldContain(nameof(DriverState.Healthy)); names.ShouldContain(nameof(DriverState.Degraded)); names.ShouldContain(nameof(DriverState.Reconnecting)); names.ShouldContain(nameof(DriverState.Faulted)); } }