ModernUO/Projects/UOContent.Tests/Tests/Engines/Spawners/Json/ImportCleanupTests.cs
Kamron Batman 9a25054809
test: remove trivial, duplicate and content-value tests (#2721)
## Summary
Many tests proved a specific change when it landed but don't need to run on every CI build forever. This removes **202 test methods and 9 files: 313 test cases, 2,247 → 1,934**. UOContent.Tests drops from about 14s to about 5s locally.

Removed:
- **Tautologies.** Asserting a constant, a constructor readback or a trivial getter, or testing BCL behavior.
- **Exact duplicates** of a surviving test on the same code path.
- **Obsolete regressions** whose failure can no longer be expressed.
- **Game-content values** shard owners customize (era drop rates, loot and skill tables, single-creature tuning). Each customization would otherwise force a test fix.

## How it was decided
1. Every test was classified, with a reason, by a per-shard sweep over all 287 test files.
2. Each proposed deletion was then checked by a second, adversarial reviewer against the surviving tests and the production code.
3. Anything that was the only coverage of a separate code path was **kept**, even where it looked like a duplicate. Examples: the unsigned `SpanReader`/`SpanWriter` methods, the at-location versus bounds enumerators, null-map enumerables, the security filters, archive-journal state transitions. About 130 proposed deletions were rejected this way.

Whole files removed:
- `FishingTests`, apart from 3 tests: the map-edge scan, serpent cleanup, and SOS chest consumption. The SOS test now stops at the first chest instead of measuring a catch rate. The multi-million-cast rate simulations are gone.
- `LordOaksTests` and `MeerEnragedTests` (single-creature tests).
- `AutoArchiveHelperTests`, `JsonDiscoverableTypeAttributeTests`, `DecimalSerializationTests` and `EnumConversionTests` (tautologies, or tests of their own local helpers).
- `NetworkStatsTests`.
- `MigratedDataLoadTests` (a subset of `AllSpawnFilesLoadTests`).
- `SpawnerFixtureCapture`: a capture tool, not a test, and its `version == 12` assert can no longer pass. The `.bin` fixtures it produced stay.

## Tests
- Server.Tests: 811 pass.
- UOContent.Tests: 1,123 pass.

A follow-up PR, stacked on this one, fixes how the remaining tests behave: shared state, CI-vacuous tests, harness duplication.
2026-10-18 20:08:19 -07:00

174 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using Server;
using Server.Engines.Spawners;
using Xunit;
namespace UOContent.Tests.Engines.Spawners.Json;
[Collection("Sequential UOContent Tests")]
public class ImportCleanupTests
{
private const string SpawnerGuid = "11111111-1111-1111-1111-111111111111";
[Fact]
public void Import_ValidFile_PlacesSpawner()
{
var dir = Path.Combine(Path.GetTempPath(), "muo-spawner-import-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "test.json");
File.WriteAllText(path, """
[
{
"$type": "Spawner",
"guid": "11111111-1111-1111-1111-111111111111",
"location": [305, 305, 0],
"map": "Felucca",
"count": 1,
"spawnBounds": { "x1": 300, "y1": 300, "x2": 310, "y2": 310 },
"entries": []
}
]
""");
BaseSpawner placedSpawner = null;
try
{
var all = new Dictionary<Guid, ISpawner>();
ImportSpawnersCommand.ImportFile(new FileInfo(path), all);
foreach (var s in Map.Felucca.GetItemsAt<BaseSpawner>(new Point3D(305, 305, 0)))
{
if (s.Guid == new Guid(SpawnerGuid))
{
placedSpawner = s;
break;
}
}
Assert.NotNull(placedSpawner);
Assert.True(all.ContainsKey(new Guid(SpawnerGuid)));
}
finally
{
placedSpawner?.Delete();
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
}
}
[Fact]
public void Import_NoMap_DeletesOrphanedSpawner()
{
// A spawner with no map entry deserialized by STJ will have map == null (or Map.Internal).
// Verify it does NOT end up on any live map.
var dir = Path.Combine(Path.GetTempPath(), "muo-spawner-import-nomap-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "test-nomap.json");
File.WriteAllText(path, """
[
{
"$type": "Spawner",
"guid": "22222222-2222-2222-2222-222222222222",
"location": [400, 400, 0],
"count": 1,
"spawnBounds": { "x1": 395, "y1": 395, "x2": 405, "y2": 405 },
"entries": []
}
]
""");
try
{
var all = new Dictionary<Guid, ISpawner>();
ImportSpawnersCommand.ImportFile(new FileInfo(path), all);
// The spawner must NOT be in allSpawners (rejected due to missing map).
Assert.DoesNotContain(new Guid("22222222-2222-2222-2222-222222222222"), all.Keys);
}
finally
{
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
}
}
private static int CountSpawnersNear(Point3D p)
{
var n = 0;
foreach (var _ in Map.Felucca.GetItemsAt<BaseSpawner>(p))
{
n++;
}
return n;
}
[Fact]
public void Import_DuplicateLocation_ReplacesExistingSpawner()
{
// Verifies that an existing spawner at the same location and type is removed and replaced.
var dir = Path.Combine(Path.GetTempPath(), "muo-spawner-import-dup-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "test-dup.json");
var newGuid = new Guid("33333333-3333-3333-3333-333333333333");
// Use a non-interpolated raw string literal; the guid is a known constant so hardcode it.
File.WriteAllText(path, """
[
{
"$type": "Spawner",
"guid": "33333333-3333-3333-3333-333333333333",
"location": [310, 310, 0],
"map": "Felucca",
"count": 1,
"spawnBounds": { "x1": 305, "y1": 305, "x2": 315, "y2": 315 },
"entries": []
}
]
""");
// Place a pre-existing spawner at the same location.
var existing = new Spawner(1, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(10));
existing.MoveToWorld(new Point3D(310, 310, 0), Map.Felucca);
BaseSpawner placedSpawner = null;
try
{
var all = new Dictionary<Guid, ISpawner> { [existing.Guid] = existing };
ImportSpawnersCommand.ImportFile(new FileInfo(path), all);
// existing should have been deleted and replaced.
Assert.True(existing.Deleted);
Assert.DoesNotContain(existing.Guid, all.Keys);
foreach (var s in Map.Felucca.GetItemsAt<BaseSpawner>(new Point3D(310, 310, 0)))
{
if (s.Guid == newGuid)
{
placedSpawner = s;
break;
}
}
Assert.NotNull(placedSpawner);
}
finally
{
if (!existing.Deleted)
{
existing.Delete();
}
placedSpawner?.Delete();
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
}
}
}
}