Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/S7DriverPageFormSerializationTests.cs
T
Joseph Doherty 6a616a1ab2 test(adminui): migrate AdminUI.Tests to v3 greenfield schema + Batch-1 stubs
Migrate tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests (was 358 build errors) to
the v3 Raw-only Tag schema and the Batch-1 AdminUI stubs. Production untouched.

- Driver-page serialization tests: drop the retired pre-declared Tags editor
  (page *TagRow types + DriverOptions.Tags); multi-device pages keep their
  Devices editor (ToOptions(devices)). Enum-serialization round-trip coverage
  (CpuType/ModbusFamily/MelsecFamily/AbCipPlcFamily/AbLegacyPlcFamily/FocasCncSeries)
  preserved intact.
- UnsTreeTestDb: reseed to v3 (Device->Tag raw slice, no EquipmentId/DriverInstanceId
  on Tag, no Namespace).
- UnsTreeService tag tests: assert Batch-1 stubs (CreateTag/UpdateTag refusal,
  empty tag/tag-driver lists); DeleteTag stays live against a raw Tag.
- Equipment #122 guard retained (validates input driver vs line cluster); drop the
  retired persisted-binding assertions + NamespaceId seeds. Area/Line #122 driver-
  orphan guard retired -> assert cross-cluster move now succeeds.
- DeleteCluster: drop the deleted-Namespace child-check test.
- OpcUaClientTagConfigModel/TagConfigValidator: address key FullName -> nodeId.
- ScriptTagCatalog: project surviving Name/DataType/TagConfig; DriverInstanceId null.
- VirtualTag {{equip}} equipment-tag-derived base is dark -> 3 tests skipped (Batch-3).

Result: build green; 507 passed / 3 skipped / 0 failed.
2026-07-15 21:50:48 -04:00

109 lines
3.9 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.Drivers;
using ZB.MOM.WW.OtOpcUa.Driver.S7;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
// v3 Batch-1 migration: the S7 driver page dropped its pre-declared Tags editor — tags now live in
// the Raw tree (/raw, Batch 2), and S7DriverOptions.Tags (the typed S7TagDefinition list) +
// S7DriverPage.S7TagRow were retired (the driver now consumes RawTags). The former tag-editor and
// tag-serialization tests (S7TagRow_*, TagList_SerializeRoundTrip_PreservesTags, and the tag legs of
// the round-trip tests) were removed. The connection/protocol-field + enum-serialization round-trip
// coverage (CpuType, S7DataType) is retained below unchanged.
public sealed class S7DriverPageFormSerializationTests
{
private static readonly JsonSerializerOptions _opts = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = false,
};
[Fact]
public void RoundTrip_PreservesKnownFields()
{
var original = new S7DriverOptions
{
Host = "10.0.0.5",
Port = 102,
CpuType = S7CpuType.S71200,
Rack = 0,
Slot = 1,
Timeout = TimeSpan.FromSeconds(10),
Probe = new S7ProbeOptions
{
Enabled = false,
Interval = TimeSpan.FromSeconds(15),
Timeout = TimeSpan.FromSeconds(3),
},
ProbeTimeoutSeconds = 30,
};
var json = JsonSerializer.Serialize(original, _opts);
var back = JsonSerializer.Deserialize<S7DriverOptions>(json, _opts);
back.ShouldNotBeNull();
back.Host.ShouldBe("10.0.0.5");
back.Port.ShouldBe(102);
back.CpuType.ShouldBe(S7CpuType.S71200);
back.Rack.ShouldBe((short)0);
back.Slot.ShouldBe((short)1);
back.Timeout.ShouldBe(TimeSpan.FromSeconds(10));
back.Probe.ShouldNotBeNull();
back.Probe.Enabled.ShouldBeFalse();
back.Probe.Interval.ShouldBe(TimeSpan.FromSeconds(15));
back.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(3));
back.ProbeTimeoutSeconds.ShouldBe(30);
}
[Fact]
public void Deserialize_DropsUnknownFields()
{
var jsonWithExtra = """{"unknownField":"old-value","probeTimeoutSeconds":12}""";
var optsSkip = new JsonSerializerOptions(_opts)
{
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
};
var back = JsonSerializer.Deserialize<S7DriverOptions>(jsonWithExtra, optsSkip);
back.ShouldNotBeNull();
back.ProbeTimeoutSeconds.ShouldBe(12);
}
[Fact]
public void FormModel_RoundTrip_PreservesEditableFields()
{
var opts = new S7DriverOptions
{
Host = "192.168.1.50",
Port = 102,
CpuType = S7CpuType.S7300,
Rack = 0,
Slot = 2,
Timeout = TimeSpan.FromSeconds(7),
Probe = new S7ProbeOptions
{
Enabled = true,
Interval = TimeSpan.FromSeconds(8),
Timeout = TimeSpan.FromSeconds(4),
},
ProbeTimeoutSeconds = 20,
};
var form = S7DriverPage.FormModel.FromOptions(opts);
var roundTripped = form.ToOptions();
roundTripped.Host.ShouldBe("192.168.1.50");
roundTripped.Port.ShouldBe(102);
roundTripped.CpuType.ShouldBe(S7CpuType.S7300);
roundTripped.Rack.ShouldBe((short)0);
roundTripped.Slot.ShouldBe((short)2);
roundTripped.Timeout.ShouldBe(TimeSpan.FromSeconds(7));
roundTripped.Probe.Enabled.ShouldBeTrue();
roundTripped.Probe.Interval.ShouldBe(TimeSpan.FromSeconds(8));
roundTripped.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(4));
roundTripped.ProbeTimeoutSeconds.ShouldBe(20);
}
}