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

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text;using System.Text.Json;
using XFEExtension.NetCore.XUnit.Attributes;
using XFEEDToolBox.Core.Execution;using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox.Test;
[TestFixture]public sealed class CommunityGoalRouteMatchTests
{
    private static string Hex(string value)=>Convert.ToHexStringLower(Encoding.UTF8.GetBytes(value));
    private static string Body(string sentence)=>JsonSerializer.Serialize(new{initiatives=new Dictionary<string,object>{["864"]=new{id=864,activityType="tradelist",goalType="trade",market_id=42,expiry=2000000000,complete=false,final_state="active",hidden="0",
        bulletin=new{title=Hex("Trade initiative"),body=Hex(sentence)},systemName=Hex("AD Leonis"),marketName=Hex("Homer Platform"),dynamic=new{complete=false,commanderSubscribed=false,commanderContributionQty=(long?)null}}}});
    [Test]public void OnlyTheVerifiedDestinationSentenceSuppliesAcceptedCommodityEvidence()
    {
        var valid="Pilots can support this initiative by delivering Polymers, Coffee, Uranium and Liquid Oxygen to Homer Platform in the AD Leonis system.";
        var goal=CommunityGoalCatalogue.Parse(Body(valid)).Single();Check.Equal("polymers,coffee,uranium,liquidoxygen",string.Join(',',goal.AcceptedCommodities));
        Check.Equal(0,CommunityGoalCatalogue.Parse(Body(valid.Replace("Homer Platform","Other station"))).Single().AcceptedCommodities.Count);
        Check.Equal(0,CommunityGoalCatalogue.Parse(Body("Accepts many commodities; details unavailable.")).Single().AcceptedCommodities.Count);
    }
    [Test]public void BadgeRequiresActiveGoalExactStationAndPositiveAcceptedCargo()
    {
        var now=DateTimeOffset.FromUnixTimeSeconds(1900000000);var goal=new CommunityGoalInfo(864,"Trade","tradelist","trade",42,"AD Leonis","Homer Platform",now.AddDays(1),true,false,null){AcceptedCommodities=["uranium"]};
        var leg=new TradeLeg{From=Check.Station(1),To=Check.Station(42) with{SystemName="AD Leonis",Name="Homer Platform"},Orders=[new("uranium","Uranium",10,100,200)]};var plan=new RoutePlan{Legs=[leg]};
        Check.Equal(1,CommunityGoalCatalogue.MatchRoute([goal],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal with{Expires=now}],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal with{AcceptedCommodities=[]}],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal with{MarketId=99}],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal with{Activity="combat"}],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal with{Active=false}],plan,now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal],plan with{Legs=[leg with{Orders=[new("uranium","Uranium",0,100,200)]}]},now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal],plan with{Legs=[leg with{Orders=[new("gold","Gold",10,100,200)]}]},now).Count);
        Check.Equal(0,CommunityGoalCatalogue.MatchRoute([goal],plan with{Legs=[leg with{To=leg.To with{Name="Other station"}}]},now).Count);
        var profit=plan.NetProfit;var rate=plan.CreditsPerHour;_ =CommunityGoalCatalogue.MatchRoute([goal],plan,now);Check.Equal(profit,plan.NetProfit);Check.Equal(rate,plan.CreditsPerHour);
    }
}