using CliFx.Infrastructure;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Commands;
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Tests;
///
/// Covers Driver.Modbus.Cli-010: must reject a non-positive
/// --interval-ms before touching the driver so the operator gets a clear
/// rather than a downstream failure deep
/// inside PollGroupEngine. Mirrors the ValidateInterval guard in
/// Driver.AbCip.Cli.SubscribeCommand.
///
[Trait("Category", "Unit")]
public sealed class SubscribeCommandValidationTests
{
/// Verifies that ValidateInterval rejects zero and negative interval values.
/// The invalid interval in milliseconds to test.
[Theory]
[InlineData(0)]
[InlineData(-1)]
[InlineData(-1000)]
public void ValidateInterval_rejects_non_positive_interval(int intervalMs)
{
Should.Throw(
() => SubscribeCommand.ValidateInterval(intervalMs));
}
/// Verifies that ValidateInterval accepts strictly positive interval values.
/// The valid interval in milliseconds to test.
[Theory]
[InlineData(1)]
[InlineData(250)]
[InlineData(1000)]
[InlineData(5000)]
public void ValidateInterval_accepts_positive_interval(int intervalMs)
{
Should.NotThrow(() => SubscribeCommand.ValidateInterval(intervalMs));
}
///
/// Verifies that ExecuteAsync throws
/// when --interval-ms is non-positive, before any driver I/O.
///
[Fact]
public async Task ExecuteAsync_rejects_zero_interval_before_driver_connect()
{
var sut = new SubscribeCommand
{
Host = "127.0.0.1",
Region = ModbusRegion.HoldingRegisters,
Address = 0,
DataType = ModbusDataType.UInt16,
IntervalMs = 0,
};
using var console = new FakeInMemoryConsole();
await Should.ThrowAsync(
async () => await sut.ExecuteAsync(console));
}
}