bd6c0b4d3d
Add missing <returns>/<param>/<summary>/<typeparam> tags and clean up misused inheritdoc across 481 files so the documented API surface is complete. Documentation-only (zero code lines changed). The 131 remaining findings are inheritdoc-style warnings deliberately left to preserve hand-written implementation rationale (plan-decision notes, race-condition explanations).
157 lines
7.1 KiB
C#
157 lines
7.1 KiB
C#
using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
|
|
|
|
internal class FakeFocasClient : IFocasClient
|
|
{
|
|
/// <inheritdoc />
|
|
public bool IsConnected { get; private set; }
|
|
/// <summary>Gets the count of connection attempts.</summary>
|
|
public int ConnectCount { get; private set; }
|
|
/// <summary>Gets the count of dispose operations.</summary>
|
|
public int DisposeCount { get; private set; }
|
|
/// <summary>Gets or sets a value indicating whether to throw on connect.</summary>
|
|
public bool ThrowOnConnect { get; set; }
|
|
/// <summary>Gets or sets a value indicating whether to throw on read.</summary>
|
|
public bool ThrowOnRead { get; set; }
|
|
/// <summary>Gets or sets a value indicating whether to throw on write.</summary>
|
|
public bool ThrowOnWrite { get; set; }
|
|
/// <summary>Gets or sets the result of probe operations.</summary>
|
|
public bool ProbeResult { get; set; } = true;
|
|
/// <summary>Gets or sets the exception to throw.</summary>
|
|
public Exception? Exception { get; set; }
|
|
|
|
/// <summary>Gets the dictionary of read values keyed by address.</summary>
|
|
public Dictionary<string, object?> Values { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
/// <summary>Gets the dictionary of read statuses keyed by address.</summary>
|
|
public Dictionary<string, uint> ReadStatuses { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
/// <summary>Gets the dictionary of write statuses keyed by address.</summary>
|
|
public Dictionary<string, uint> WriteStatuses { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
/// <summary>Gets the log of write operations.</summary>
|
|
public List<(FocasAddress addr, FocasDataType type, object? value)> WriteLog { get; } = new();
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task ConnectAsync(FocasHostAddress address, TimeSpan timeout, CancellationToken ct)
|
|
{
|
|
ConnectCount++;
|
|
if (ThrowOnConnect) throw Exception ?? new InvalidOperationException();
|
|
IsConnected = true;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task<(object? value, uint status)> ReadAsync(
|
|
FocasAddress address, FocasDataType type, CancellationToken ct)
|
|
{
|
|
if (ThrowOnRead) throw Exception ?? new InvalidOperationException();
|
|
var key = address.Canonical;
|
|
var status = ReadStatuses.TryGetValue(key, out var s) ? s : FocasStatusMapper.Good;
|
|
var value = Values.TryGetValue(key, out var v) ? v : null;
|
|
return Task.FromResult((value, status));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task<uint> WriteAsync(
|
|
FocasAddress address, FocasDataType type, object? value, CancellationToken ct)
|
|
{
|
|
if (ThrowOnWrite) throw Exception ?? new InvalidOperationException();
|
|
WriteLog.Add((address, type, value));
|
|
Values[address.Canonical] = value;
|
|
var status = WriteStatuses.TryGetValue(address.Canonical, out var s) ? s : FocasStatusMapper.Good;
|
|
return Task.FromResult(status);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task<bool> ProbeAsync(CancellationToken ct) => Task.FromResult(ProbeResult);
|
|
|
|
/// <summary>Gets the list of active alarms.</summary>
|
|
public List<FocasActiveAlarm> Alarms { get; } = [];
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<FocasActiveAlarm>> ReadAlarmsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasActiveAlarm>>([.. Alarms]);
|
|
|
|
// ---- Fixed-tree T1 ----
|
|
/// <summary>Gets or sets the system information.</summary>
|
|
public FocasSysInfo SysInfo { get; set; } = new(0, 3, "M", "M", "30i", "A1.0", 3);
|
|
/// <summary>Gets the list of axis names.</summary>
|
|
public List<FocasAxisName> AxisNames { get; } = [new("X", ""), new("Y", ""), new("Z", "")];
|
|
/// <summary>Gets the list of spindle names.</summary>
|
|
public List<FocasSpindleName> SpindleNames { get; } = [new("S", "1", "", "")];
|
|
/// <summary>Gets the dictionary of dynamic snapshots keyed by axis index.</summary>
|
|
public Dictionary<int, FocasDynamicSnapshot> DynamicByAxis { get; } = [];
|
|
|
|
/// <inheritdoc />
|
|
public virtual Task<FocasSysInfo> GetSysInfoAsync(CancellationToken ct) => Task.FromResult(SysInfo);
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<FocasAxisName>> GetAxisNamesAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasAxisName>>([.. AxisNames]);
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<FocasSpindleName>> GetSpindleNamesAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasSpindleName>>([.. SpindleNames]);
|
|
/// <inheritdoc />
|
|
public virtual Task<FocasDynamicSnapshot> ReadDynamicAsync(int axisIndex, CancellationToken ct)
|
|
{
|
|
if (!DynamicByAxis.TryGetValue(axisIndex, out var snap))
|
|
snap = new FocasDynamicSnapshot(axisIndex, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
return Task.FromResult(snap);
|
|
}
|
|
|
|
/// <summary>Gets or sets the program information.</summary>
|
|
public FocasProgramInfo ProgramInfo { get; set; } = new("O0001", 1, 0, 1);
|
|
/// <inheritdoc />
|
|
public virtual Task<FocasProgramInfo> GetProgramInfoAsync(CancellationToken ct) =>
|
|
Task.FromResult(ProgramInfo);
|
|
|
|
/// <summary>Gets the dictionary of timers keyed by timer kind.</summary>
|
|
public Dictionary<FocasTimerKind, FocasTimer> Timers { get; } = [];
|
|
/// <inheritdoc />
|
|
public virtual Task<FocasTimer> GetTimerAsync(FocasTimerKind kind, CancellationToken ct)
|
|
{
|
|
if (!Timers.TryGetValue(kind, out var t))
|
|
t = new FocasTimer(kind, 0, 0);
|
|
return Task.FromResult(t);
|
|
}
|
|
|
|
/// <summary>Gets the list of servo loads.</summary>
|
|
public List<FocasServoLoad> ServoLoads { get; } = [];
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<FocasServoLoad>> GetServoLoadsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasServoLoad>>([.. ServoLoads]);
|
|
|
|
/// <summary>Gets the list of spindle loads.</summary>
|
|
public List<int> SpindleLoads { get; } = [];
|
|
/// <summary>Gets the list of spindle maximum RPMs.</summary>
|
|
public List<int> SpindleMaxRpms { get; } = [];
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<int>> GetSpindleLoadsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<int>>([.. SpindleLoads]);
|
|
/// <inheritdoc />
|
|
public virtual Task<IReadOnlyList<int>> GetSpindleMaxRpmsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<int>>([.. SpindleMaxRpms]);
|
|
|
|
/// <summary>Disposes the client.</summary>
|
|
public virtual void Dispose()
|
|
{
|
|
DisposeCount++;
|
|
IsConnected = false;
|
|
}
|
|
}
|
|
|
|
/// <summary>A factory for creating fake FOCAS clients.</summary>
|
|
internal sealed class FakeFocasClientFactory : IFocasClientFactory
|
|
{
|
|
/// <summary>Gets the list of created clients.</summary>
|
|
public List<FakeFocasClient> Clients { get; } = new();
|
|
/// <summary>Gets or sets a customization function for creating clients.</summary>
|
|
public Func<FakeFocasClient>? Customise { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public IFocasClient Create()
|
|
{
|
|
var c = Customise?.Invoke() ?? new FakeFocasClient();
|
|
Clients.Add(c);
|
|
return c;
|
|
}
|
|
}
|