using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Core.Abstractions; using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.PlcFamilies; namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.IntegrationTests; /// /// PR 7 — wire-level smoke for contiguous PCCC array reads. One libplctag tag with /// elem_count=N pulls N consecutive words in a single PCCC frame; the driver decodes /// the buffer element-by-element + returns a typed .NET array. Skipped when the ab_server /// PCCC fixture isn't reachable. /// [Collection(AbLegacyServerCollection.Name)] [Trait("Category", "Integration")] [Trait("Simulator", "ab_server-PCCC")] public sealed class AbLegacyArrayReadTests(AbLegacyServerFixture sim) { [AbLegacyFact] public async Task Slc500_reads_ten_consecutive_N_file_words_in_one_frame() { if (sim.SkipReason is not null) Assert.Skip(sim.SkipReason); // Skip when the running compose profile isn't SLC500 — single ab_server container per // port, so the array test pins to one family at a time. The seeded `--tag=N7[120]` in // docker-compose.yml gives the simulator enough room for the contiguous read. var only = Environment.GetEnvironmentVariable("AB_LEGACY_COMPOSE_PROFILE"); if (!string.IsNullOrEmpty(only) && !string.Equals(only, "slc500", StringComparison.OrdinalIgnoreCase)) { Assert.Skip($"Test targets the SLC500 compose profile; AB_LEGACY_COMPOSE_PROFILE='{only}'."); } var deviceUri = $"ab://{sim.Host}:{sim.Port}/{sim.CipPath}"; await using var drv = new AbLegacyDriver(new AbLegacyDriverOptions { Devices = [new AbLegacyDeviceOptions(deviceUri, AbLegacyPlcFamily.Slc500)], Tags = [ new AbLegacyTagDefinition( Name: "Block", DeviceHostAddress: deviceUri, Address: "N7:0,10", DataType: AbLegacyDataType.Int), ], Timeout = TimeSpan.FromSeconds(5), Probe = new AbLegacyProbeOptions { Enabled = false }, }, driverInstanceId: "ablegacy-array-smoke"); await drv.InitializeAsync("{}", TestContext.Current.CancellationToken); var snapshots = await drv.ReadAsync(["Block"], TestContext.Current.CancellationToken); snapshots.Single().StatusCode.ShouldBe(AbLegacyStatusMapper.Good, "PCCC contiguous-block read of N7:0,10 must succeed against the SLC500 simulator"); var arr = snapshots.Single().Value.ShouldBeOfType(); arr.Length.ShouldBe(10); } }