From a0dccbf8ee310062c909386d3fd3c585c3a247e0 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 19 Jun 2026 05:06:43 -0400 Subject: [PATCH] test(drivers): tighten driver-page converter guard + clarify S7 numeric case Code-review follow-ups: the page-coverage test now asserts every *DriverPage declares a _jsonOpts serializer (so a new page that serialises config a different way fails the guard, not just converter removal); clarify that 40 == (int)S7CpuType.S71500 in the numeric-throws test. --- .../S7DriverConfigEnumSerializationTests.cs | 2 ++ .../DriverPageJsonConverterTests.cs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests/S7DriverConfigEnumSerializationTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests/S7DriverConfigEnumSerializationTests.cs index 8023bad3..feda2cf0 100644 --- a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests/S7DriverConfigEnumSerializationTests.cs +++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.S7.Tests/S7DriverConfigEnumSerializationTests.cs @@ -40,6 +40,8 @@ public sealed class S7DriverConfigEnumSerializationTests [Fact] public void Factory_throws_on_the_numeric_enum_form_the_pre_fix_page_emitted() { + // 40 == (int)S7CpuType.S71500 — exactly what the pre-fix page (no converter) wrote for S71500. + // The throw comes from binding a JSON number to the DTO's string? CpuType, so it fires for any number. const string numericBlob = "{\"host\":\"10.0.0.5\",\"port\":102,\"cpuType\":40,\"rack\":0,\"slot\":1}"; Should.Throw(() => S7DriverFactoryExtensions.ParseOptions("s7-test", numericBlob)); } diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DriverPageJsonConverterTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DriverPageJsonConverterTests.cs index f8ade09b..8ede8c2a 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DriverPageJsonConverterTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DriverPageJsonConverterTests.cs @@ -53,9 +53,17 @@ public sealed class DriverPageJsonConverterTests "enum config fields serialise as numbers and the string-typed driver factory throws on parse."); } - /// Sanity-check that reflection actually discovered the full driver-page fleet (so a - /// rename/move can't silently shrink the guarded set to zero). + /// Enforces that EVERY concrete *DriverPage routes config serialization through a + /// _jsonOpts field — otherwise a new page that serialised config a different way would slip + /// past the converter guard above. Also a floor check so a rename can't silently shrink the set. [Fact] - public void All_known_driver_pages_are_covered() - => DriverPageTypes.Count.ShouldBeGreaterThanOrEqualTo(9); + public void Every_driver_page_uses_a_guarded_jsonOpts_serializer() + { + var allDriverPages = typeof(S7DriverPage).Assembly.GetTypes() + .Where(t => t.Name.EndsWith("DriverPage", StringComparison.Ordinal) && !t.IsAbstract) + .ToList(); + allDriverPages.Count.ShouldBeGreaterThanOrEqualTo(9, "reflection should discover the full driver-page fleet"); + DriverPageTypes.Count.ShouldBe(allDriverPages.Count, + "every *DriverPage must declare a _jsonOpts config serializer so the string-enum converter guard covers it"); + } }