Lifts the WS read loop, SIO encode/decode, per-WS OutboundSequencer + InboundTracker, and SIO ack out of BattleSession into a participant. PushAsync(noStock=false) assigns playSeq via the sequencer; noStock=true bypasses it. FrameEmitted fires on each deduplicated inbound envelope. The existing BattleSession keeps its own copy of the WS code for now; Task 9 cuts the handler over to use BattleSessionV2 + RealParticipant and Task 10 deletes the old BattleSession + duplicate code.
70 lines
2.6 KiB
C#
70 lines
2.6 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NUnit.Framework;
|
|
using SVSim.BattleNode.Bridge;
|
|
using SVSim.BattleNode.Protocol;
|
|
using SVSim.BattleNode.Protocol.Bodies;
|
|
using SVSim.BattleNode.Sessions;
|
|
using SVSim.BattleNode.Sessions.Participants;
|
|
using SVSim.UnitTests.BattleNode.Infrastructure;
|
|
|
|
namespace SVSim.UnitTests.BattleNode.Sessions.Participants;
|
|
|
|
[TestFixture]
|
|
public class RealParticipantTests
|
|
{
|
|
[Test]
|
|
public void PushAsync_ordered_assigns_playSeq_via_OutboundSequencer()
|
|
{
|
|
var ws = new TestWebSocket();
|
|
var p = new RealParticipant(ws, viewerId: 1, FixtureCtx(),
|
|
NullLogger<RealParticipant>.Instance);
|
|
|
|
// First ordered push gets playSeq = 1; second = 2; etc.
|
|
// Inspect the participant's outbound sequencer state via its public Archive.
|
|
var env = NewEnvelope(NetworkBattleUri.Matched);
|
|
p.PushAsync(env, noStock: false, CancellationToken.None).Wait();
|
|
p.PushAsync(env, noStock: false, CancellationToken.None).Wait();
|
|
|
|
Assert.That(p.Outbound.Archive.Count, Is.EqualTo(2));
|
|
Assert.That(p.Outbound.Archive[1].PlaySeq, Is.EqualTo(1));
|
|
Assert.That(p.Outbound.Archive[2].PlaySeq, Is.EqualTo(2));
|
|
}
|
|
|
|
[Test]
|
|
public void PushAsync_noStock_omits_playSeq()
|
|
{
|
|
var ws = new TestWebSocket();
|
|
var p = new RealParticipant(ws, viewerId: 1, FixtureCtx(),
|
|
NullLogger<RealParticipant>.Instance);
|
|
|
|
p.PushAsync(NewEnvelope(NetworkBattleUri.BattleFinish), noStock: true, CancellationToken.None).Wait();
|
|
|
|
// No playSeq archive entry for no-stock pushes.
|
|
Assert.That(p.Outbound.Archive.Count, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void ViewerId_and_Context_are_exposed()
|
|
{
|
|
var ws = new TestWebSocket();
|
|
var ctx = FixtureCtx();
|
|
var p = new RealParticipant(ws, viewerId: 906243102L, ctx,
|
|
NullLogger<RealParticipant>.Instance);
|
|
|
|
Assert.That(p.ViewerId, Is.EqualTo(906243102L));
|
|
Assert.That(p.Context, Is.SameAs(ctx));
|
|
}
|
|
|
|
private static MatchContext FixtureCtx() => new(
|
|
SelfDeckCardIds: Enumerable.Range(1, 30).Select(_ => 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);
|
|
|
|
private static MsgEnvelope NewEnvelope(NetworkBattleUri uri) =>
|
|
new(uri, ViewerId: 1, Uuid: "u", Bid: null, Try: 0,
|
|
Cat: EmitCategory.Battle, PubSeq: null, PlaySeq: null,
|
|
Body: new ResultCodeOnlyBody());
|
|
}
|