49 lines
2.0 KiB
C#
49 lines
2.0 KiB
C#
internal static partial class Program
|
|
{
|
|
static async Task TestTransportFixturesAsync()
|
|
{
|
|
var fixtures = await LoadTransportFixturesAsync();
|
|
Assert(fixtures.Count > 0, "Transport fixtures should not be empty.");
|
|
|
|
foreach (var fixture in fixtures)
|
|
{
|
|
var entry = NewEntry();
|
|
var response = await entry.HandleCommandAsync(fixture.Request);
|
|
|
|
Assert(!response.Contains('\n') && !response.Contains('\r'), $"Fixture '{fixture.Name}' returned multiline output.");
|
|
|
|
using var doc = JsonDocument.Parse(response);
|
|
var ok = doc.RootElement.GetProperty("ok").GetBoolean();
|
|
Assert(ok == fixture.ExpectOk, $"Fixture '{fixture.Name}' expected ok={fixture.ExpectOk} but got ok={ok}.");
|
|
|
|
if (fixture.ExpectOk)
|
|
{
|
|
Assert(doc.RootElement.TryGetProperty("data", out var data), $"Fixture '{fixture.Name}' expected data field.");
|
|
if (!string.IsNullOrWhiteSpace(fixture.DataKind))
|
|
{
|
|
var expectedKind = ParseValueKind(fixture.DataKind!);
|
|
Assert(data.ValueKind == expectedKind, $"Fixture '{fixture.Name}' expected data kind {expectedKind} but got {data.ValueKind}.");
|
|
}
|
|
continue;
|
|
}
|
|
|
|
Assert(doc.RootElement.TryGetProperty("error", out var error), $"Fixture '{fixture.Name}' expected error field.");
|
|
if (!string.IsNullOrWhiteSpace(fixture.ErrorContains))
|
|
{
|
|
var message = error.GetString() ?? "";
|
|
Assert(message.Contains(fixture.ErrorContains!, StringComparison.OrdinalIgnoreCase), $"Fixture '{fixture.Name}' expected error containing '{fixture.ErrorContains}'.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
sealed class TransportFixture
|
|
{
|
|
public string Name { get; init; } = "";
|
|
public string Request { get; init; } = "";
|
|
public bool ExpectOk { get; init; }
|
|
public string? DataKind { get; init; }
|
|
public string? ErrorContains { get; init; }
|
|
}
|
|
|