ModernUO/Projects/UOContent.Tests/Tests/Utilities/TryParseTests.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

67 lines
2.3 KiB
C#

using System;
using Xunit;
namespace Server.Tests.Utility;
public class TryParseTests
{
[Theory]
// Parsed directly into the target type (INumber<T>.TryParse), not via ulong + Convert.ChangeType.
[InlineData(typeof(int), "42", true, 42)]
[InlineData(typeof(int), "-5", true, -5)] // signed values parse directly now
[InlineData(typeof(int), "0xFF", true, 255)] // hex
[InlineData(typeof(int), "notanumber", false, null)]
[InlineData(typeof(byte), "255", true, (byte)255)]
[InlineData(typeof(byte), "256", false, null)] // out of the byte range
[InlineData(typeof(uint), "4294967295", true, 4294967295u)]
[InlineData(typeof(long), "-9000000000", true, -9000000000L)]
public void TestTryParseNumeric(Type type, string value, bool success, object expected)
{
var error = Server.Types.TryParse(type, value, out var constructed);
if (success)
{
Assert.Null(error);
Assert.Equal(expected, constructed);
}
else
{
Assert.NotNull(error);
}
}
}
// Interface-typed properties (BaseCreature.TargetLocation : IPoint2D) have no static Parse, so
// without these branches the parser fell through to Convert.ChangeType and reported the value as
// "not properly formatted".
public class InterfacePointParseTests
{
[Theory]
[InlineData(typeof(IPoint3D), "(1, 2, 3)", 1, 2, 3)]
[InlineData(typeof(IPoint2D), "(1, 2, 3)", 1, 2, 3)] // a 3-tuple is a valid IPoint2D
public void TuplesParseIntoPoint3D(Type type, string value, int x, int y, int z)
{
Assert.Null(Server.Types.TryParse(type, value, out var constructed));
Assert.Equal(new Point3D(x, y, z), constructed);
}
[Fact]
public void PairParsesIntoPoint2D()
{
Assert.Null(Server.Types.TryParse(typeof(IPoint2D), "(4, 5)", out var constructed));
Assert.Equal(new Point2D(4, 5), constructed);
}
[Fact]
public void PairIsNotAPoint3D()
{
Assert.NotNull(Server.Types.TryParse(typeof(IPoint3D), "(4, 5)", out _));
}
[Fact]
public void NullSentinelClearsAnInterfaceProperty()
{
Assert.Null(Server.Types.TryParse(typeof(IPoint2D), "(-null-)", out var constructed));
Assert.Null(constructed);
}
}