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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEEDToolBox.Core.Navigation;
using XFEExtension.NetCore.XUnit.Attributes;

namespace XFEEDToolBox.Test;
[TestFixture]
public sealed class FlightJourneyFailureTests
{
    [Test]public async Task ATransientFailureRequiresAPositiveOriginalSceneWitness()
    {
        var error=new InvalidOperationException("Local telemetry recovery exhausted",new FlightTelemetryUnavailableException("stale"));var reads=0;
        foreach(var saving in new[]{false,true})
        {
            var result=await FlightJourneyFailure.ClassifyAsync(error,_=>{reads++;return Task.FromResult(saving);},default);
            Check.Equal(saving,SavingSceneRecoveryRequiredException.Present(result));
            Check.That(saving?ReferenceEquals(result.InnerException,error):ReferenceEquals(result,error));
        }
        Check.Equal(2,reads);
    }
    [Test]public async Task RealIdentityHealthAndOwnershipFailuresNeverProbeForAutomaticRestart()
    {
        foreach(var error in new Exception[]{new InvalidDataException("Ship identity differs"),new FlightHealthPauseException(),new FlightThreatPauseException(),
            new InvalidOperationException("Another controller owns local navigation"),new DockingHandoffException("Actual handoff failure",1),
            new AggregateException(new IOException("transport"),new InvalidDataException("wrong ship")),
            new FlightTelemetryUnavailableException("wrapped protocol error",new InvalidDataException("wrong ship")),
            new FlightDestinationChangedException("old station","new target",new FlightTelemetryUnavailableException("stale"))})
        {
            var result=await FlightJourneyFailure.ClassifyAsync(error,_=>throw new InvalidOperationException("Unexpected restart probe"),default);
            Check.That(ReferenceEquals(error,result));
        }
    }
    [Test]public async Task CancellationCannotBeReinterpretedAsARecoverableScene()
    {
        using var stop=new CancellationTokenSource();stop.Cancel();var cancelled=false;
        try{await FlightJourneyFailure.ClassifyAsync(new IOException("lost frame"),_=>throw new InvalidOperationException("Unexpected restart probe"),stop.Token);}
        catch(OperationCanceledException){cancelled=true;}
        Check.That(cancelled);
    }
    [Test]public void SavingSceneProofNeverDiscardsConcurrentProtectedCancelledOrUnknownCleanupCauses()
    {
        var saved=new SavingSceneRecoveryRequiredException(new FlightTelemetryUnavailableException("original save transition"));
        Check.That(FlightJourneyFailure.CanRecoverScene(saved));
        Check.That(FlightJourneyFailure.CanRecoverScene(new AggregateException(saved,new IOException("transport cleanup"))));
        foreach(var blocked in new Exception[]{new InvalidDataException("identity changed"),new FlightHealthPauseException(),new FlightThreatPauseException(),
            new OperationCanceledException("user Stop"),new IOException("wrapped cancel",new OperationCanceledException("user Stop")),
            new InvalidOperationException("Another controller owns navigation")})
            Check.That(!FlightJourneyFailure.CanRecoverScene(new AggregateException(saved,blocked)));
    }
}