feat(driver-modbus): shared TagConfigJson readers, writable key, Inspect warnings (R2-11)
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Modbus;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// R2-11 (05/CONV-2) strictness surface for the Modbus equipment-tag parser: the runtime stays lenient
|
||||
/// (freeze), the new <c>Inspect</c> reports the silently-defaulted typo, and the <c>writable</c> key is
|
||||
/// now honoured (default true).
|
||||
/// </summary>
|
||||
public sealed class ModbusEquipmentTagParserStrictnessTests
|
||||
{
|
||||
// ---- Phase-A behaviour freeze: a typo'd enum still silently defaults ----
|
||||
|
||||
[Fact]
|
||||
public void Freeze_typo_dataType_still_defaults_to_Int16()
|
||||
{
|
||||
ModbusEquipmentTagParser.TryParse(
|
||||
"{\"region\":\"HoldingRegisters\",\"address\":1,\"dataType\":\"Intt16\"}", out var def)
|
||||
.ShouldBeTrue();
|
||||
def.DataType.ShouldBe(ModbusDataType.Int16);
|
||||
}
|
||||
|
||||
// ---- Inspect reports the typo ----
|
||||
|
||||
[Fact]
|
||||
public void Inspect_reports_typo_dataType_with_field_and_valid_values()
|
||||
{
|
||||
var warnings = ModbusEquipmentTagParser.Inspect(
|
||||
"{\"region\":\"HoldingRegisters\",\"address\":1,\"dataType\":\"Intt16\"}");
|
||||
warnings.ShouldHaveSingleItem();
|
||||
warnings[0].ShouldContain("Intt16");
|
||||
warnings[0].ShouldContain("dataType");
|
||||
warnings[0].ShouldContain("Int16");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inspect_clean_config_has_no_warnings()
|
||||
{
|
||||
ModbusEquipmentTagParser.Inspect(
|
||||
"{\"region\":\"HoldingRegisters\",\"address\":1,\"dataType\":\"Int16\"}")
|
||||
.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inspect_malformed_json_warns_unresolvable()
|
||||
{
|
||||
ModbusEquipmentTagParser.Inspect("{not json").ShouldHaveSingleItem();
|
||||
}
|
||||
|
||||
// ---- writable now honoured ----
|
||||
|
||||
[Fact]
|
||||
public void Writable_false_is_honoured()
|
||||
{
|
||||
ModbusEquipmentTagParser.TryParse(
|
||||
"{\"region\":\"HoldingRegisters\",\"address\":1,\"dataType\":\"Int16\",\"writable\":false}", out var def)
|
||||
.ShouldBeTrue();
|
||||
def.Writable.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Writable_absent_defaults_to_true()
|
||||
{
|
||||
ModbusEquipmentTagParser.TryParse(
|
||||
"{\"region\":\"HoldingRegisters\",\"address\":1,\"dataType\":\"Int16\"}", out var def)
|
||||
.ShouldBeTrue();
|
||||
def.Writable.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user