6a616a1ab2
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.
143 lines
5.5 KiB
C#
143 lines
5.5 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.AbCip;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
|
|
|
|
public sealed class AbCipDriverPageFormSerializationTests
|
|
{
|
|
private static readonly JsonSerializerOptions _opts = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
WriteIndented = false,
|
|
};
|
|
|
|
private static readonly JsonSerializerOptions TestJsonOpts = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
|
};
|
|
|
|
[Fact]
|
|
public void RoundTrip_PreservesKnownFields()
|
|
{
|
|
var original = new AbCipDriverOptions
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(5),
|
|
EnableControllerBrowse = true,
|
|
EnableAlarmProjection = true,
|
|
AlarmPollInterval = TimeSpan.FromSeconds(2),
|
|
EnableDeclarationOnlyUdtGrouping = true,
|
|
Probe = new AbCipProbeOptions
|
|
{
|
|
Enabled = true,
|
|
Interval = TimeSpan.FromSeconds(10),
|
|
Timeout = TimeSpan.FromSeconds(3),
|
|
ProbeTagPath = "Program:Main.HealthBit",
|
|
},
|
|
ProbeTimeoutSeconds = 10,
|
|
Devices =
|
|
[
|
|
new AbCipDeviceOptions("ab://10.0.0.1/1,0", AbCipPlcFamily.ControlLogix, "PLC-1"),
|
|
],
|
|
};
|
|
|
|
var json = JsonSerializer.Serialize(original, _opts);
|
|
var back = JsonSerializer.Deserialize<AbCipDriverOptions>(json, _opts);
|
|
|
|
back.ShouldNotBeNull();
|
|
back.Timeout.ShouldBe(TimeSpan.FromSeconds(5));
|
|
back.EnableControllerBrowse.ShouldBeTrue();
|
|
back.EnableAlarmProjection.ShouldBeTrue();
|
|
back.AlarmPollInterval.ShouldBe(TimeSpan.FromSeconds(2));
|
|
back.EnableDeclarationOnlyUdtGrouping.ShouldBeTrue();
|
|
back.Probe.Enabled.ShouldBeTrue();
|
|
back.Probe.Interval.ShouldBe(TimeSpan.FromSeconds(10));
|
|
back.Probe.Timeout.ShouldBe(TimeSpan.FromSeconds(3));
|
|
back.Probe.ProbeTagPath.ShouldBe("Program:Main.HealthBit");
|
|
back.ProbeTimeoutSeconds.ShouldBe(10);
|
|
back.Devices.Count.ShouldBe(1);
|
|
back.Devices[0].HostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
|
back.Devices[0].PlcFamily.ShouldBe(AbCipPlcFamily.ControlLogix);
|
|
}
|
|
|
|
[Fact]
|
|
public void Deserialize_DropsUnknownFields()
|
|
{
|
|
var jsonWithExtra = """{"unknownField":"old-value","probeTimeoutSeconds":10}""";
|
|
|
|
var optsWithSkip = new JsonSerializerOptions(_opts)
|
|
{
|
|
UnmappedMemberHandling = JsonUnmappedMemberHandling.Skip,
|
|
};
|
|
|
|
var back = JsonSerializer.Deserialize<AbCipDriverOptions>(jsonWithExtra, optsWithSkip);
|
|
back.ShouldNotBeNull();
|
|
back.ProbeTimeoutSeconds.ShouldBe(10);
|
|
}
|
|
|
|
[Fact]
|
|
public void DeviceRow_round_trips_through_definition()
|
|
{
|
|
var row = new AbCipDriverPage.AbCipDeviceRow
|
|
{
|
|
HostAddress = "ab://10.0.0.1/1,0", PlcFamily = AbCipPlcFamily.CompactLogix, DeviceName = "PLC-A",
|
|
};
|
|
var def = row.ToDefinition();
|
|
var back = AbCipDriverPage.AbCipDeviceRow.FromDefinition(def);
|
|
|
|
back.HostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
|
back.PlcFamily.ShouldBe(AbCipPlcFamily.CompactLogix);
|
|
back.DeviceName.ShouldBe("PLC-A");
|
|
}
|
|
|
|
[Fact]
|
|
public void DeviceRow_preserves_unedited_fields()
|
|
{
|
|
var original = new AbCipDeviceOptions(
|
|
"ab://10.0.0.1/1,0", AbCipPlcFamily.ControlLogix, "PLC-A",
|
|
AllowPacking: true, ConnectionSize: 4002);
|
|
var row = AbCipDriverPage.AbCipDeviceRow.FromDefinition(original);
|
|
row.HostAddress = "ab://10.0.0.2/1,0";
|
|
|
|
var back = row.ToDefinition();
|
|
back.HostAddress.ShouldBe("ab://10.0.0.2/1,0");
|
|
back.AllowPacking.ShouldBe(true);
|
|
back.ConnectionSize.ShouldBe(4002);
|
|
}
|
|
|
|
// v3 Batch-1 migration: the pre-declared Tags editor (AbCipDriverPage.AbCipTagRow +
|
|
// AbCipDriverOptions.Tags) was retired — tags moved to the Raw tree (/raw, Batch 2). The former
|
|
// TagRow_* / ValidateTagRow_* tests and the tag leg of the list-serialization test were removed.
|
|
// The multi-device Devices editor is RETAINED, so its coverage (DeviceRow_* + ValidateDeviceRow_*
|
|
// + the device-list serialization below, all carrying the AbCipPlcFamily enum) stays.
|
|
|
|
[Fact]
|
|
public void ValidateDeviceRow_rejects_duplicate_host()
|
|
{
|
|
var rows = new List<AbCipDriverPage.AbCipDeviceRow> { new() { HostAddress = "ab://10.0.0.1/1,0" } };
|
|
AbCipDriverPage.AbCipDeviceRow.ValidateRow(new() { HostAddress = "ab://10.0.0.1/1,0" }, rows, null)
|
|
.ShouldNotBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void Device_list_survives_options_serialize_round_trip()
|
|
{
|
|
var devices = new List<AbCipDeviceOptions>
|
|
{
|
|
new("ab://10.0.0.1/1,0", AbCipPlcFamily.ControlLogix, "PLC-1"),
|
|
new("ab://10.0.0.2/1,0", AbCipPlcFamily.CompactLogix, "PLC-2"),
|
|
};
|
|
var opts = new AbCipDriverPage.FormModel().ToOptions(devices);
|
|
var json = JsonSerializer.Serialize(opts, TestJsonOpts);
|
|
var back = JsonSerializer.Deserialize<AbCipDriverOptions>(json, TestJsonOpts)!;
|
|
back.Devices.Count.ShouldBe(2);
|
|
back.Devices[0].HostAddress.ShouldBe("ab://10.0.0.1/1,0");
|
|
back.Devices[0].PlcFamily.ShouldBe(AbCipPlcFamily.ControlLogix);
|
|
back.Devices[1].PlcFamily.ShouldBe(AbCipPlcFamily.CompactLogix);
|
|
}
|
|
}
|