fix(driver-s7-cli): resolve Medium code-review finding (Driver.S7.Cli-001)

Wrap all numeric/DateTime BCL parses in ParseValue with try/catch(FormatException)
and try/catch(OverflowException) that re-throw as CommandException, matching the
existing Bool path. Update ParseValue_non_numeric_for_numeric_types_throws to assert
CommandException (not FormatException), and add an overflow-edge test (Byte value 256).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 10:17:25 -04:00
parent aeb5fc48ae
commit 01a6b6d859
2 changed files with 54 additions and 18 deletions

View File

@@ -99,10 +99,20 @@ public sealed class WriteCommandParseValueTests
[Fact]
public void ParseValue_non_numeric_for_numeric_types_throws()
{
Should.Throw<FormatException>(
// Driver.S7.Cli-001: malformed input must produce a clean CommandException
// (friendly one-line error), not a raw FormatException stack trace.
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("xyz", S7DataType.Int16));
}
[Fact]
public void ParseValue_overflow_for_numeric_types_throws_CommandException()
{
// OverflowException from out-of-range input must also surface as CommandException.
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("256", S7DataType.Byte));
}
[Theory]
[InlineData("DB1.DBW0", S7DataType.Int16, "DB1.DBW0:Int16")]
[InlineData("M0.0", S7DataType.Bool, "M0.0:Bool")]