using Shouldly;
using Xunit;
using ZB.MOM.WW.LmxOpcUa.Host.Domain;
namespace ZB.MOM.WW.LmxOpcUa.Tests.Domain
{
///
/// Verifies the operator-facing error messages and quality mappings derived from MXAccess error codes.
///
public class MxErrorCodesTests
{
///
/// Confirms that known MXAccess error codes produce readable operator-facing descriptions.
///
/// The MXAccess error code.
/// A substring expected in the returned description.
[Theory]
[InlineData(1008, "Invalid reference")]
[InlineData(1012, "Wrong data type")]
[InlineData(1013, "Not writable")]
[InlineData(1014, "Request timed out")]
[InlineData(1015, "Communication failure")]
[InlineData(1016, "Not connected")]
public void GetMessage_KnownCodes_ContainsDescription(int code, string expectedSubstring)
{
MxErrorCodes.GetMessage(code).ShouldContain(expectedSubstring);
}
///
/// Confirms that unknown MXAccess error codes are reported as unknown while preserving the numeric code.
///
[Fact]
public void GetMessage_UnknownCode_ReturnsUnknown()
{
MxErrorCodes.GetMessage(9999).ShouldContain("Unknown");
MxErrorCodes.GetMessage(9999).ShouldContain("9999");
}
///
/// Confirms that known MXAccess error codes map to the expected bridge quality values.
///
/// The MXAccess error code.
/// The expected bridge quality value.
[Theory]
[InlineData(1008, Quality.BadConfigError)]
[InlineData(1012, Quality.BadConfigError)]
[InlineData(1013, Quality.BadOutOfService)]
[InlineData(1014, Quality.BadCommFailure)]
[InlineData(1015, Quality.BadCommFailure)]
[InlineData(1016, Quality.BadNotConnected)]
public void MapToQuality_KnownCodes(int code, Quality expected)
{
MxErrorCodes.MapToQuality(code).ShouldBe(expected);
}
///
/// Confirms that unknown MXAccess error codes map to the generic bad quality bucket.
///
[Fact]
public void MapToQuality_UnknownCode_ReturnsBad()
{
MxErrorCodes.MapToQuality(9999).ShouldBe(Quality.Bad);
}
}
}