using Shouldly; using Xunit; namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests; /// /// Task 2 coverage for / : /// defaults are sane (non-zero timers, probe on) and the required-field shape (AgentUri) binds. /// [Trait("Category", "Unit")] public sealed class MTConnectDriverOptionsTests { /// Default sample/heartbeat timers are non-zero and the probe is enabled by default. [Fact] public void Options_default_sample_and_heartbeat_are_sane() { var o = new MTConnectDriverOptions { AgentUri = "http://agent:5000" }; o.SampleIntervalMs.ShouldBeGreaterThan(0); o.HeartbeatMs.ShouldBeGreaterThan(0); o.Probe.Enabled.ShouldBeTrue(); } /// AgentUri is the only required field; DeviceName scope defaults to unset (agent-wide). [Fact] public void Options_agent_uri_is_required_device_name_defaults_to_null() { var o = new MTConnectDriverOptions { AgentUri = "http://agent:5000" }; o.AgentUri.ShouldBe("http://agent:5000"); o.DeviceName.ShouldBeNull(); } /// RequestTimeoutMs and SampleCount default to sane, non-zero, non-wedging values. [Fact] public void Options_request_timeout_and_sample_count_are_non_zero() { var o = new MTConnectDriverOptions { AgentUri = "http://agent:5000" }; o.RequestTimeoutMs.ShouldBeGreaterThan(0); o.SampleCount.ShouldBeGreaterThan(0); } /// Probe sub-options mirror ModbusProbeOptions' shape: Enabled/Interval/Timeout, both non-zero. [Fact] public void Probe_defaults_have_non_zero_interval_and_timeout() { var probe = new MTConnectDriverOptions { AgentUri = "http://agent:5000" }.Probe; probe.Interval.ShouldBeGreaterThan(TimeSpan.Zero); probe.Timeout.ShouldBeGreaterThan(TimeSpan.Zero); } /// Reconnect sub-options default to a bounded, non-degenerate geometric backoff. [Fact] public void Reconnect_defaults_bound_backoff_growth() { var reconnect = new MTConnectDriverOptions { AgentUri = "http://agent:5000" }.Reconnect; reconnect.MaxBackoffMs.ShouldBeGreaterThan(reconnect.MinBackoffMs); reconnect.BackoffMultiplier.ShouldBeGreaterThan(1.0); } /// MTConnectTagDefinition round-trips its positional fields, including MTConnect metadata. [Fact] public void TagDefinition_carries_dataItemId_and_mtconnect_metadata() { var tag = new MTConnectTagDefinition( FullName: "dtop_2", DriverDataType: ZB.MOM.WW.OtOpcUa.Core.Abstractions.DriverDataType.Float64, MtCategory: "SAMPLE", MtType: "POSITION", MtSubType: "ACTUAL", Units: "MILLIMETER"); tag.FullName.ShouldBe("dtop_2"); tag.DriverDataType.ShouldBe(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DriverDataType.Float64); tag.IsArray.ShouldBeFalse(); tag.ArrayDim.ShouldBe(0); tag.MtCategory.ShouldBe("SAMPLE"); tag.MtType.ShouldBe("POSITION"); tag.MtSubType.ShouldBe("ACTUAL"); tag.Units.ShouldBe("MILLIMETER"); } }