XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using XFEEDToolBox.Core.Services;
using XFEExtension.NetCore.XUnit.Attributes;

namespace XFEEDToolBox.Test;

[TestFixture]
public sealed class FlightDiagnosticPersistenceTests
{
    [Test]public async Task IdenticalAcknowledgementsDeduplicateButDifferentTargetsAndGenerationsPersist()
    {
        using var temporary=new TemporaryDirectory();
        await using(var runtime=new ToolboxRuntime(temporary.Path))
        {
            await runtime.InitializeAsync(offline:true);
            static JsonElement Ack(long target,long generation)=>JsonSerializer.SerializeToElement(new
            {
                processId=42,service="InterstellarTargetSelection",issue="acknowledged",targetSystemAddress=target,
                sample=new{state="acknowledged"},diagnostic=new{generation,selected=true}
            });
            foreach(var row in new[]{Ack(1,5),Ack(1,5),Ack(2,5),Ack(2,5),Ack(2,6),Ack(2,6)})runtime.RecordScoDiagnostic(row);
        }
        var rows=File.ReadAllLines(Path.Combine(temporary.Path,"logs","sco-diagnostics.jsonl"))
            .Select(line=>{using var document=JsonDocument.Parse(line);return document.RootElement.GetProperty("status").Clone();}).ToArray();
        Check.Equal(3,rows.Length);
        Check.Equal(1L,rows[0].GetProperty("targetSystemAddress").GetInt64());
        Check.Equal(2L,rows[1].GetProperty("targetSystemAddress").GetInt64());
        Check.Equal(6L,rows[2].GetProperty("diagnostic").GetProperty("generation").GetInt64());
    }
}