test(spawners): lock legacy homeRange->spawnBounds JSON read
Add regression tests for homeRange property conversion on deserialize. Tests verify that legacy JSON with homeRange field (no spawnBounds) deserializes to centered Rectangle3D bounds as implemented in BaseSpawner.OnAfterJsonDeserialize. - homeRange: 3 -> Rectangle3D(97, 197, -128, 7, 7, 256) - homeRange: 0 -> Rectangle3D(100, 200, 5, 1, 1, 0) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c41d6a89d3
commit
206d938395
1 changed files with 62 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Server;
|
||||
using Server.Engines.Spawners;
|
||||
using Xunit;
|
||||
|
||||
namespace UOContent.Tests.Engines.Spawners.Json;
|
||||
|
||||
[Collection("Sequential UOContent Tests")]
|
||||
public class LegacyHomeRangeTests
|
||||
{
|
||||
[Fact]
|
||||
public void HomeRange_NoSpawnBounds_ProducesCenteredBounds()
|
||||
{
|
||||
const string legacy = """
|
||||
[
|
||||
{
|
||||
"$type": "Spawner",
|
||||
"guid": "3df0543a-373c-4673-a98b-8191686f4ab3",
|
||||
"location": [100, 200, 5],
|
||||
"map": "Felucca",
|
||||
"count": 1,
|
||||
"homeRange": 3,
|
||||
"entries": [ { "name": "Fisherman", "maxCount": 1, "probability": 100 } ]
|
||||
}
|
||||
]
|
||||
""";
|
||||
|
||||
var rt = JsonSerializer.Deserialize<List<BaseSpawner>>(legacy, SpawnerJsonSerializer.Options);
|
||||
var s = Assert.IsType<Spawner>(Assert.Single(rt));
|
||||
|
||||
// homeRange 3 -> Rectangle3D(100-3, 200-3, -128, 7, 7, 256)
|
||||
Assert.Equal(new Rectangle3D(97, 197, -128, 7, 7, 256), s.SpawnBounds);
|
||||
|
||||
s.Delete();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HomeRangeZero_ProducesSingleTileBounds()
|
||||
{
|
||||
const string legacy = """
|
||||
[
|
||||
{
|
||||
"$type": "Spawner",
|
||||
"location": [100, 200, 5],
|
||||
"map": "Felucca",
|
||||
"count": 1,
|
||||
"homeRange": 0,
|
||||
"entries": [ { "name": "Fisherman", "maxCount": 1, "probability": 100 } ]
|
||||
}
|
||||
]
|
||||
""";
|
||||
|
||||
var rt = JsonSerializer.Deserialize<List<BaseSpawner>>(legacy, SpawnerJsonSerializer.Options);
|
||||
var s = Assert.IsType<Spawner>(Assert.Single(rt));
|
||||
|
||||
// homeRange 0 -> Rectangle3D(100, 200, 5, 1, 1, 0)
|
||||
Assert.Equal(new Rectangle3D(100, 200, 5, 1, 1, 0), s.SpawnBounds);
|
||||
|
||||
s.Delete();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue