feat(scripting): evaluators log through root script logger → script-log page (F8)
This commit is contained in:
@@ -101,4 +101,64 @@ public sealed class ScriptLoggerFactoryTests
|
||||
// this exact string. If it changes, the filter breaks silently.
|
||||
ScriptLoggerFactory.ScriptNameProperty.ShouldBe("ScriptName");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A logger from the identity overload, when written through a
|
||||
/// <see cref="ScriptLogTopicSink"/>, produces an entry carrying every bound id.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Create_identity_overload_binds_ids_onto_published_entry()
|
||||
{
|
||||
var publisher = new FakePublisher();
|
||||
var root = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.WriteTo.Sink(new ScriptLogTopicSink(publisher, LogEventLevel.Information))
|
||||
.CreateLogger();
|
||||
var factory = new ScriptLoggerFactory(root);
|
||||
|
||||
var logger = factory.Create(
|
||||
scriptId: "S9", virtualTagId: "V9", alarmId: "A9", equipmentId: "EQ9");
|
||||
logger.Information("typed identity");
|
||||
|
||||
publisher.Published.Count.ShouldBe(1);
|
||||
var entry = publisher.Published[0];
|
||||
entry.ScriptId.ShouldBe("S9");
|
||||
entry.VirtualTagId.ShouldBe("V9");
|
||||
entry.AlarmId.ShouldBe("A9");
|
||||
entry.EquipmentId.ShouldBe("EQ9");
|
||||
entry.Message.ShouldBe("typed identity");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The identity overload leaves optional ids unbound (null on the entry) when not
|
||||
/// supplied, binding only <c>ScriptId</c>.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Create_identity_overload_leaves_optional_ids_null_when_absent()
|
||||
{
|
||||
var publisher = new FakePublisher();
|
||||
var root = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose()
|
||||
.WriteTo.Sink(new ScriptLogTopicSink(publisher, LogEventLevel.Information))
|
||||
.CreateLogger();
|
||||
var factory = new ScriptLoggerFactory(root);
|
||||
|
||||
factory.Create(scriptId: "S10").Information("only script id");
|
||||
|
||||
var entry = publisher.Published[0];
|
||||
entry.ScriptId.ShouldBe("S10");
|
||||
entry.VirtualTagId.ShouldBeNull();
|
||||
entry.AlarmId.ShouldBeNull();
|
||||
entry.EquipmentId.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>Capturing publisher for the identity-overload sink tests.</summary>
|
||||
private sealed class FakePublisher : IScriptLogPublisher
|
||||
{
|
||||
/// <summary>Gets the entries published so far.</summary>
|
||||
public List<Commons.Messages.Logging.ScriptLogEntry> Published { get; } = [];
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Publish(Commons.Messages.Logging.ScriptLogEntry entry) => Published.Add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user