using System;
using ArchestrA;
using ZB.MOM.WW.LmxOpcUa.Host.Configuration;
using ZB.MOM.WW.LmxOpcUa.Host.Historian;
namespace ZB.MOM.WW.LmxOpcUa.Tests.Helpers
{
///
/// Fake Historian connection factory for tests. Controls whether connections
/// succeed, fail, or timeout without requiring the real Historian SDK runtime.
///
internal sealed class FakeHistorianConnectionFactory : IHistorianConnectionFactory
{
///
/// When set, throws this exception.
///
public Exception? ConnectException { get; set; }
///
/// Number of times has been called.
///
public int ConnectCallCount { get; private set; }
///
/// When set, called on each to determine behavior.
/// Receives the call count (1-based). Return null to succeed, or throw to fail.
///
public Action? OnConnect { get; set; }
public HistorianAccess CreateAndConnect(HistorianConfiguration config, HistorianConnectionType type)
{
ConnectCallCount++;
if (OnConnect != null)
{
OnConnect(ConnectCallCount);
}
else if (ConnectException != null)
{
throw ConnectException;
}
// Return a HistorianAccess that is not actually connected.
// ReadRawAsync etc. will fail when they try to use it, which exercises
// the HandleConnectionError → reconnect path.
return new HistorianAccess();
}
}
}