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(()=>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));} } } }