test(worker): pin the MxStatusDetailText table (mxaccessgw#178)
The detail-code-to-text table had no direct tests; only three codes were covered incidentally through MxStatusProxyConverterTests. The new MxStatusDetailTextTests pins every known code's text, checks codes outside the table (including the gaps inside it and the int extremes) map to empty, sweeps -16..20000 to assert the table holds exactly the pinned codes, and checks every text is non-blank, trimmed and distinct. (mxaccessgw#178) Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -0,0 +1,133 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using ZB.MOM.WW.MxGateway.Worker.Conversion;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.MxGateway.Worker.Tests.Conversion;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pins the <see cref="MxStatusDetailText"/> table: the text each known MXAccess
|
||||||
|
/// <c>MXSTATUS_PROXY.detail</c> code maps to, and that every other code maps to the empty
|
||||||
|
/// string. The text reaches clients as <c>MxStatusProxy.DiagnosticText</c>, so an accidental
|
||||||
|
/// edit, a dropped row or a duplicate code is a visible wire change (mxaccessgw#178).
|
||||||
|
/// </summary>
|
||||||
|
public sealed class MxStatusDetailTextTests
|
||||||
|
{
|
||||||
|
/// <summary>Every known detail code with its expected text.</summary>
|
||||||
|
public static TheoryData<int, string> KnownDetails => new()
|
||||||
|
{
|
||||||
|
{ 16, "Request timed out" },
|
||||||
|
{ 17, "Platform communication error" },
|
||||||
|
{ 18, "Invalid platform ID" },
|
||||||
|
{ 19, "Invalid engine ID" },
|
||||||
|
{ 20, "Engine communication error" },
|
||||||
|
{ 21, "Invalid reference" },
|
||||||
|
{ 22, "No Galaxy Repository" },
|
||||||
|
{ 23, "Invalid object ID" },
|
||||||
|
{ 24, "Object signature mismatch" },
|
||||||
|
{ 25, "Invalid primitive ID" },
|
||||||
|
{ 26, "Invalid attribute ID" },
|
||||||
|
{ 27, "Invalid property ID" },
|
||||||
|
{ 28, "Index out of range" },
|
||||||
|
{ 29, "Data out of range" },
|
||||||
|
{ 30, "Incorrect data type" },
|
||||||
|
{ 31, "Attribute not readable" },
|
||||||
|
{ 32, "Attribute not writeable" },
|
||||||
|
{ 33, "Write access denied" },
|
||||||
|
{ 34, "Unknown error" },
|
||||||
|
{ 36, "Wrong data type" },
|
||||||
|
{ 37, "Wrong number of dimensions" },
|
||||||
|
{ 38, "Invalid index" },
|
||||||
|
{ 39, "Index out of order" },
|
||||||
|
{ 40, "Dimension does not exist" },
|
||||||
|
{ 41, "Conversion not supported" },
|
||||||
|
{ 42, "Unable to convert string" },
|
||||||
|
{ 43, "Overflow" },
|
||||||
|
{ 44, "Attribute signature mismatch" },
|
||||||
|
{ 47, "Nmx version mismatch" },
|
||||||
|
{ 48, "Nmx command not valid" },
|
||||||
|
{ 49, "Lmx version mismatch" },
|
||||||
|
{ 50, "Lmx command not valid" },
|
||||||
|
{ 56, "Secured Write" },
|
||||||
|
{ 57, "Verified Write" },
|
||||||
|
{ 60, "User did not have the necessary permissions to write" },
|
||||||
|
{ 61, "Verifier did not have the necessary permissions to verify" },
|
||||||
|
{ 541, "Conversion to intended data type is not supported" },
|
||||||
|
{ 542, "Unable to convert the input string to intended data type" },
|
||||||
|
{ 8017, "Object must be offscan to modify attributes that have an MxSecurityConfigure security classification" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Upper bound of the exhaustive sweep. It covers every code in the table (the largest is
|
||||||
|
// 8017) with headroom, so a row added anywhere in that range fails the set-equality test
|
||||||
|
// until it is added to KnownDetails as well.
|
||||||
|
private const int SweepUpperBound = 20_000;
|
||||||
|
|
||||||
|
/// <summary>Verifies each known code maps to its documented text.</summary>
|
||||||
|
/// <param name="detail">MXAccess status detail code.</param>
|
||||||
|
/// <param name="expected">Expected description.</param>
|
||||||
|
[Theory]
|
||||||
|
[MemberData(nameof(KnownDetails))]
|
||||||
|
public void Lookup_WithKnownDetail_ReturnsText(int detail, string expected)
|
||||||
|
{
|
||||||
|
Assert.Equal(expected, MxStatusDetailText.Lookup(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies codes outside the table, including the gaps inside it, map to empty.</summary>
|
||||||
|
/// <param name="detail">MXAccess status detail code with no entry.</param>
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(15)]
|
||||||
|
[InlineData(35)]
|
||||||
|
[InlineData(45)]
|
||||||
|
[InlineData(46)]
|
||||||
|
[InlineData(51)]
|
||||||
|
[InlineData(55)]
|
||||||
|
[InlineData(58)]
|
||||||
|
[InlineData(59)]
|
||||||
|
[InlineData(62)]
|
||||||
|
[InlineData(540)]
|
||||||
|
[InlineData(543)]
|
||||||
|
[InlineData(8016)]
|
||||||
|
[InlineData(8018)]
|
||||||
|
[InlineData(-1)]
|
||||||
|
[InlineData(int.MinValue)]
|
||||||
|
[InlineData(int.MaxValue)]
|
||||||
|
public void Lookup_WithUnknownDetail_ReturnsEmpty(int detail)
|
||||||
|
{
|
||||||
|
Assert.Equal(string.Empty, MxStatusDetailText.Lookup(detail));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verifies the table holds exactly the pinned codes: sweeping the code range finds no
|
||||||
|
/// entry missing from <see cref="KnownDetails"/> and none extra.
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void Lookup_AcrossCodeRange_ResolvesExactlyThePinnedCodes()
|
||||||
|
{
|
||||||
|
HashSet<int> pinned = new(KnownDetails.Select(row => (int)row[0]));
|
||||||
|
List<int> resolved = new();
|
||||||
|
for (int detail = -16; detail <= SweepUpperBound; detail++)
|
||||||
|
{
|
||||||
|
if (MxStatusDetailText.Lookup(detail).Length > 0)
|
||||||
|
{
|
||||||
|
resolved.Add(detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(pinned.OrderBy(code => code), resolved);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verifies no entry is blank or padded, and no two codes share a text.</summary>
|
||||||
|
[Fact]
|
||||||
|
public void KnownDetails_HaveDistinctTrimmedNonEmptyText()
|
||||||
|
{
|
||||||
|
List<string> texts = KnownDetails.Select(row => MxStatusDetailText.Lookup((int)row[0])).ToList();
|
||||||
|
|
||||||
|
Assert.All(texts, text =>
|
||||||
|
{
|
||||||
|
Assert.False(string.IsNullOrWhiteSpace(text));
|
||||||
|
Assert.Equal(text.Trim(), text);
|
||||||
|
});
|
||||||
|
Assert.Equal(texts.Count, texts.Distinct().Count());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user