using System.Text.Json; using XFEEDToolBox.Core.Galaxy; using XFEEDToolBox.Core.Navigation; using XFEEDToolBox.Core.Planning; using XFEEDToolBox.Core.Models; using XFEExtension.NetCore.XUnit.Attributes; namespace XFEEDToolBox.Test; [TestFixture] public sealed class SystemMapCatalogueTests { private static readonly GalacticSystem System=new("Atlas",new(1,2,3),123); private const string Bodies="""{"name":"Atlas","id64":123,"bodies":[{"id":5,"bodyId":1,"name":"Atlas A","type":"Star","subType":"K star","distanceToArrival":0},{"id":6,"name":"Atlas A 1","type":"Planet","isLandable":true,"distanceToArrival":100}]}"""; private const string Stations="""{"name":"Atlas","id64":123,"stations":[{"marketId":100,"name":"Port","type":"Coriolis Starport","distanceToArrival":100},{"marketId":200,"name":"Surface","type":"Odyssey Settlement","body":{"name":"Atlas A 1"},"distanceToArrival":101},{"marketId":300,"name":"Unknown","type":"New Station Type"}]}"""; [Test]public void PublicDiagramPreservesStationIdentityWithoutInventingNativeNavigationOrbits() { using var bodies=JsonDocument.Parse(Bodies);using var stations=JsonDocument.Parse(Stations); var atlas=SystemMapCatalogueClient.Parse(System,bodies.RootElement,stations.RootElement); Check.That(atlas.Preview.DisplayOnly);Check.Equal(5,atlas.Preview.Locations.Count);Check.Equal(3,atlas.Stations.Count); Check.Equal(0,atlas.Preview.Orbits.Count);Check.That(atlas.Preview.Locations.All(row=>row.WorldAddress==0)); var port=atlas.Stations.Values.Single(row=>row.MarketId==100); Check.Equal("Atlas",port.SystemName);Check.Equal("Port",port.Name);Check.Equal(LandingPad.Large,port.MaxLandingPad); Check.That(atlas.Stations.Values.Single(row=>row.MarketId==200).IsPlanetary); Check.Equal(LandingPad.Unknown,atlas.Stations.Values.Single(row=>row.MarketId==300).MaxLandingPad); var rejected=false;try{ShipPadPolicy.RequireFits(atlas.Stations.Values.Single(row=>row.MarketId==300),"anaconda");}catch(InvalidOperationException){rejected=true;} Check.That(rejected); } [Test]public void AForeignSystemOrConflictingMarketCannotSupplyAJourneyDestination() { using var bodies=JsonDocument.Parse(Bodies); foreach(var response in new[]{Stations.Replace("\"id64\":123","\"id64\":124"),Stations.Replace("\"Atlas\"","\"Foreign\""),Stations.Replace("\"marketId\":200","\"marketId\":100")}) { using var stations=JsonDocument.Parse(response);var rejected=false; try{SystemMapCatalogueClient.Parse(System,bodies.RootElement,stations.RootElement);}catch(InvalidDataException){rejected=true;} Check.That(rejected); } } }