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

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Newtonsoft.Json.Linq;
using XFEWarframe.Core;
using XFEWarframe.Core.Data;
using XFEWarframe.Core.Services;
using Xunit;

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    private sealed class TestClock(DateTimeOffset initial) : TimeProvider
    {
        public DateTimeOffset Now { get; set; } = initial;
        public override DateTimeOffset GetUtcNow() => Now;
    }
    [Fact] public async Task WorldStateContainsPlayableRotationsAndPersistsRandomStock()
    {
        var time = new TestClock(new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero)); engine = new(store, options, time);
        var response = await Call("/dynamic/worldState.php"); Assert.Equal(200, response.Status); var world = JObject.Parse(response.Body);
        Assert.Equal(6, world["Invasions"]!.Count()); Assert.Single(world["Sorties"]!); Assert.Single(world["LiteSorties"]!);
        Assert.Equal(3, world["Sorties"]![0]!["Variants"]!.Count()); Assert.NotEmpty(world["VoidStorms"]!); Assert.NotEmpty(world["ActiveMissions"]!);
        Assert.Equal(12, world["SyndicateMissions"]!.Count()); Assert.NotEmpty(world["DailyDeals"]!); Assert.NotEmpty(world["PrimeVaultTraders"]![0]!["Manifest"]!);
        Assert.Equal("RadioLegionIntermission15Syndicate", world["SeasonInfo"]!.Value<string>("AffiliationTag"));
        Assert.NotEmpty(world["KnownCalendarSeasons"]![0]!["Days"]!); Assert.Single(world["EndlessXpSchedule"]!);
        await store.DisposeAsync(); store = new(root); engine = new(store, options, time);
        Assert.Equal(response.Body, (await Call("/dynamic/worldState.php")).Body);
        time.Now = time.Now.AddDays(1);
        var next = JObject.Parse((await Call("/dynamic/worldState.php")).Body);
        Assert.NotEqual(Wire.Id(world["Sorties"]![0]!["_id"]), Wire.Id(next["Sorties"]![0]!["_id"]));
        Assert.All(next["ActiveMissions"]!, x => Assert.True(Wire.DateMs(x["Expiry"]) > time.Now.ToUnixTimeMilliseconds()));
    }
    [Theory] [InlineData("19.5.3")] [InlineData("25.7.0")] [InlineData("32.0.0")] [InlineData("43.5.0")]
    public void WorldDataIsVersionGatedAndDoesNotMutateMetadata(string gameVersion)
    {
        var label = ((JObject)Assets.Json("world/gameToBuildVersion.json")).Value<string>(gameVersion)!;
        var template = WorldData.Get("worldState").DeepClone(); var time = new DateTimeOffset(2026, 9, 24, 12, 0, 0, TimeSpan.Zero).ToUnixTimeMilliseconds();
        var state = new JObject { ["worldState"] = new JObject { ["baroAlwaysAvailable"] = true } };
        var world = WorldApi.Generate(state, label, time); Assert.NotEmpty(world["VoidTraders"]![0]!["Manifest"]!);
        if (gameVersion == "19.5.3") { Assert.Empty(world["Invasions"]!); Assert.Null(world["SeasonInfo"]); Assert.NotNull(world["VoidTraders"]![0]!["_id"]!["$id"]); }
        if (gameVersion == "43.5.0") Assert.Equal("RadioLegionIntermission16Syndicate", world["SeasonInfo"]!.Value<string>("AffiliationTag"));
        Assert.True(JToken.DeepEquals(template, WorldData.Get("worldState")));
    }
    [Fact] public void SortieRolloverFollowsTorontoDaylightSavingTime()
    {
        int Day(int month, int day) => WorldData.DayOf(new DateTimeOffset(2026, month, day, 0, 0, 0, TimeSpan.Zero).ToUnixTimeMilliseconds());
        Assert.Equal(17, DateTimeOffset.FromUnixTimeMilliseconds(WorldData.SortieTime(Day(1, 20))).Hour);
        Assert.Equal(16, DateTimeOffset.FromUnixTimeMilliseconds(WorldData.SortieTime(Day(7, 20))).Hour);
    }
    [Fact] public void CalendarHasUniqueDaysAndChoicesAcrossYear()
    {
        for (var week = 88; week < 96; week++)
        {
            var season = WorldSeasons.Calendar(week); var days = (JArray)season["Days"]!;
            Assert.Equal(days.Count, days.Select(x => x.Value<int>("day")).Distinct().Count());
            var events = days.SelectMany(x => x["events"]!).ToArray();
            Assert.Equal(6, events.Count(x => x.Value<string>("type") == "CET_CHALLENGE"));
            Assert.Equal(12, events.Count(x => x.Value<string>("type") == "CET_REWARD"));
            Assert.Equal(9, events.Count(x => x.Value<string>("type") == "CET_UPGRADE"));
            Assert.Equal(9, events.Where(x => x["upgrade"] is not null).Select(x => x.Value<string>("upgrade")).Distinct().Count());
            Assert.Equal(week / 4, season.Value<int>("YearIteration"));
        }
    }
}