refactor(battle-node): switch MsgEnvelope.Body to IMsgBody, migrate all sites
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Text.Json;
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
@@ -19,7 +18,8 @@ public class MsgEnvelopeTests
|
||||
|
||||
var env = MsgEnvelope.FromJson(json);
|
||||
|
||||
var idxList = (List<object?>)env.Body["idxList"]!;
|
||||
var raw = (RawBody)env.Body;
|
||||
var idxList = (List<object?>)raw.Entries["idxList"]!;
|
||||
Assert.That(idxList.Count, Is.EqualTo(2));
|
||||
Assert.That(idxList[0], Is.TypeOf<long>(), "idxList[0] must be boxed long, not double.");
|
||||
Assert.That(idxList[0], Is.EqualTo(2L));
|
||||
@@ -39,7 +39,7 @@ public class MsgEnvelopeTests
|
||||
Cat: EmitCategory.General,
|
||||
PubSeq: null,
|
||||
PlaySeq: null,
|
||||
Body: new Dictionary<string, object?> { ["foo"] = 42 });
|
||||
Body: new RawBody(new Dictionary<string, object?> { ["foo"] = 42 }));
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var back = MsgEnvelope.FromJson(json);
|
||||
@@ -49,7 +49,7 @@ public class MsgEnvelopeTests
|
||||
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
|
||||
Assert.That(((RawBody)back.Body).Entries["foo"], Is.EqualTo(42L));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -64,7 +64,7 @@ public class MsgEnvelopeTests
|
||||
Cat: EmitCategory.Battle,
|
||||
PubSeq: null,
|
||||
PlaySeq: 5,
|
||||
Body: new Dictionary<string, object?>());
|
||||
Body: new RawBody(new Dictionary<string, object?>()));
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MsgEnvelopeTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToJson_BodyContainingReservedKey_Throws()
|
||||
public void ToJson_RawBodyContainingReservedKey_Throws()
|
||||
{
|
||||
var env = new MsgEnvelope(
|
||||
Uri: NetworkBattleUri.Loaded,
|
||||
@@ -96,7 +96,7 @@ public class MsgEnvelopeTests
|
||||
Cat: EmitCategory.Battle,
|
||||
PubSeq: null,
|
||||
PlaySeq: null,
|
||||
Body: new Dictionary<string, object?> { ["uri"] = "Injected" });
|
||||
Body: new RawBody(new Dictionary<string, object?> { ["uri"] = "Injected" }));
|
||||
|
||||
var ex = Assert.Throws<ArgumentException>(() => MsgEnvelope.ToJson(env));
|
||||
Assert.That(ex!.Message, Does.Contain("uri"));
|
||||
@@ -114,7 +114,7 @@ public class MsgEnvelopeTests
|
||||
Cat: EmitCategory.Battle,
|
||||
PubSeq: null,
|
||||
PlaySeq: null,
|
||||
Body: new Dictionary<string, object?>());
|
||||
Body: new RawBody(new Dictionary<string, object?>()));
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user