feat(battle-node): BattleResult enum for BattleFinish.result wire codes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
namespace SVSim.UnitTests.BattleNode.Protocol.Bodies;
|
||||
@@ -31,9 +32,11 @@ public class SmallBodiesTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BattleFinishBody_SerializesResultAndResultCode()
|
||||
public void BattleFinishBody_SerializesResultAndResultCode_AsNumericWireValues()
|
||||
{
|
||||
var body = new BattleFinishBody(Result: 1);
|
||||
// The wire field is the int code (Win=1); BattleResult uses JsonNumberEnumConverter
|
||||
// to override the default JsonStringEnumConverter (which would emit "Win" instead).
|
||||
var body = new BattleFinishBody(Result: BattleResult.Win);
|
||||
|
||||
var node = (JsonObject)JsonSerializer.SerializeToNode(body)!;
|
||||
|
||||
@@ -41,6 +44,17 @@ public class SmallBodiesTests
|
||||
Assert.That(node["resultCode"]!.GetValue<int>(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BattleFinishBody_LoseAndConsistency_SerializeAsZeroAndTwo()
|
||||
{
|
||||
// Lock the wire values per BattleFinishResponsProcessing's switch (0=LOSE, 2=CONSISTENCY).
|
||||
var lose = (JsonObject)JsonSerializer.SerializeToNode(new BattleFinishBody(BattleResult.Lose))!;
|
||||
var consistency = (JsonObject)JsonSerializer.SerializeToNode(new BattleFinishBody(BattleResult.Consistency))!;
|
||||
|
||||
Assert.That(lose["result"]!.GetValue<int>(), Is.EqualTo(0));
|
||||
Assert.That(consistency["result"]!.GetValue<int>(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AlivePushBody_SerializesScsAndOcs_AndDoesNotIncludeResultCode()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user