using XFEEDToolBox.Core.Navigation; using XFEExtension.NetCore.XUnit.Attributes; namespace XFEEDToolBox.Test; [TestFixture] public sealed class SystemDestinationPolicyTests { private static readonly NavigationAssists Docking=new(false,true,false); private static SystemLocation Station=>new(7,(1UL<<55)|123,"Station","",12,SystemLocationCategory.Station,77,new(1000,2000,3000),5000,false,new('b',64)); private static CurrentSystemSnapshot Snapshot(SystemLocation location)=>new(123,"Fixture",81,9,DateTimeOffset.UtcNow,[location]); private static SystemNavigationCapabilities Complete=>new(new('a',64),true,true,true,true,false,false,"Fixture verified independent docking") {OriginalDockingConfigured=true,UsesNativeSupercruiseAssist=false,ApplicationFlightControlVerified=true,ApplicationFlightControlSchema=1}; private static string? Reason(SystemLocation location,SystemNavigationCapabilities? capabilities=null,NavigationAssists? assists=null) =>SystemDestinationPolicy.UnsupportedReason(Snapshot(location),location,capabilities??Complete,assists??Docking); [Test]public void StationAndCarrierRequireTheirCompleteIndependentDockingContract() { Check.That(Reason(Station) is null); Check.That(Reason(Station with{Category=SystemLocationCategory.Carrier,NativeKind=14}) is null); Check.That(Reason(Station,Complete with{OriginalDockingConfigured=false})?.Contains("独立停靠扩展")==true); Check.That(Reason(Station,Complete with{DockingRequests=false})?.Contains("停靠扩展")==true); Check.That(Reason(Station,Complete with{NativeAssists=false})?.Contains("验证")==true); Check.That(Reason(Station,assists:new(false,false,false))?.Contains("路径尚未验证")==true); } [Test]public void BasicFlightDoesNotPromiseArrivalAtStarsPlanetsAsteroidsSignalsOrPoints() { var full=Complete with{DockingPaths=true,PlanetaryApproach=true}; var orbit=new SystemNavigationTarget(123,Station.WorldAddress,"Body",SystemTargetKind.Orbit); Check.That(full.Supports(orbit,new(false,false,false)),"The lower-level research/control contract remains unchanged."); foreach(var category in new[]{SystemLocationCategory.Star,SystemLocationCategory.Planet,SystemLocationCategory.LandablePlanet,SystemLocationCategory.Asteroid, SystemLocationCategory.Settlement,SystemLocationCategory.Signal,SystemLocationCategory.PointOfInterest,SystemLocationCategory.Other,SystemLocationCategory.None,SystemLocationCategory.All}) { var location=Station with{Category=category,MarketId=null};var snapshot=Snapshot(location); Check.That(SystemDestinationPolicy.UnsupportedReason(snapshot,location,full,Docking)?.Contains("尚未验证")==true); Check.Equal(1,snapshot.Locations.Count);Check.That(snapshot.Locations[0]==location,"Unsupported destinations remain available for browsing and selection."); } } [Test]public void MissingCoordinatesIdentityOrMarketCannotAuthorizeArrival() { Check.That(Reason(Station with{Position=null})?.Contains("坐标")==true); Check.That(Reason(Station with{Position=new(double.NaN,0,0)})?.Contains("坐标")==true); Check.That(Reason(Station with{MarketId=null})?.Contains("编号")==true); Check.That(Reason(Station with{MarketId=0})?.Contains("编号")==true); foreach(var location in new[]{Station with{Identity=""},Station with{Identity=new('g',64)},Station with{Key=-1},Station with{WorldAddress=0}, Station with{WorldAddress=(1UL<<55)|124},Station with{NativeKind=0},Station with{Name=""}}) Check.That(Reason(location)?.Contains("完整身份")==true); } [Test]public void ChangedCatalogueIdentityAndMissingCurrentPoseRequireReselection() { var location=Station; Check.That(SystemDestinationPolicy.UnsupportedReason(Snapshot(location with{Identity=new('c',64)}),location,Complete,Docking)?.Contains("重新选择")==true); Check.That(SystemDestinationPolicy.UnsupportedReason(Snapshot(location with{Position=null}),location,Complete,Docking)?.Contains("坐标")==true); Check.That(Reason(location,Complete with{TelemetryReady=false,TelemetryIssue="等待驾驶舱"})=="等待驾驶舱"); Check.That(Reason(location,Complete with{CruiseControl=false})?.Contains("驾驶控制")==true); } [Test]public void AVerifiedDockingPathMayReplaceHardwareButAnUnverifiedPathCannot() { var noHardware=new NavigationAssists(false,false,false); Check.That(Reason(Station,Complete with{DockingPaths=true},noHardware) is null); Check.That(Reason(Station,Complete with{DockingPaths=false},noHardware) is not null); Check.That(Reason(Station,Complete with{DockingPaths=true,DockingRequests=false},noHardware) is not null); } }