ModernUO/Projects/UOContent.Tests/Tests/Engines/Spawners/Json/MigratedDataLoadTests.cs
Kamron Batman 2f8a7afa57 chore(spawners): migrate spawn data to $type discriminator
- Rename "type" -> "$type" (first key, required for STJ polymorphism) in
  all 109 spawn JSON files (5,612 records).
- Convert "homeRange" + "location" -> "spawnBounds" object, dropping homeRange.
  Runtime keeps reading homeRange so un-migrated/external files still load.
- Add BoundsEquivalenceTests (hr=0/1/3/7) validating that the script's toBounds
  formula produces the same Rectangle3D as the runtime homeRange path.
- Add MigratedDataLoadTests loading a real migrated file as List<SpawnerDto>
  and round-tripping each DTO through ToSpawner().
- Add tools/spawner-json-migrate/migrate.mjs (offline Node script).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 16:17:35 -07:00

47 lines
1.4 KiB
C#

// Regression guard: verifies that a real migrated spawn file (post-uoml/felucca/Vendors.json)
// can be deserialized as List<SpawnerDto> and each DTO produces a valid spawner via ToSpawner().
// Exercises the $type discriminator path introduced by the data migration.
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Server;
using Server.Engines.Spawners;
using Xunit;
namespace UOContent.Tests.Engines.Spawners.Json;
[Collection("Sequential UOContent Tests")]
public class MigratedDataLoadTests
{
[Fact]
public void MigratedFile_LoadsWithDollarType()
{
var path = Path.Combine(Core.BaseDirectory, "Data", "Spawns", "post-uoml", "felucca", "Vendors.json");
if (!File.Exists(path))
{
return; // distribution data not present in this checkout
}
var dtos = JsonSerializer.Deserialize<List<SpawnerDto>>(File.ReadAllText(path), SpawnerJsonSerializer.Options);
Assert.NotEmpty(dtos);
var spawners = new List<BaseSpawner>(dtos.Count);
try
{
foreach (var dto in dtos)
{
spawners.Add(dto.ToSpawner());
}
Assert.Equal(dtos.Count, spawners.Count);
}
finally
{
foreach (var s in spawners)
{
s?.Delete();
}
}
}
}