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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

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

namespace XFEEDToolBox.Test;

[TestFixture]
public class LocalSelectionRecoveryTests
{
    [Test]public void TransitionReadinessCanWaitButOwnershipAndCancellationRemainTerminal()
    {
        Check.That(NavigationRecovery.CanRetry(new InvalidOperationException("Stop flight control before selecting a local destination"),CancellationToken.None));
        Check.That(!NavigationRecovery.CanRetry(new InvalidOperationException("Another controller owns local navigation"),CancellationToken.None));
        Check.That(!NavigationRecovery.CanRetry(new InvalidOperationException("Local control belongs to another controller"),CancellationToken.None));
        using var stop=new CancellationTokenSource();stop.Cancel();
        Check.That(!NavigationRecovery.CanRetry(new InvalidOperationException("Stop flight control before selecting a local destination"),stop.Token));
    }
    [Test]public void SystemTransitionCanWaitWhileUnsafeSessionAndHullRemainTerminal()
    {
        var healthy=new PlayerState{InGame=true,CurrentShipId=5,Ships=[new(){ShipId=5,HullHealth=1}],Navigation=new(){CurrentSystemAddress=1}};
        NavigationSafety.RequireLocalSelection(healthy,1);
        Check.Throws<FlightTelemetryUnavailableException>(()=>NavigationSafety.RequireLocalSelection(healthy,2));
        NavigationSafety.RequireLocalSelection(healthy with{Ships=[new(){ShipId=5,HullHealth=.49}]},1);
        foreach(var unsafeState in new[]{healthy with{InGame=false},healthy with{Ships=[new(){ShipId=5,HullHealth=0}]},healthy with{Navigation=new(){CurrentSystemAddress=1,ExternalThreat=true}}})
        {
            try{NavigationSafety.RequireLocalSelection(unsafeState,2);throw new Exception("Unsafe target selection was accepted.");}
            catch(InvalidOperationException error){Check.That(!NavigationRecovery.CanRetry(error,CancellationToken.None));}
        }
    }
}