feat(battle-node): typed OpponentTurnStart/ResultCodeOnly/BattleFinish/AlivePush bodies
This commit is contained in:
7
SVSim.BattleNode/Protocol/Bodies/AlivePushBody.cs
Normal file
7
SVSim.BattleNode/Protocol/Bodies/AlivePushBody.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
public sealed record AlivePushBody(
|
||||
[property: JsonPropertyName("scs")] string Scs,
|
||||
[property: JsonPropertyName("ocs")] string Ocs) : IMsgBody;
|
||||
7
SVSim.BattleNode/Protocol/Bodies/BattleFinishBody.cs
Normal file
7
SVSim.BattleNode/Protocol/Bodies/BattleFinishBody.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
public sealed record BattleFinishBody(
|
||||
[property: JsonPropertyName("result")] int Result,
|
||||
[property: JsonPropertyName("resultCode")] int ResultCode = 1) : IMsgBody;
|
||||
@@ -0,0 +1,7 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
public sealed record OpponentTurnStartBody(
|
||||
[property: JsonPropertyName("spin")] int Spin,
|
||||
[property: JsonPropertyName("resultCode")] int ResultCode = 1) : IMsgBody;
|
||||
6
SVSim.BattleNode/Protocol/Bodies/ResultCodeOnlyBody.cs
Normal file
6
SVSim.BattleNode/Protocol/Bodies/ResultCodeOnlyBody.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
public sealed record ResultCodeOnlyBody(
|
||||
[property: JsonPropertyName("resultCode")] int ResultCode = 1) : IMsgBody;
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
namespace SVSim.UnitTests.BattleNode.Protocol.Bodies;
|
||||
|
||||
[TestFixture]
|
||||
public class SmallBodiesTests
|
||||
{
|
||||
[Test]
|
||||
public void OpponentTurnStartBody_SerializesSpin_AndDefaultsResultCodeToOne()
|
||||
{
|
||||
var body = new OpponentTurnStartBody(Spin: 100);
|
||||
|
||||
var node = (JsonObject)JsonSerializer.SerializeToNode(body)!;
|
||||
|
||||
Assert.That(node["spin"]!.GetValue<int>(), Is.EqualTo(100));
|
||||
Assert.That(node["resultCode"]!.GetValue<int>(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResultCodeOnlyBody_SerializesJustResultCode()
|
||||
{
|
||||
var body = new ResultCodeOnlyBody();
|
||||
|
||||
var node = (JsonObject)JsonSerializer.SerializeToNode(body)!;
|
||||
|
||||
Assert.That(node.Count, Is.EqualTo(1));
|
||||
Assert.That(node["resultCode"]!.GetValue<int>(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BattleFinishBody_SerializesResultAndResultCode()
|
||||
{
|
||||
var body = new BattleFinishBody(Result: 1);
|
||||
|
||||
var node = (JsonObject)JsonSerializer.SerializeToNode(body)!;
|
||||
|
||||
Assert.That(node["result"]!.GetValue<int>(), Is.EqualTo(1));
|
||||
Assert.That(node["resultCode"]!.GetValue<int>(), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AlivePushBody_SerializesScsAndOcs_AndDoesNotIncludeResultCode()
|
||||
{
|
||||
var body = new AlivePushBody(Scs: "ONLINE", Ocs: "ONLINE");
|
||||
|
||||
var node = (JsonObject)JsonSerializer.SerializeToNode(body)!;
|
||||
|
||||
Assert.That(node["scs"]!.GetValue<string>(), Is.EqualTo("ONLINE"));
|
||||
Assert.That(node["ocs"]!.GetValue<string>(), Is.EqualTo("ONLINE"));
|
||||
Assert.That(node.ContainsKey("resultCode"), Is.False);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user