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.
This commit is contained in:
Joseph Doherty
2026-06-19 05:06:43 -04:00
parent 4b14feb373
commit a0dccbf8ee
2 changed files with 14 additions and 4 deletions
@@ -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<Exception>(() => S7DriverFactoryExtensions.ParseOptions("s7-test", numericBlob));
}
@@ -53,9 +53,17 @@ public sealed class DriverPageJsonConverterTests
"enum config fields serialise as numbers and the string-typed driver factory throws on parse.");
}
/// <summary>Sanity-check that reflection actually discovered the full driver-page fleet (so a
/// rename/move can't silently shrink the guarded set to zero).</summary>
/// <summary>Enforces that EVERY concrete <c>*DriverPage</c> routes config serialization through a
/// <c>_jsonOpts</c> 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.</summary>
[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");
}
}