chore: organize solution into module folders (Core/Server/Drivers/Client/Tooling)
Group all 69 projects into category subfolders under src/ and tests/ so the Rider Solution Explorer mirrors the module structure. Folders: Core, Server, Drivers (with a nested Driver CLIs subfolder), Client, Tooling. - Move every project folder on disk with git mv (history preserved as renames). - Recompute relative paths in 57 .csproj files: cross-category ProjectReferences, the lib/ HintPath+None refs in Driver.Historian.Wonderware, and the external mxaccessgw refs in Driver.Galaxy and its test project. - Rebuild ZB.MOM.WW.OtOpcUa.slnx with nested solution folders. - Re-prefix project paths in functional scripts (e2e, compliance, smoke SQL, integration, install). Build green (0 errors); unit tests pass. Docs left for a separate pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Covers <see cref="WriteCommand.ParseValue"/>. Every Logix atomic type has at least
|
||||
/// one happy-path case plus a failure case for unparseable input.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class WriteCommandParseValueTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("on", true)]
|
||||
[InlineData("NO", false)]
|
||||
public void ParseValue_Bool_accepts_common_aliases(string raw, bool expected)
|
||||
{
|
||||
WriteCommand.ParseValue(raw, AbCipDataType.Bool).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Bool_rejects_garbage()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("maybe", AbCipDataType.Bool));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_SInt_widens_to_sbyte()
|
||||
{
|
||||
WriteCommand.ParseValue("-128", AbCipDataType.SInt).ShouldBe((sbyte)-128);
|
||||
WriteCommand.ParseValue("127", AbCipDataType.SInt).ShouldBe((sbyte)127);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int_signed_16bit()
|
||||
{
|
||||
WriteCommand.ParseValue("-32768", AbCipDataType.Int).ShouldBe((short)-32768);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_DInt_and_Dt_both_land_on_int()
|
||||
{
|
||||
WriteCommand.ParseValue("42", AbCipDataType.DInt).ShouldBeOfType<int>();
|
||||
WriteCommand.ParseValue("1234567", AbCipDataType.Dt).ShouldBeOfType<int>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_LInt_64bit()
|
||||
{
|
||||
WriteCommand.ParseValue("9223372036854775807", AbCipDataType.LInt).ShouldBe(long.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_unsigned_range_respects_bounds()
|
||||
{
|
||||
WriteCommand.ParseValue("255", AbCipDataType.USInt).ShouldBeOfType<byte>();
|
||||
WriteCommand.ParseValue("65535", AbCipDataType.UInt).ShouldBeOfType<ushort>();
|
||||
WriteCommand.ParseValue("4294967295", AbCipDataType.UDInt).ShouldBeOfType<uint>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Real_invariant_culture_decimal()
|
||||
{
|
||||
WriteCommand.ParseValue("3.14", AbCipDataType.Real).ShouldBe(3.14f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_LReal_handles_double_precision()
|
||||
{
|
||||
WriteCommand.ParseValue("2.718281828", AbCipDataType.LReal).ShouldBeOfType<double>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_String_passthrough()
|
||||
{
|
||||
WriteCommand.ParseValue("hello logix", AbCipDataType.String).ShouldBe("hello logix");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_non_numeric_for_numeric_types_throws()
|
||||
{
|
||||
Should.Throw<FormatException>(
|
||||
() => WriteCommand.ParseValue("xyz", AbCipDataType.DInt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Motor01_Speed", AbCipDataType.Real, "Motor01_Speed:Real")]
|
||||
[InlineData("Program:Main.Counter", AbCipDataType.DInt, "Program:Main.Counter:DInt")]
|
||||
[InlineData("Recipe[3]", AbCipDataType.Int, "Recipe[3]:Int")]
|
||||
public void SynthesiseTagName_preserves_path_verbatim(
|
||||
string path, AbCipDataType type, string expected)
|
||||
{
|
||||
ReadCommand.SynthesiseTagName(path, type).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli\ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,91 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Covers <see cref="WriteCommand.ParseValue"/>. PCCC types are narrower than AB CIP
|
||||
/// (no 64-bit, no unsigned variants, no Structure / Dt) so the matrix is smaller.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class WriteCommandParseValueTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("yes", true)]
|
||||
[InlineData("OFF", false)]
|
||||
public void ParseValue_Bit_accepts_common_aliases(string raw, bool expected)
|
||||
{
|
||||
WriteCommand.ParseValue(raw, AbLegacyDataType.Bit).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int_signed_16bit()
|
||||
{
|
||||
WriteCommand.ParseValue("-32768", AbLegacyDataType.Int).ShouldBe((short)-32768);
|
||||
WriteCommand.ParseValue("32767", AbLegacyDataType.Int).ShouldBe((short)32767);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_AnalogInt_parses_same_as_Int()
|
||||
{
|
||||
// A-file uses N-file semantics — 16-bit signed with the same wire format.
|
||||
WriteCommand.ParseValue("100", AbLegacyDataType.AnalogInt).ShouldBeOfType<short>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Long_32bit()
|
||||
{
|
||||
WriteCommand.ParseValue("-2147483648", AbLegacyDataType.Long).ShouldBe(int.MinValue);
|
||||
WriteCommand.ParseValue("2147483647", AbLegacyDataType.Long).ShouldBe(int.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Float_invariant_culture()
|
||||
{
|
||||
WriteCommand.ParseValue("3.14", AbLegacyDataType.Float).ShouldBe(3.14f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_String_passthrough()
|
||||
{
|
||||
WriteCommand.ParseValue("hello slc", AbLegacyDataType.String).ShouldBe("hello slc");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(AbLegacyDataType.TimerElement)]
|
||||
[InlineData(AbLegacyDataType.CounterElement)]
|
||||
[InlineData(AbLegacyDataType.ControlElement)]
|
||||
public void ParseValue_Element_types_land_on_int32(AbLegacyDataType type)
|
||||
{
|
||||
// T/C/R sub-elements are 32-bit at the wire level regardless of semantic meaning.
|
||||
WriteCommand.ParseValue("42", type).ShouldBeOfType<int>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Bit_rejects_unknown_strings()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("perhaps", AbLegacyDataType.Bit));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_non_numeric_for_numeric_types_throws()
|
||||
{
|
||||
Should.Throw<FormatException>(
|
||||
() => WriteCommand.ParseValue("xyz", AbLegacyDataType.Int));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("N7:0", AbLegacyDataType.Int, "N7:0:Int")]
|
||||
[InlineData("B3:0/3", AbLegacyDataType.Bit, "B3:0/3:Bit")]
|
||||
[InlineData("F8:10", AbLegacyDataType.Float, "F8:10:Float")]
|
||||
[InlineData("T4:0.ACC", AbLegacyDataType.TimerElement, "T4:0.ACC:TimerElement")]
|
||||
public void SynthesiseTagName_preserves_PCCC_address_verbatim(
|
||||
string address, AbLegacyDataType type, string expected)
|
||||
{
|
||||
ReadCommand.SynthesiseTagName(address, type).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli\ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,123 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Cli.Common;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Cli.Common.Tests;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class SnapshotFormatterTests
|
||||
{
|
||||
private static readonly DateTime FixedTime =
|
||||
new(2026, 4, 21, 12, 34, 56, 789, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void Format_includes_tag_value_status_and_both_timestamps()
|
||||
{
|
||||
var snap = new DataValueSnapshot(42, 0u, FixedTime, FixedTime);
|
||||
var output = SnapshotFormatter.Format("N7:0", snap);
|
||||
|
||||
output.ShouldContain("Tag: N7:0");
|
||||
output.ShouldContain("Value: 42");
|
||||
output.ShouldContain("Status: 0x00000000 (Good)");
|
||||
output.ShouldContain("Source Time: 2026-04-21T12:34:56.789Z");
|
||||
output.ShouldContain("Server Time: 2026-04-21T12:34:56.789Z");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x00000000u, "Good")]
|
||||
[InlineData(0x80000000u, "Bad")]
|
||||
[InlineData(0x80050000u, "BadCommunicationError")]
|
||||
[InlineData(0x80060000u, "BadTimeout")]
|
||||
[InlineData(0x80340000u, "BadNodeIdUnknown")]
|
||||
[InlineData(0x40000000u, "Uncertain")]
|
||||
public void FormatStatus_names_well_known_status_codes(uint status, string expectedName)
|
||||
{
|
||||
SnapshotFormatter.FormatStatus(status).ShouldContain(expectedName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatStatus_unknown_codes_fall_back_to_hex_only()
|
||||
{
|
||||
// 0xDEADBEEF isn't in the shortlist — just render the hex form, no name.
|
||||
SnapshotFormatter.FormatStatus(0xDEADBEEFu).ShouldBe("0xDEADBEEF");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatValue_renders_null_as_placeholder()
|
||||
{
|
||||
var snap = new DataValueSnapshot(null, 0x80050000u, null, FixedTime);
|
||||
var output = SnapshotFormatter.Format("Orphan", snap);
|
||||
output.ShouldContain("Value: <null>");
|
||||
output.ShouldContain("Source Time: -"); // null timestamp → dash
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatValue_formats_booleans_lowercase()
|
||||
{
|
||||
var snap = new DataValueSnapshot(true, 0u, FixedTime, FixedTime);
|
||||
SnapshotFormatter.Format("Coil", snap).ShouldContain("Value: true");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatValue_formats_floats_invariant_culture()
|
||||
{
|
||||
// Guards against non-invariant decimal separators (e.g. comma on PL locales)
|
||||
// that would break cross-platform log diffs.
|
||||
var snap = new DataValueSnapshot(3.14f, 0u, FixedTime, FixedTime);
|
||||
SnapshotFormatter.Format("F8:0", snap).ShouldContain("3.14");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatValue_quotes_strings()
|
||||
{
|
||||
var snap = new DataValueSnapshot("hello", 0u, FixedTime, FixedTime);
|
||||
SnapshotFormatter.Format("Msg", snap).ShouldContain("\"hello\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatWrite_shows_status_with_tag_name()
|
||||
{
|
||||
var result = new WriteResult(0u);
|
||||
SnapshotFormatter.FormatWrite("Scratch", result)
|
||||
.ShouldBe("Write Scratch: 0x00000000 (Good)");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatTable_aligns_columns_and_includes_header_separator()
|
||||
{
|
||||
var names = new[] { "A", "LongerTag" };
|
||||
var snaps = new[]
|
||||
{
|
||||
new DataValueSnapshot(1, 0u, FixedTime, FixedTime),
|
||||
new DataValueSnapshot(2, 0u, FixedTime, FixedTime),
|
||||
};
|
||||
var table = SnapshotFormatter.FormatTable(names, snaps);
|
||||
|
||||
table.ShouldContain("TAG");
|
||||
table.ShouldContain("VALUE");
|
||||
table.ShouldContain("STATUS");
|
||||
table.ShouldContain("SOURCE TIME");
|
||||
table.ShouldContain("---"); // separator row
|
||||
table.ShouldContain("LongerTag");
|
||||
table.ShouldContain("0x00000000");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatTable_rejects_mismatched_lengths()
|
||||
{
|
||||
Should.Throw<ArgumentException>(() => SnapshotFormatter.FormatTable(
|
||||
new[] { "A", "B" },
|
||||
new[] { new DataValueSnapshot(1, 0u, FixedTime, FixedTime) }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatTimestamp_normalises_local_kind_to_utc()
|
||||
{
|
||||
// Unspecified / Local times must land on UTC in the output — otherwise a CI box in
|
||||
// UTC+X would emit diffs against dev-laptop runs.
|
||||
var local = new DateTime(2026, 4, 21, 8, 0, 0, DateTimeKind.Local);
|
||||
var formatted = SnapshotFormatter.FormatTimestamp(local);
|
||||
formatted.ShouldEndWith("Z");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.Cli.Common.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.Cli.Common\ZB.MOM.WW.OtOpcUa.Driver.Cli.Common.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Tests;
|
||||
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class ReadCommandTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(ModbusRegion.HoldingRegisters, 100, ModbusDataType.UInt16, "HR[100]:UInt16")]
|
||||
[InlineData(ModbusRegion.Coils, 0, ModbusDataType.Bool, "Coil[0]:Bool")]
|
||||
[InlineData(ModbusRegion.DiscreteInputs, 42, ModbusDataType.Bool, "DI[42]:Bool")]
|
||||
[InlineData(ModbusRegion.InputRegisters, 5, ModbusDataType.Int16, "IR[5]:Int16")]
|
||||
[InlineData(ModbusRegion.HoldingRegisters, 200, ModbusDataType.Float32, "HR[200]:Float32")]
|
||||
public void SynthesiseTagName_produces_stable_region_prefix_plus_address_plus_type(
|
||||
ModbusRegion region, ushort address, ModbusDataType type, string expected)
|
||||
{
|
||||
ReadCommand.SynthesiseTagName(region, address, type).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Covers the <c>--value</c> string → CLR type parser inside
|
||||
/// <see cref="WriteCommand.ParseValue"/>. This is the piece that guards against
|
||||
/// locale surprises (e.g. comma-as-decimal-separator on PL locales), so all numeric
|
||||
/// paths assert the invariant-culture path.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class WriteCommandParseValueTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("false", false)]
|
||||
[InlineData("1", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("YES", true)]
|
||||
[InlineData("No", false)]
|
||||
[InlineData("on", true)]
|
||||
[InlineData("off", false)]
|
||||
public void ParseValue_Bool_accepts_common_aliases(string raw, bool expected)
|
||||
{
|
||||
WriteCommand.ParseValue(raw, ModbusDataType.Bool).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Bool_rejects_unknown_strings()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("maybe", ModbusDataType.Bool));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int16_parses_positive_and_negative()
|
||||
{
|
||||
WriteCommand.ParseValue("-32768", ModbusDataType.Int16).ShouldBe((short)-32768);
|
||||
WriteCommand.ParseValue("32767", ModbusDataType.Int16).ShouldBe((short)32767);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UInt16_and_Bcd16_both_yield_ushort()
|
||||
{
|
||||
WriteCommand.ParseValue("65535", ModbusDataType.UInt16).ShouldBeOfType<ushort>();
|
||||
WriteCommand.ParseValue("65535", ModbusDataType.Bcd16).ShouldBeOfType<ushort>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Float32_uses_invariant_culture_period_as_decimal_separator()
|
||||
{
|
||||
WriteCommand.ParseValue("3.14", ModbusDataType.Float32).ShouldBe(3.14f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Float64_handles_larger_precision()
|
||||
{
|
||||
var result = WriteCommand.ParseValue("2.718281828", ModbusDataType.Float64);
|
||||
result.ShouldBeOfType<double>();
|
||||
((double)result).ShouldBe(2.718281828d, 0.0000001d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_String_returns_raw_string_unmodified()
|
||||
{
|
||||
WriteCommand.ParseValue("hello world", ModbusDataType.String).ShouldBe("hello world");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_BitInRegister_accepts_bool_aliases()
|
||||
{
|
||||
WriteCommand.ParseValue("true", ModbusDataType.BitInRegister).ShouldBe(true);
|
||||
WriteCommand.ParseValue("0", ModbusDataType.BitInRegister).ShouldBe(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int32_parses_negative_max()
|
||||
{
|
||||
WriteCommand.ParseValue("-2147483648", ModbusDataType.Int32).ShouldBe(int.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_rejects_non_numeric_for_numeric_types()
|
||||
{
|
||||
Should.Throw<FormatException>(
|
||||
() => WriteCommand.ParseValue("not-a-number", ModbusDataType.Int32));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli\ZB.MOM.WW.OtOpcUa.Driver.Modbus.Cli.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,117 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.S7.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Cli.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Covers <see cref="WriteCommand.ParseValue"/> across every S7 atomic type.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class WriteCommandParseValueTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("yes", true)]
|
||||
[InlineData("OFF", false)]
|
||||
public void ParseValue_Bool_accepts_common_aliases(string raw, bool expected)
|
||||
{
|
||||
WriteCommand.ParseValue(raw, S7DataType.Bool).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Bool_rejects_garbage()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("maybe", S7DataType.Bool));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Byte_ranges()
|
||||
{
|
||||
WriteCommand.ParseValue("0", S7DataType.Byte).ShouldBe((byte)0);
|
||||
WriteCommand.ParseValue("255", S7DataType.Byte).ShouldBe((byte)255);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int16_signed_range()
|
||||
{
|
||||
WriteCommand.ParseValue("-32768", S7DataType.Int16).ShouldBe((short)-32768);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UInt16_unsigned_max()
|
||||
{
|
||||
WriteCommand.ParseValue("65535", S7DataType.UInt16).ShouldBe((ushort)65535);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int32_parses_negative()
|
||||
{
|
||||
WriteCommand.ParseValue("-2147483648", S7DataType.Int32).ShouldBe(int.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UInt32_parses_max()
|
||||
{
|
||||
WriteCommand.ParseValue("4294967295", S7DataType.UInt32).ShouldBe(uint.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int64_parses_min()
|
||||
{
|
||||
WriteCommand.ParseValue("-9223372036854775808", S7DataType.Int64).ShouldBe(long.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UInt64_parses_max()
|
||||
{
|
||||
WriteCommand.ParseValue("18446744073709551615", S7DataType.UInt64).ShouldBe(ulong.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Float32_invariant_culture()
|
||||
{
|
||||
WriteCommand.ParseValue("3.14", S7DataType.Float32).ShouldBe(3.14f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Float64_higher_precision()
|
||||
{
|
||||
WriteCommand.ParseValue("2.718281828", S7DataType.Float64).ShouldBeOfType<double>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_String_passthrough()
|
||||
{
|
||||
WriteCommand.ParseValue("hallo siemens", S7DataType.String).ShouldBe("hallo siemens");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_DateTime_parses_roundtrip_form()
|
||||
{
|
||||
var result = WriteCommand.ParseValue("2026-04-21T12:34:56Z", S7DataType.DateTime);
|
||||
result.ShouldBeOfType<DateTime>();
|
||||
((DateTime)result).Year.ShouldBe(2026);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_non_numeric_for_numeric_types_throws()
|
||||
{
|
||||
Should.Throw<FormatException>(
|
||||
() => WriteCommand.ParseValue("xyz", S7DataType.Int16));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("DB1.DBW0", S7DataType.Int16, "DB1.DBW0:Int16")]
|
||||
[InlineData("M0.0", S7DataType.Bool, "M0.0:Bool")]
|
||||
[InlineData("IW4", S7DataType.UInt16, "IW4:UInt16")]
|
||||
[InlineData("QD8", S7DataType.UInt32, "QD8:UInt32")]
|
||||
[InlineData("DB10.STRING[0]", S7DataType.String, "DB10.STRING[0]:String")]
|
||||
public void SynthesiseTagName_preserves_S7_address_verbatim(
|
||||
string address, S7DataType type, string expected)
|
||||
{
|
||||
ReadCommand.SynthesiseTagName(address, type).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.S7.Cli.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.S7.Cli\ZB.MOM.WW.OtOpcUa.Driver.S7.Cli.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,142 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli.Commands;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Covers <see cref="WriteCommand.ParseValue"/> for the IEC 61131-3 atomic types
|
||||
/// TwinCAT exposes. Wider matrix than AB CIP because IEC adds WSTRING + the four
|
||||
/// TIME/DATE variants that all marshal as UDINT on the wire.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class WriteCommandParseValueTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("on", true)]
|
||||
[InlineData("NO", false)]
|
||||
public void ParseValue_Bool_accepts_common_aliases(string raw, bool expected)
|
||||
{
|
||||
WriteCommand.ParseValue(raw, TwinCATDataType.Bool).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Bool_rejects_garbage()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("maybe", TwinCATDataType.Bool));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_SInt_signed_byte()
|
||||
{
|
||||
WriteCommand.ParseValue("-128", TwinCATDataType.SInt).ShouldBe((sbyte)-128);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_USInt_unsigned_byte()
|
||||
{
|
||||
WriteCommand.ParseValue("255", TwinCATDataType.USInt).ShouldBe((byte)255);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Int_signed_16bit()
|
||||
{
|
||||
WriteCommand.ParseValue("-32768", TwinCATDataType.Int).ShouldBe((short)-32768);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UInt_unsigned_16bit()
|
||||
{
|
||||
WriteCommand.ParseValue("65535", TwinCATDataType.UInt).ShouldBe((ushort)65535);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_DInt_int32_bounds()
|
||||
{
|
||||
WriteCommand.ParseValue("-2147483648", TwinCATDataType.DInt).ShouldBe(int.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_UDInt_uint32_max()
|
||||
{
|
||||
WriteCommand.ParseValue("4294967295", TwinCATDataType.UDInt).ShouldBe(uint.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_LInt_int64_min()
|
||||
{
|
||||
WriteCommand.ParseValue("-9223372036854775808", TwinCATDataType.LInt).ShouldBe(long.MinValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_ULInt_uint64_max()
|
||||
{
|
||||
WriteCommand.ParseValue("18446744073709551615", TwinCATDataType.ULInt).ShouldBe(ulong.MaxValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Real_invariant_culture()
|
||||
{
|
||||
WriteCommand.ParseValue("3.14", TwinCATDataType.Real).ShouldBe(3.14f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_LReal_higher_precision()
|
||||
{
|
||||
WriteCommand.ParseValue("2.718281828", TwinCATDataType.LReal).ShouldBeOfType<double>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_String_passthrough()
|
||||
{
|
||||
WriteCommand.ParseValue("hallo beckhoff", TwinCATDataType.String).ShouldBe("hallo beckhoff");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_WString_passthrough()
|
||||
{
|
||||
// CLI layer doesn't distinguish UTF-8 input; the driver handles the WSTRING
|
||||
// encoding on the wire.
|
||||
WriteCommand.ParseValue("überstall", TwinCATDataType.WString).ShouldBe("überstall");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TwinCATDataType.Time)]
|
||||
[InlineData(TwinCATDataType.Date)]
|
||||
[InlineData(TwinCATDataType.DateTime)]
|
||||
[InlineData(TwinCATDataType.TimeOfDay)]
|
||||
public void ParseValue_IEC_date_time_variants_land_on_uint32(TwinCATDataType type)
|
||||
{
|
||||
// IEC 61131-3 TIME / DATE / DT / TOD all marshal as UDINT on the wire; the CLI
|
||||
// accepts a numeric raw value and lets the caller handle the encoding.
|
||||
WriteCommand.ParseValue("1234567", type).ShouldBeOfType<uint>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_Structure_refused()
|
||||
{
|
||||
Should.Throw<CliFx.Exceptions.CommandException>(
|
||||
() => WriteCommand.ParseValue("42", TwinCATDataType.Structure));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseValue_non_numeric_for_numeric_types_throws()
|
||||
{
|
||||
Should.Throw<FormatException>(
|
||||
() => WriteCommand.ParseValue("xyz", TwinCATDataType.DInt));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("MAIN.bStart", TwinCATDataType.Bool, "MAIN.bStart:Bool")]
|
||||
[InlineData("GVL.Counter", TwinCATDataType.DInt, "GVL.Counter:DInt")]
|
||||
[InlineData("Motor1.Status.Running", TwinCATDataType.Bool, "Motor1.Status.Running:Bool")]
|
||||
[InlineData("Recipe[3]", TwinCATDataType.Real, "Recipe[3]:Real")]
|
||||
public void SynthesiseTagName_preserves_symbolic_path_verbatim(
|
||||
string symbol, TwinCATDataType type, string expected)
|
||||
{
|
||||
ReadCommand.SynthesiseTagName(symbol, type).ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3" Version="1.1.0"/>
|
||||
<PackageReference Include="Shouldly" Version="4.3.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Drivers\Cli\ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli\ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Cli.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user