Replace the shadow-property (Approach A) JSON mechanism with plain DTO records
so malformed files fail as GC-only and never leak live world Items.
Changes:
- Add Json/SpawnerDto.cs: abstract SpawnerDto + SpawnerDataDto / RegionSpawnerDto /
ProximitySpawnerDto, each [JsonDiscoverableType("<name>")] with ToSpawner()
- Add BaseSpawner.Dto.cs: internal ApplyDto(SpawnerDto) + private-protected Dto*
export helpers (DtoGuid, DtoMinDelay, etc.)
- Add Spawner.Dto.cs, RegionSpawner.Dto.cs, ProximitySpawner.Dto.cs: ToDto() overrides
- Add public abstract SpawnerDto ToDto() to BaseSpawner
- Retarget SpawnerJsonSerializer: discovery filter BaseSpawner→SpawnerDto; polymorphism
gate typeof(SpawnerDto); remove PruneToJsonProperties + AddOnDeserialized modifiers
- Delete BaseSpawner.Json.cs, Spawner.Json.cs, RegionSpawner.Json.cs,
ProximitySpawner.Json.cs (Approach A shadow-property partials)
- Remove [JsonDiscoverableType] + [JsonConstructor] from Spawner/RegionSpawner/ProximitySpawner
- Rewire ExportSpawnersCommand: build List<SpawnerDto> via spawner.ToDto()
- Rewire ImportSpawnersCommand: Deserialize<List<SpawnerDto>> then dto.ToSpawner();
map-null check now fires before ToSpawner(), so no orphan Items on bad map
- Delete 3 Approach-A round-trip tests; add SpawnerDtoRoundTripTests (4 cases)
- Update ExportImportFileTests + LegacyHomeRangeTests to use DTO path
- Add Import_MalformedFile_LeaksNoWorldItems to ImportCleanupTests
Build: dotnet build ModernUO.slnx → 0 errors, 0 warnings
Tests: dotnet test UOContent.Tests → 478/478 pass
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Server;
|
|
using Server.Engines.Spawners;
|
|
using Server.Json;
|
|
using Xunit;
|
|
|
|
namespace UOContent.Tests.Engines.Spawners.Json;
|
|
|
|
[Collection("Sequential UOContent Tests")]
|
|
public class ExportImportFileTests
|
|
{
|
|
[Fact]
|
|
public void Serialize_ThenDeserialize_File_PreservesSpawner()
|
|
{
|
|
Spawner original = null;
|
|
BaseSpawner rebuilt = null;
|
|
var path = Path.GetTempFileName();
|
|
try
|
|
{
|
|
original = new Spawner(3, TimeSpan.FromMinutes(4), TimeSpan.FromMinutes(8), 1,
|
|
new Rectangle3D(200, 200, 0, 9, 9, 0), "Tanner");
|
|
original.MoveToWorld(new Point3D(204, 204, 0), Map.Felucca);
|
|
|
|
JsonConfig.Serialize(path, new List<SpawnerDto> { original.ToDto() }, SpawnerJsonSerializer.Options);
|
|
|
|
var dtos = JsonConfig.Deserialize<List<SpawnerDto>>(path, SpawnerJsonSerializer.Options);
|
|
rebuilt = Assert.Single(dtos).ToSpawner();
|
|
var s = Assert.IsType<Spawner>(rebuilt);
|
|
Assert.Equal(3, s.Count);
|
|
Assert.Equal(1, s.Team);
|
|
Assert.Equal(new Rectangle3D(200, 200, 0, 9, 9, 0), s.SpawnBounds);
|
|
}
|
|
finally
|
|
{
|
|
rebuilt?.Delete();
|
|
original?.Delete();
|
|
File.Delete(path);
|
|
}
|
|
}
|
|
}
|