using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using S7NetDataType = global::S7.Net.DataType;
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Tests;
///
/// Shared in-memory recorder used across the S7 driver
/// test suite. Captures every folder + variable the driver projects via
/// so a test can assert the discovered shape without a
/// live address space. Replaces the three structurally-identical per-file recorders
/// (RecordingAddressSpaceBuilder/RecordingBuilder/CapturingBuilder) that
/// previously duplicated this code.
///
internal sealed class RecordingAddressSpaceBuilder : IAddressSpaceBuilder
{
/// Browse names of every folder the driver created, in order.
public readonly List Folders = new();
/// Every variable the driver created, as (browse name, attribute info) pairs.
public readonly List<(string Name, DriverAttributeInfo Attr)> Variables = new();
/// Records the folder browse name and returns this builder for chaining.
/// The browse name of the folder.
/// The display name of the folder.
/// This builder instance for method chaining.
public IAddressSpaceBuilder Folder(string browseName, string displayName)
{
Folders.Add(browseName);
return this;
}
/// Records the variable's browse name + attribute info.
/// The browse name of the variable.
/// The display name of the variable.
/// The attribute information for the variable.
/// A stub handle.
public IVariableHandle Variable(string browseName, string displayName, DriverAttributeInfo attributeInfo)
{
Variables.Add((browseName, attributeInfo));
return new StubHandle();
}
/// No-op property sink — the S7 driver does not add properties.
/// The browse name of the property.
/// The data type of the property.
/// The initial value of the property.
public void AddProperty(string browseName, DriverDataType dataType, object? value) { }
/// No-op alarm sink — the S7 driver never surfaces alarms.
/// The variable to attach the alarm to.
/// The name of the alarm.
/// The alarm information.
public void AttachAlarmCondition(IVariableHandle sourceVariable, string alarmName, DriverAttributeInfo alarmInfo) { }
private sealed class StubHandle : IVariableHandle
{
/// Gets the full reference of the variable.
public string FullReference => "stub";
/// Marks this variable as an alarm condition.
/// The alarm condition information.
/// An alarm condition sink.
public IAlarmConditionSink MarkAsAlarmCondition(AlarmConditionInfo info)
=> throw new NotImplementedException("S7 driver never calls this — no alarm surfacing");
}
}
///
/// Minimal whose connection opens cleanly and answers the CPU-status
/// probe, but serves no data. Used by the tests that need the driver Initialized — which in
/// v3 is what builds the RawPath → definition table projects —
/// without a live PLC or wire I/O.
///
internal sealed class ConnectingFakeS7PlcFactory : IS7PlcFactory
{
/// Creates a fresh connecting fake connection.
public IS7Plc Create(S7CpuType cpuType, string host, int port, short rack, short slot, TimeSpan timeout)
=> new ConnectingFakeS7Plc();
private sealed class ConnectingFakeS7Plc : IS7Plc
{
/// Gets a value indicating whether the fake connection is open.
public bool IsConnected { get; private set; }
/// Opens the fake connection.
public Task OpenAsync(CancellationToken ct) { IsConnected = true; return Task.CompletedTask; }
/// Closes the fake connection.
public void Close() => IsConnected = false;
/// Not exercised by these tests.
public Task