fix(mtconnect): options carry the authored tag definitions (Task 2 follow-up)
This commit is contained in:
@@ -54,6 +54,21 @@ public sealed class MTConnectDriverOptions
|
||||
/// </summary>
|
||||
public int HeartbeatMs { get; init; } = 10000;
|
||||
|
||||
/// <summary>
|
||||
/// The authored tags this driver instance serves — one <see cref="MTConnectTagDefinition"/>
|
||||
/// per tag, keyed by the DataItem <c>id</c> it binds
|
||||
/// (<see cref="MTConnectTagDefinition.FullName"/>). The factory config DTO carries these and
|
||||
/// builds them into the options; the driver indexes them to know each tag's target
|
||||
/// <see cref="MTConnectTagDefinition.DriverDataType"/> when coercing an Agent observation
|
||||
/// (whose wire form is always text) into a published value.
|
||||
/// <para>
|
||||
/// Defaults to <b>empty, never <c>null</c></b>: a driver instance may legitimately be
|
||||
/// authored with no tags yet, and a null collection here would surface as a
|
||||
/// NullReferenceException at deploy time from operator-authored config.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public IReadOnlyList<MTConnectTagDefinition> Tags { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Background connectivity-probe settings. When <see cref="MTConnectProbeOptions.Enabled"/>
|
||||
/// is true the driver periodically issues a cheap <c>/probe</c> request and raises
|
||||
|
||||
@@ -56,6 +56,47 @@ public sealed class MTConnectDriverOptionsTests
|
||||
reconnect.BackoffMultiplier.ShouldBeGreaterThan(1.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MTConnectDriverOptions.Tags"/> defaults to an <i>empty</i> collection, never
|
||||
/// <c>null</c> — a null collection here is an operator-authorable NullReferenceException at
|
||||
/// deploy, since a driver instance authored with no tags binds this default.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Options_tags_default_to_empty_and_are_never_null()
|
||||
{
|
||||
var o = new MTConnectDriverOptions { AgentUri = "http://agent:5000" };
|
||||
|
||||
o.Tags.ShouldNotBeNull();
|
||||
o.Tags.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A populated options object carries the authored tag definitions through unchanged —
|
||||
/// the observation index (Task 8) coerces each present observation to <i>its tag's</i>
|
||||
/// DriverDataType, so the definitions must reach the driver from the factory config.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Options_round_trip_the_authored_tag_definitions()
|
||||
{
|
||||
var pos = new MTConnectTagDefinition(
|
||||
FullName: "dev1_pos",
|
||||
DriverDataType: ZB.MOM.WW.OtOpcUa.Core.Abstractions.DriverDataType.Float64,
|
||||
MtCategory: "SAMPLE",
|
||||
MtType: "POSITION",
|
||||
Units: "MILLIMETER");
|
||||
var partCount = new MTConnectTagDefinition(
|
||||
FullName: "dev1_partcount",
|
||||
DriverDataType: ZB.MOM.WW.OtOpcUa.Core.Abstractions.DriverDataType.Int64,
|
||||
MtCategory: "EVENT",
|
||||
MtType: "PART_COUNT");
|
||||
|
||||
var o = new MTConnectDriverOptions { AgentUri = "http://agent:5000", Tags = [pos, partCount] };
|
||||
|
||||
o.Tags.Count.ShouldBe(2);
|
||||
o.Tags[0].ShouldBe(pos);
|
||||
o.Tags[1].ShouldBe(partCount);
|
||||
}
|
||||
|
||||
/// <summary>MTConnectTagDefinition round-trips its positional fields, including MTConnect metadata.</summary>
|
||||
[Fact]
|
||||
public void TagDefinition_carries_dataItemId_and_mtconnect_metadata()
|
||||
|
||||
Reference in New Issue
Block a user