feat(battle-node): NetworkBattleUri / EmitCategory enums and MsgEnvelope record
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
66
SVSim.UnitTests/BattleNode/Protocol/MsgEnvelopeTests.cs
Normal file
66
SVSim.UnitTests/BattleNode/Protocol/MsgEnvelopeTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Text.Json;
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.UnitTests.BattleNode.Protocol;
|
||||
|
||||
[TestFixture]
|
||||
public class MsgEnvelopeTests
|
||||
{
|
||||
[Test]
|
||||
public void Roundtrip_PreservesEnvelopeAndBody()
|
||||
{
|
||||
var env = new MsgEnvelope(
|
||||
Uri: NetworkBattleUri.InitNetwork,
|
||||
ViewerId: 906243102,
|
||||
Uuid: "udid-1234",
|
||||
Bid: "597830888107",
|
||||
Try: 0,
|
||||
Cat: EmitCategory.General,
|
||||
PubSeq: null,
|
||||
PlaySeq: null,
|
||||
Body: new Dictionary<string, object?> { ["foo"] = 42 });
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var back = MsgEnvelope.FromJson(json);
|
||||
|
||||
Assert.That(back.Uri, Is.EqualTo(NetworkBattleUri.InitNetwork));
|
||||
Assert.That(back.ViewerId, Is.EqualTo(906243102));
|
||||
Assert.That(back.Uuid, Is.EqualTo("udid-1234"));
|
||||
Assert.That(back.Bid, Is.EqualTo("597830888107"));
|
||||
Assert.That(back.Cat, Is.EqualTo(EmitCategory.General));
|
||||
Assert.That(back.Body["foo"], Is.EqualTo(42L)); // JsonElement → int64
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToJson_OmitsNullEnvelopeFields()
|
||||
{
|
||||
var env = new MsgEnvelope(
|
||||
Uri: NetworkBattleUri.Ready,
|
||||
ViewerId: 1,
|
||||
Uuid: "u",
|
||||
Bid: null,
|
||||
Try: 0,
|
||||
Cat: EmitCategory.Battle,
|
||||
PubSeq: null,
|
||||
PlaySeq: 5,
|
||||
Body: new Dictionary<string, object?>());
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
|
||||
Assert.That(json, Does.Not.Contain("\"bid\""));
|
||||
Assert.That(json, Does.Not.Contain("\"pubSeq\""));
|
||||
Assert.That(json, Does.Contain("\"playSeq\":5"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FromJson_DispatchesUriToEnum()
|
||||
{
|
||||
const string json = "{\"uri\":\"PlayActions\",\"viewerId\":1,\"uuid\":\"u\",\"try\":0,\"cat\":1}";
|
||||
|
||||
var env = MsgEnvelope.FromJson(json);
|
||||
|
||||
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.PlayActions));
|
||||
Assert.That(env.Cat, Is.EqualTo(EmitCategory.Battle));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user