d6b2f24c3f
One cross-client conformance pass; also closes first-cycle CLI-08. CLI-37: an MxStatusProxy entry is a failure iff `category != MX_STATUS_CATEGORY_OK`. The proto contract has always said so — `success` is the raw 16-bit COM member carried verbatim for diagnostics, not a boolean — but four clients branched on `success` alone and .NET required both, so the same gateway reply produced opposite verdicts per language. An absent entry stays success; a present entry with an UNSPECIFIED category is a failure, because the worker always maps a category and an unmapped one is not proven OK. CLI-38: a reply fails on HRESULT iff `hresult` is present and negative, so positive COM success codes such as S_FALSE (1) pass. .NET/Go/Java used `!= 0`, which errored on a parity-preserving S_FALSE that Python and Rust accepted. This makes the existing ClientLibrariesDesign.md claim true rather than rewriting the doc to describe the divergence. Four shared fixtures pin both rules cross-client, and each language suite also carries a table test for the two edges a fixture cannot express (absent entry, UNSPECIFIED category). A Java test fake that built a status with a bare `setSuccess(1)` and no category is fixed — under the category rule that reply was never a success.
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using System.Text.Json;
|
|
using Google.Protobuf;
|
|
using ZB.MOM.WW.MxGateway.Client;
|
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Client.Tests;
|
|
|
|
public sealed class MxStatusProxyExtensionsTests
|
|
{
|
|
/// <summary>Verifies that fixture statuses correctly project success and preserve raw integer fields.</summary>
|
|
[Fact]
|
|
public void FixtureStatuses_ProjectSuccessAndPreserveRawFields()
|
|
{
|
|
using JsonDocument document = JsonDocument.Parse(ReadFixture(
|
|
"statuses",
|
|
"status-conversion-cases.json"));
|
|
|
|
foreach (JsonElement testCase in document.RootElement.GetProperty("cases").EnumerateArray())
|
|
{
|
|
MxStatusProxy status = JsonParser.Default.Parse<MxStatusProxy>(
|
|
testCase.GetProperty("status").GetRawText());
|
|
|
|
Assert.Equal(status.Category is MxStatusCategory.Ok, status.IsSuccess());
|
|
Assert.Equal(
|
|
testCase.GetProperty("status").GetProperty("rawCategory").GetInt32(),
|
|
status.RawCategory);
|
|
Assert.Equal(
|
|
testCase.GetProperty("status").GetProperty("rawDetectedBy").GetInt32(),
|
|
status.RawDetectedBy);
|
|
}
|
|
}
|
|
|
|
/// <summary>Verifies that the raw success member never overrides the authoritative category.</summary>
|
|
[Theory]
|
|
[InlineData(MxStatusCategory.Ok, 0, true)]
|
|
[InlineData(MxStatusCategory.Ok, 1, true)]
|
|
[InlineData(MxStatusCategory.CommunicationError, 1, false)]
|
|
[InlineData(MxStatusCategory.Unspecified, 1, false)]
|
|
public void IsSuccess_BranchesOnCategoryOnly(
|
|
MxStatusCategory category,
|
|
int success,
|
|
bool expected)
|
|
{
|
|
MxStatusProxy status = new() { Category = category, Success = success };
|
|
|
|
Assert.Equal(expected, status.IsSuccess());
|
|
}
|
|
|
|
private static string ReadFixture(string category, string fileName)
|
|
{
|
|
DirectoryInfo directory = new(AppContext.BaseDirectory);
|
|
while (directory is not null)
|
|
{
|
|
string path = Path.Combine(
|
|
directory.FullName,
|
|
"clients",
|
|
"proto",
|
|
"fixtures",
|
|
"behavior",
|
|
category,
|
|
fileName);
|
|
|
|
if (File.Exists(path))
|
|
{
|
|
return File.ReadAllText(path);
|
|
}
|
|
|
|
directory = directory.Parent!;
|
|
}
|
|
|
|
throw new FileNotFoundException(fileName);
|
|
}
|
|
}
|