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

XFEWarframe

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

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWarframe.Loadouts;
using Xunit;

namespace XFEWarframe.Client.Tests;

public sealed class ModLoadoutRulesTests
{
    private static ModCard Card(string key, string group, int drain = 6, string polarity = "AP_ATTACK", int[]? compatible = null) =>
        new(key, "/Lotus/Upgrades/" + key, key, "WARFRAME", group, 0, 5, drain, polarity, "RARE", "", "{\"lvl\":0}", 1, compatible ?? [0, 1]);
    private static ModLoadout Layout(params ModCard[] cards) => new(30, true, [new(0, ModSlotKind.Normal, "AP_UNIVERSAL"), new(1, ModSlotKind.Normal, "AP_UNIVERSAL")], cards);
    [Fact] public void DragInstallsSwapsAndMovesTheSameInstanceWithoutDuplicatingIt()
    {
        var layout = Layout(Card("a", "a"), Card("b", "b"));
        var original = new Dictionary<int, string> { [0] = "a", [1] = "b" };
        var swapped = ModLoadoutRules.Install(layout, original, "a", 1, 0);
        Assert.Equal("b", swapped[0]); Assert.Equal("a", swapped[1]); Assert.Equal("a", original[0]);
        var moved = ModLoadoutRules.Install(layout, swapped, "a", 0);
        Assert.Equal("a", moved[0]); Assert.Empty(moved[1]);
    }
    [Fact] public void IncompatibleSwapLeavesBothSlotsUnchanged()
    {
        var layout = Layout(Card("a", "a"), Card("b", "b", compatible: [1]));
        var original = new Dictionary<int, string> { [0] = "a", [1] = "b" };
        Assert.Throws<InvalidOperationException>(() => ModLoadoutRules.Install(layout, original, "a", 1, 0));
        Assert.Equal("a", original[0]); Assert.Equal("b", original[1]);
    }
    [Fact] public void GroupDuplicatesAndForeignInstancesCannotBeInstalled()
    {
        var layout = Layout(Card("base", "damage"), Card("prime", "damage"));
        var selection = new Dictionary<int, string> { [0] = "base", [1] = "" };
        Assert.Throws<InvalidOperationException>(() => ModLoadoutRules.Install(layout, selection, "prime", 1));
        Assert.Throws<InvalidOperationException>(() => ModLoadoutRules.Install(layout, selection, "foreign", 1));
    }
    [Fact] public void AStaleDragCannotOverwriteNewerDrafts()
    {
        var layout = Layout(Card("a", "a"), Card("b", "b"));
        var selection = new Dictionary<int, string> { [0] = "b", [1] = "" };
        Assert.Throws<InvalidOperationException>(() => ModLoadoutRules.Install(layout, selection, "a", 1, 0));
        Assert.Equal("b", selection[0]);
    }
    [Fact] public void LockedSlotsRejectNewCardsButAllowUninstallingImportedCards()
    {
        var layout = Layout(Card("a", "a")) with { Slots = [new(0, ModSlotKind.Normal, "AP_UNIVERSAL", true)] };
        Assert.NotNull(ModLoadoutRules.Validate(layout, new Dictionary<int,string> { [0] = "a" }));
        Assert.Null(ModLoadoutRules.Validate(layout, new Dictionary<int,string> { [0] = "" }, new Dictionary<int,string> { [0] = "a" }));
    }
    [Fact] public void PolaritiesAuraAndArcanesContributeToCapacity()
    {
        var layout = new ModLoadout(30, true, [new(0, ModSlotKind.Normal, "AP_ANY"), new(8, ModSlotKind.Aura, "AP_ATTACK"), new(10, ModSlotKind.Arcane, "")],
            [Card("normal", "normal", 7, compatible:[0]), Card("aura", "aura", -7, compatible:[8]), Card("arcane", "arcane", 99, compatible:[10])]);
        var capacity = ModLoadoutRules.Capacity(layout, new Dictionary<int,string> { [0] = "normal", [8] = "aura", [10] = "arcane" });
        Assert.Equal(44, capacity.Maximum); Assert.Equal(4, capacity.Used); Assert.Equal(40, capacity.Remaining);
    }
    [Fact] public void KnownCapacityRejectsOverflowButAnUnknownEstimateDoesNotRejectNativeCompatibleSaves()
    {
        var layout = Layout(Card("a", "a", 40)); var selection = new Dictionary<int,string> { [0] = "a", [1] = "" };
        Assert.NotNull(ModLoadoutRules.Validate(layout, selection));
        Assert.Null(ModLoadoutRules.Validate(layout with { CapacityKnown = false }, selection));
    }
    [Fact] public void UnrecognizedImportedCardsArePreservedButCannotBeIntroducedElsewhere()
    {
        var layout = Layout(Card("a", "a")); var original = new Dictionary<int,string> { [0] = "legacy", [1] = "" };
        Assert.Null(ModLoadoutRules.Validate(layout, original, original));
        Assert.NotNull(ModLoadoutRules.Validate(layout, new Dictionary<int,string> { [0] = "", [1] = "legacy" }, original));
    }
}