Group all 69 projects into category subfolders under src/ and tests/ so the Rider Solution Explorer mirrors the module structure. Folders: Core, Server, Drivers (with a nested Driver CLIs subfolder), Client, Tooling. - Move every project folder on disk with git mv (history preserved as renames). - Recompute relative paths in 57 .csproj files: cross-category ProjectReferences, the lib/ HintPath+None refs in Driver.Historian.Wonderware, and the external mxaccessgw refs in Driver.Galaxy and its test project. - Rebuild ZB.MOM.WW.OtOpcUa.slnx with nested solution folders. - Re-prefix project paths in functional scripts (e2e, compliance, smoke SQL, integration, install). Build green (0 errors); unit tests pass. Docs left for a separate pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
116 lines
5.0 KiB
C#
116 lines
5.0 KiB
C#
using ZB.MOM.WW.OtOpcUa.Driver.FOCAS;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
|
|
|
|
internal class FakeFocasClient : IFocasClient
|
|
{
|
|
public bool IsConnected { get; private set; }
|
|
public int ConnectCount { get; private set; }
|
|
public int DisposeCount { get; private set; }
|
|
public bool ThrowOnConnect { get; set; }
|
|
public bool ThrowOnRead { get; set; }
|
|
public bool ThrowOnWrite { get; set; }
|
|
public bool ProbeResult { get; set; } = true;
|
|
public Exception? Exception { get; set; }
|
|
|
|
public Dictionary<string, object?> Values { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
public Dictionary<string, uint> ReadStatuses { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
public Dictionary<string, uint> WriteStatuses { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
public List<(FocasAddress addr, FocasDataType type, object? value)> WriteLog { get; } = new();
|
|
|
|
public virtual Task ConnectAsync(FocasHostAddress address, TimeSpan timeout, CancellationToken ct)
|
|
{
|
|
ConnectCount++;
|
|
if (ThrowOnConnect) throw Exception ?? new InvalidOperationException();
|
|
IsConnected = true;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
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));
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public virtual Task<bool> ProbeAsync(CancellationToken ct) => Task.FromResult(ProbeResult);
|
|
|
|
public List<FocasActiveAlarm> Alarms { get; } = [];
|
|
|
|
public virtual Task<IReadOnlyList<FocasActiveAlarm>> ReadAlarmsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasActiveAlarm>>([.. Alarms]);
|
|
|
|
// ---- Fixed-tree T1 ----
|
|
public FocasSysInfo SysInfo { get; set; } = new(0, 3, "M", "M", "30i", "A1.0", 3);
|
|
public List<FocasAxisName> AxisNames { get; } = [new("X", ""), new("Y", ""), new("Z", "")];
|
|
public List<FocasSpindleName> SpindleNames { get; } = [new("S", "1", "", "")];
|
|
public Dictionary<int, FocasDynamicSnapshot> DynamicByAxis { get; } = [];
|
|
|
|
public virtual Task<FocasSysInfo> GetSysInfoAsync(CancellationToken ct) => Task.FromResult(SysInfo);
|
|
public virtual Task<IReadOnlyList<FocasAxisName>> GetAxisNamesAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasAxisName>>([.. AxisNames]);
|
|
public virtual Task<IReadOnlyList<FocasSpindleName>> GetSpindleNamesAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasSpindleName>>([.. SpindleNames]);
|
|
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);
|
|
}
|
|
|
|
public FocasProgramInfo ProgramInfo { get; set; } = new("O0001", 1, 0, 1);
|
|
public virtual Task<FocasProgramInfo> GetProgramInfoAsync(CancellationToken ct) =>
|
|
Task.FromResult(ProgramInfo);
|
|
|
|
public Dictionary<FocasTimerKind, FocasTimer> Timers { get; } = [];
|
|
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);
|
|
}
|
|
|
|
public List<FocasServoLoad> ServoLoads { get; } = [];
|
|
public virtual Task<IReadOnlyList<FocasServoLoad>> GetServoLoadsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<FocasServoLoad>>([.. ServoLoads]);
|
|
|
|
public List<int> SpindleLoads { get; } = [];
|
|
public List<int> SpindleMaxRpms { get; } = [];
|
|
public virtual Task<IReadOnlyList<int>> GetSpindleLoadsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<int>>([.. SpindleLoads]);
|
|
public virtual Task<IReadOnlyList<int>> GetSpindleMaxRpmsAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyList<int>>([.. SpindleMaxRpms]);
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
DisposeCount++;
|
|
IsConnected = false;
|
|
}
|
|
}
|
|
|
|
internal sealed class FakeFocasClientFactory : IFocasClientFactory
|
|
{
|
|
public List<FakeFocasClient> Clients { get; } = new();
|
|
public Func<FakeFocasClient>? Customise { get; set; }
|
|
|
|
public IFocasClient Create()
|
|
{
|
|
var c = Customise?.Invoke() ?? new FakeFocasClient();
|
|
Clients.Add(c);
|
|
return c;
|
|
}
|
|
}
|