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

XFEWarframe

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

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

namespace XFEWarframe.Tests;

public sealed partial class EngineTests
{
    [Fact]
    public async Task LoginAndBootstrapAdvertiseTheSameIntegratedChatAddress()
    {
        options.GamePublicUrl = "https://game.example.invalid:8443";
        var response = JObject.Parse((await Call("/api/login.php", new { email = "chat@example.invalid", password = "digest" })).Body);
        Assert.Equal(new[] { "game.example.invalid" }, response["IRC"]!.Values<string>());
        var tunables = JObject.Parse((await Call("/custom/tunables.json")).Body);
        Assert.Equal("game.example.invalid", tunables.Value<string>("irc"));
        options.Irc.TlsPorts = [16697];
        response = JObject.Parse((await Call("/api/login.php", new { email = "chat@example.invalid", password = "digest", kick = true })).Body);
        Assert.Equal("game.example.invalid:16697", response["IRC"]![0]!.ToString());
        options.IrcAddresses = ["%THIS_MACHINE%:6695-6699", "chat.example.invalid"];
        response = JObject.Parse((await Call("/api/login.php", new { email = "chat@example.invalid", password = "digest", kick = true })).Body);
        Assert.Equal(new[] { "game.example.invalid:6695-6699", "chat.example.invalid" }, response["IRC"]!.Values<string>());
        options.Irc.Enabled = false; options.IrcAddresses = [];
        response = JObject.Parse((await Call("/api/login.php", new { email = "chat@example.invalid", password = "digest", kick = true })).Body);
        Assert.Empty(response["IRC"]!);
        Assert.Null(JObject.Parse((await Call("/custom/tunables.json")).Body)["irc"]);
    }

    [Fact]
    public void ExistingConfigurationAutomaticallyEnablesChatAndRejectsPortConflicts()
    {
        var old = JsonSerializer.Deserialize<ServerOptions>("{\"IrcAddresses\":[],\"PublicUrl\":\"http://127.0.0.1:8444\"}")!;
        old.Validate(); Assert.True(old.Irc.Enabled); Assert.Equal(new[] { "127.0.0.1" }, old.GetIrcAddresses());
        Assert.Equal(5, old.Irc.TlsPorts.Length);
        old.Irc.Ports = [6697]; Assert.Throws<InvalidDataException>(old.Validate);
        old.Irc.Ports = [-1]; Assert.Throws<InvalidDataException>(old.Validate);
        old.Irc.Ports = []; old.Irc.TlsPorts = []; Assert.Throws<InvalidDataException>(old.Validate);
        old.Irc.Enabled = false; old.Validate();
    }
}