using Serilog;
using Serilog.Core;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Core.Scripting;
namespace ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests;
///
/// In-memory for tests. Holds a tag dictionary + a write
/// log + a deterministic clock. Concrete subclasses in production will wire
/// GetTag/SetVirtualTag through the virtual-tag engine + driver dispatch; here they
/// hit a plain dictionary.
///
public sealed class FakeScriptContext : ScriptContext
{
/// Gets the dictionary of tags available in this context.
public Dictionary Tags { get; } = new(StringComparer.Ordinal);
/// Gets the log of virtual tag write operations.
public List<(string Path, object? Value)> Writes { get; } = [];
///
public override DateTime Now { get; } = new DateTime(2026, 1, 1, 12, 0, 0, DateTimeKind.Utc);
///
public override ILogger Logger { get; } = new LoggerConfiguration().CreateLogger();
///
public override DataValueSnapshot GetTag(string path)
{
return Tags.TryGetValue(path, out var v)
? v
: new DataValueSnapshot(null, 0x80340000u, null, Now); // BadNodeIdUnknown
}
///
public override void SetVirtualTag(string path, object? value)
{
Writes.Add((path, value));
}
/// Seeds the context with a tag value for testing.
/// The tag path.
/// The tag value.
/// The OPC UA status code (default: 0).
/// The source timestamp (default: ).
/// This instance for method chaining.
public FakeScriptContext Seed(string path, object? value,
uint statusCode = 0u, DateTime? sourceTs = null)
{
Tags[path] = new DataValueSnapshot(value, statusCode, sourceTs ?? Now, Now);
return this;
}
}