using XFEEDToolBox.Core.Galaxy; using XFEExtension.NetCore.XUnit.Attributes; namespace XFEEDToolBox.Test; [TestFixture] public class GalaxyHistoricalTradeTests { private static readonly DateTimeOffset RecordedAt=DateTimeOffset.Parse("2026-10-20T02:03:04Z"); private static OriginalTradeDataSnapshot Cache(ulong commander,long system,DateTimeOffset time,params OriginalTradeRoute[] routes)=>new(commander,system,time,routes,""); [Test] public void PlayerAndNpcFlowsUseActualAmountsDirectionCommodityAndTheirOriginalCacheTime() { var snapshots=new[]{Cache(42,1,RecordedAt,new OriginalTradeRoute(1,2,"Gold",7,0),new(2,1,"Silver",0,3),new(1,3,"Tobacco",1,2)),Cache(99,1,RecordedAt,new OriginalTradeRoute(1,2,"Wrong account",100,100))}; var all=GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.All,null);Check.Equal(3,all.Count);Check.That(all.All(e=>e.CachedAt==RecordedAt)); var players=GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.Players,null);Check.Equal(2,players.Count);Check.That(!players.Any(e=>e.Commodity=="Gold")); var npcs=GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.Npc,new HashSet{"gold"});Check.Equal(1,npcs.Count);Check.Equal(1L,npcs[0].FromSystemAddress);Check.Equal(2L,npcs[0].ToSystemAddress);Check.Equal(7d,npcs[0].Amount(GalaxyTradeFlowSource.All)); Check.Equal(0,GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.All,new HashSet()).Count);Check.Equal(0,GalaxyHistoricalTrade.Select(snapshots,0,GalaxyTradeFlowSource.All,null).Count); } [Test] public void NewerEndpointCacheSupersedesAnOlderPositiveFlowEvenWhenItNowReportsZero() { var snapshots=new[]{Cache(42,1,RecordedAt,new OriginalTradeRoute(1,2,"Gold",7,4)),Cache(42,2,RecordedAt.AddDays(1),new OriginalTradeRoute(1,2,"gold",9,0))}; Check.Equal(0,GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.Players,null).Count); var npcs=GalaxyHistoricalTrade.Select(snapshots,42,GalaxyTradeFlowSource.Npc,null);Check.Equal(1,npcs.Count);Check.Equal(9d,npcs[0].NpcAmount);Check.Equal(2L,npcs[0].CacheSystemAddress);Check.Equal(RecordedAt.AddDays(1),npcs[0].CachedAt); } [Test] public void ALineRequiresBothExactAddressesAndMeasuredCoordinatesWithoutSubstitutingANearbySystem() { const long large=9007199254740993; var edges=GalaxyHistoricalTrade.Select([Cache(42,large,RecordedAt,new OriginalTradeRoute(large,2,"Gold",1,2))],42,GalaxyTradeFlowSource.All,null); var from=new GalacticSystem("Actual from",new(1,2,3)){SystemAddress=large};var to=new GalacticSystem("Actual to",new(4,5,6)){SystemAddress=2}; var known=new Dictionary{{large,from},{2,to with{SystemAddress=3}}};var projection=GalaxyHistoricalTrade.Project(edges,known); Check.Equal(0,projection.Flows.Count);Check.That(projection.MissingSystemAddresses.SequenceEqual(new[]{2L})); known[2]=to;projection=GalaxyHistoricalTrade.Project(edges,known);Check.Equal(1,projection.Flows.Count);Check.Equal(large,projection.Flows[0].From.SystemAddress);Check.Equal(to.Position,projection.Flows[0].To.Position);Check.Equal(RecordedAt,projection.OldestCache);Check.Equal(0,projection.MissingSystemAddresses.Count); known[2]=to with{Position=new(double.NaN,0,0)};Check.Equal(0,GalaxyHistoricalTrade.Project(edges,known).Flows.Count); } [Test] public void HistoricalDisplayControlsNeverActivateOrAlterTheStellarQueryPredicate() { var initial=GalaxyMapFilter.Default;var changed=initial with{ShowHistoricalTradeFlows=true,HistoricalTradeSource=GalaxyTradeFlowSource.Npc,HistoricalTradeCommodities=new HashSet{"gold"}}; Check.That(!changed.IsQueryActive&&changed.Mode==GalaxyMapMode.Realistic);Check.Equal(initial.QueryKey,changed.QueryKey); } }