Files
Axi_Omron/tests/AxiOmron.PcbCheck.Tests/OmronFinsPlcServiceTests.cs
yunxiao.zhu 17839a9e76 ✨ feat(*): 更新 PLC 相关配置与结果代码类型
- 修改 appConfig.json 中 PLC 和扫描仪的 IP 地址及字节序配置
- 将多个地方的 ResultCode 类型从 short 更新为 ushort,以确保与 PLC 通信一致
- 更新相关服务和模型以适应新的 ResultCode 类型
- 调整单元测试以验证新配置和类型的正确性
2026-06-02 17:59:04 +08:00

42 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}