GuildEmblemListTask.Parse reads jsonData[i][emblem_id].ToLong(), confirming shape (b): array of objects with emblem_id. The existing List<GuildEmblemEntry> DTO was already correct. Add EmblemList_serializes_as_array_of_objects_with_emblem_id test to GuildWireShape to lock the shape in. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
63 lines
2.6 KiB
C#
63 lines
2.6 KiB
C#
using NUnit.Framework;
|
|
using System.Text.Json;
|
|
using SVSim.EmulatedEntrypoint.Models.Dtos.Guild;
|
|
|
|
namespace SVSim.UnitTests.Wire;
|
|
|
|
[TestFixture]
|
|
public class GuildWireShape
|
|
{
|
|
private static readonly JsonSerializerOptions Opts = new()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower,
|
|
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
|
|
};
|
|
|
|
[Test]
|
|
public void EmblemList_serializes_as_array_of_objects_with_emblem_id()
|
|
{
|
|
// GuildEmblemListTask.Parse() reads jsonData[i]["emblem_id"].ToLong()
|
|
// → wire must be an array of objects, each with an "emblem_id" string field.
|
|
var resp = new GuildEmblemListResponse
|
|
{
|
|
EmblemList = new() { new GuildEmblemEntry { EmblemId = 100_000_001L }, new GuildEmblemEntry { EmblemId = 100_000_002L } }
|
|
};
|
|
var json = JsonSerializer.Serialize(resp, Opts);
|
|
using var doc = JsonDocument.Parse(json);
|
|
var arr = doc.RootElement.GetProperty("guild_emblem_list");
|
|
|
|
Assert.That(arr.ValueKind, Is.EqualTo(JsonValueKind.Array));
|
|
Assert.That(arr.GetArrayLength(), Is.EqualTo(2));
|
|
|
|
var first = arr[0];
|
|
Assert.That(first.ValueKind, Is.EqualTo(JsonValueKind.Object));
|
|
Assert.That(first.GetProperty("emblem_id").ValueKind, Is.EqualTo(JsonValueKind.String));
|
|
Assert.That(first.GetProperty("emblem_id").GetString(), Is.EqualTo("100000001"));
|
|
}
|
|
|
|
[Test]
|
|
public void GuildInfo_non_joined_serializes_to_prod_shape()
|
|
{
|
|
var resp = new GuildInfoResponse
|
|
{
|
|
MaxMemberNum = 30,
|
|
MaxSubLeaderNum = 2,
|
|
GuildStatus = 0,
|
|
UsableStampList = Enumerable.Range(100001, 20).Select(i => i.ToString()).ToList(),
|
|
};
|
|
var json = JsonSerializer.Serialize(resp, Opts);
|
|
using var doc = JsonDocument.Parse(json);
|
|
var root = doc.RootElement;
|
|
|
|
Assert.That(root.GetProperty("max_member_num").GetString(), Is.EqualTo("30"));
|
|
Assert.That(root.GetProperty("max_sub_leader_num").GetString(), Is.EqualTo("2"));
|
|
Assert.That(root.GetProperty("guild_status").GetString(), Is.EqualTo("0"));
|
|
Assert.That(root.GetProperty("usable_stamp_list").EnumerateArray().Select(e => e.GetString()).First(), Is.EqualTo("100001"));
|
|
|
|
// The four nullable fields MUST NOT appear when null:
|
|
Assert.That(root.TryGetProperty("guild", out _), Is.False);
|
|
Assert.That(root.TryGetProperty("join_request_count", out _), Is.False);
|
|
Assert.That(root.TryGetProperty("invite_count", out _), Is.False);
|
|
}
|
|
}
|