- 修改 appConfig.json 中 PLC 和扫描仪的 IP 地址及字节序配置 - 将多个地方的 ResultCode 类型从 short 更新为 ushort,以确保与 PLC 通信一致 - 更新相关服务和模型以适应新的 ResultCode 类型 - 调整单元测试以验证新配置和类型的正确性
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using AxiOmron.PcbCheck.Options;
|
||
using AxiOmron.PcbCheck.Services.Implementations;
|
||
using IoTClient.Enums;
|
||
using Xunit;
|
||
|
||
namespace AxiOmron.PcbCheck.Tests;
|
||
|
||
/// <summary>
|
||
/// 验证欧姆龙 FINS PLC 服务的通信参数解析行为。
|
||
/// </summary>
|
||
public sealed class OmronFinsPlcServiceTests
|
||
{
|
||
/// <summary>
|
||
/// 默认字节序应使用 ABCD,避免 UInt16 结果代码发生高低字节交换。
|
||
/// </summary>
|
||
[Fact]
|
||
public void ResolveEndianFormat_ShouldUseAbcd_WhenConfigurationIsDefault()
|
||
{
|
||
var options = new PlcOptions();
|
||
|
||
EndianFormat result = OmronFinsPlcService.ResolveEndianFormat(options);
|
||
|
||
Assert.Equal(EndianFormat.ABCD, result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 非法字节序配置应抛出明确异常,避免使用错误端序静默读写 PLC 寄存器。
|
||
/// </summary>
|
||
[Fact]
|
||
public void ResolveEndianFormat_ShouldThrow_WhenConfigurationIsInvalid()
|
||
{
|
||
var options = new PlcOptions
|
||
{
|
||
EndianFormat = "XYZ"
|
||
};
|
||
|
||
var exception = Assert.Throws<InvalidOperationException>(() => OmronFinsPlcService.ResolveEndianFormat(options));
|
||
|
||
Assert.Contains("PLC 字节序配置无效", exception.Message);
|
||
}
|
||
}
|