58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System.Text.Json;
|
|
using Google.Protobuf;
|
|
using MxGateway.Client;
|
|
using MxGateway.Contracts.Proto;
|
|
|
|
namespace MxGateway.Client.Tests;
|
|
|
|
public sealed class MxStatusProxyExtensionsTests
|
|
{
|
|
[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());
|
|
int success = testCase.GetProperty("status").GetProperty("success").GetInt32();
|
|
|
|
Assert.Equal(success != 0 && 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);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|