Pairs with BuildOpponentTurnStart. Wire shape from prod capture (turnState=0, resultCode=1). Single test locks uri, ViewerId, Cat, and body shape.
176 lines
6.4 KiB
C#
176 lines
6.4 KiB
C#
using NUnit.Framework;
|
|
using SVSim.BattleNode.Bridge;
|
|
using SVSim.BattleNode.Lifecycle;
|
|
using SVSim.BattleNode.Protocol;
|
|
using SVSim.BattleNode.Protocol.Bodies;
|
|
|
|
namespace SVSim.UnitTests.BattleNode.Lifecycle;
|
|
|
|
[TestFixture]
|
|
public class ScriptedLifecycleTests
|
|
{
|
|
[Test]
|
|
public void BuildMatched_PutsOppoIdInSelfInfoEqualToTheRealOpponentVid()
|
|
{
|
|
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(),
|
|
playerViewerId: 906243102, opponentViewerId: 847666884, battleId: "b");
|
|
|
|
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.Matched));
|
|
var body = (MatchedBody)env.Body;
|
|
Assert.That(body.SelfInfo.OppoId, Is.EqualTo(847666884L));
|
|
Assert.That(body.OppoInfo.OppoId, Is.EqualTo(906243102L));
|
|
Assert.That(env.Bid, Is.EqualTo("b"));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildMatched_ContainsThirtyCardSelfDeck()
|
|
{
|
|
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), 1, 2, "b");
|
|
var body = (MatchedBody)env.Body;
|
|
Assert.That(body.SelfDeck.Count, Is.EqualTo(30));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildMatched_deck_idxs_pair_1to30_with_context_card_ids()
|
|
{
|
|
var draftedDeck = Enumerable.Range(1, 30).Select(i => 200_000_000L + i).ToList();
|
|
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(draftedDeck), 1, 2, "b");
|
|
var body = (MatchedBody)env.Body;
|
|
|
|
for (int i = 0; i < 30; i++)
|
|
{
|
|
Assert.That(body.SelfDeck[i].Idx, Is.EqualTo(i + 1),
|
|
$"slot {i}: idx should be 1-based position");
|
|
Assert.That(body.SelfDeck[i].CardId, Is.EqualTo(200_000_000L + i + 1),
|
|
$"slot {i}: cardId should be the drafted card");
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void BuildMatched_selfInfo_cosmetics_flow_from_context()
|
|
{
|
|
var ctx = FixtureCtx() with
|
|
{
|
|
CountryCode = "JPN", UserName = "Drafter", SleeveId = "999",
|
|
EmblemId = "888", DegreeId = "777", FieldId = 42, IsOfficial = 1,
|
|
};
|
|
|
|
var env = ScriptedLifecycle.BuildMatched(ctx, 1, 2, "b");
|
|
var body = (MatchedBody)env.Body;
|
|
|
|
Assert.That(body.SelfInfo.CountryCode, Is.EqualTo("JPN"));
|
|
Assert.That(body.SelfInfo.UserName, Is.EqualTo("Drafter"));
|
|
Assert.That(body.SelfInfo.SleeveId, Is.EqualTo("999"));
|
|
Assert.That(body.SelfInfo.EmblemId, Is.EqualTo("888"));
|
|
Assert.That(body.SelfInfo.DegreeId, Is.EqualTo("777"));
|
|
Assert.That(body.SelfInfo.FieldId, Is.EqualTo(42));
|
|
Assert.That(body.SelfInfo.IsOfficial, Is.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType()
|
|
{
|
|
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), playerViewerId: 1);
|
|
var body = (BattleStartBody)env.Body;
|
|
Assert.That(body.TurnState, Is.EqualTo(0));
|
|
Assert.That(body.BattleType, Is.EqualTo(11));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildBattleStart_class_chara_cardMaster_battleType_flow_from_context()
|
|
{
|
|
var ctx = FixtureCtx() with
|
|
{
|
|
ClassId = "7", CharaId = "5000123",
|
|
CardMasterName = "card_master_test_v2",
|
|
BattleType = 42,
|
|
};
|
|
|
|
var env = ScriptedLifecycle.BuildBattleStart(ctx, playerViewerId: 1);
|
|
var body = (BattleStartBody)env.Body;
|
|
|
|
Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7"));
|
|
Assert.That(body.SelfInfo.CharaId, Is.EqualTo("5000123"));
|
|
Assert.That(body.SelfInfo.CardMasterName, Is.EqualTo("card_master_test_v2"));
|
|
Assert.That(body.BattleType, Is.EqualTo(42));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildDeal_HasThreeSelfAndThreeOppoEntries()
|
|
{
|
|
var env = ScriptedLifecycle.BuildDeal();
|
|
var body = (DealBody)env.Body;
|
|
Assert.That(body.Self.Count, Is.EqualTo(3));
|
|
Assert.That(body.Oppo.Count, Is.EqualTo(3));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_NoSwap_ReturnsInitialHand()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(Array.Empty<long>());
|
|
Assert.That(hand, Is.EqualTo(new long[] { 1, 2, 3 }));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_SwapMiddleCard_ReplacesWithFreshDeckIdx()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 2 });
|
|
Assert.That(hand, Is.EqualTo(new long[] { 1, 4, 3 }));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_SwapAll_ReplacesAllWithFreshDeckIdxs()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 1, 2, 3 });
|
|
Assert.That(hand, Is.EqualTo(new long[] { 4, 5, 6 }));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildSwapResponse_RendersGivenHandAsPositions()
|
|
{
|
|
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 });
|
|
var body = (SwapResponseBody)env.Body;
|
|
Assert.That(body.Self.Count, Is.EqualTo(3));
|
|
Assert.That(body.Self[1].Idx, Is.EqualTo(4));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildReady_IncludesIdxChangeSeedAndSpin_AndUsesGivenHand()
|
|
{
|
|
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 });
|
|
var body = (ReadyBody)env.Body;
|
|
Assert.That(body.IdxChangeSeed, Is.EqualTo(771_335_280));
|
|
Assert.That(body.Spin, Is.EqualTo(243));
|
|
Assert.That(body.Self[1].Idx, Is.EqualTo(4));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildOpponentTurnStart_HasUriTurnStartAndSpin()
|
|
{
|
|
var env = ScriptedLifecycle.BuildOpponentTurnStart();
|
|
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.TurnStart));
|
|
var body = (OpponentTurnStartBody)env.Body;
|
|
Assert.That(body.Spin, Is.EqualTo(100));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildOpponentTurnEnd_emits_TurnEnd_uri_with_turn_state_zero()
|
|
{
|
|
var env = ScriptedLifecycle.BuildOpponentTurnEnd();
|
|
|
|
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.TurnEnd));
|
|
Assert.That(env.ViewerId, Is.EqualTo(ScriptedLifecycle.FakeOpponentViewerId));
|
|
Assert.That(env.Cat, Is.EqualTo(EmitCategory.Battle));
|
|
var body = (TurnEndBody)env.Body;
|
|
Assert.That(body.TurnState, Is.EqualTo(0));
|
|
Assert.That(body.ResultCode, Is.EqualTo(1));
|
|
}
|
|
|
|
private static MatchContext FixtureCtx(IReadOnlyList<long>? deck = null) => new(
|
|
SelfDeckCardIds: deck ?? Enumerable.Range(1, 30).Select(i => 100_011_010L).ToList(),
|
|
ClassId: "1", CharaId: "1", CardMasterName: "card_master_node_10015",
|
|
CountryCode: "KOR", UserName: "Player", SleeveId: "3000011",
|
|
EmblemId: "701441011", DegreeId: "300003", FieldId: 43, IsOfficial: 0,
|
|
BattleType: 11);
|
|
}
|