mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 14:21:14 +00:00
23ab05766d
Replaces bare strings with two enums in Common/Enums/:
RegionStatus { Queued, Processing, Completed, Failed }
RoutePointType { Start, End, Action, Intermediate }
Adds a Dapper EnumStringTypeHandler<T> (DataAccess/TypeHandlers/)
that round-trips enums to/from lowercase strings, registered once
at startup via DapperEnumTypeHandlers.RegisterAll(). DataAccess now
references Common (project ref) so entities can carry the enum types.
Sites converted: RegionService (5), RouteProcessingService (3),
RoutePointGraphBuilder (4), entity Status/PointType columns. Log
message and summary file format preserved via .ToLowerInvariant().
API JSON contract preserved by adding JsonStringEnumConverter with
JsonNamingPolicy.CamelCase to the http JSON options — single-word
enum members serialize to the same lowercase strings as before.
DTO renamed: Common.DTO.RegionStatus -> RegionStatusResponse to
free the RegionStatus name for the new enum (forced by the task's
explicit enum name); the renamed DTO has no public-API impact at
the JSON wire level. Stale doc references updated.
AC RT2 in _docs/00_problem/acceptance_criteria.md now lists all 4
point types (start/end/action/intermediate).
Tests: 171 / 171 unit + 5 / 5 smoke green (was 141 + 5; +30 new tests
covering type handler round-trip, set/parse, unknown-value rejection,
idempotent registration, and the AC RT2 doc check).
Co-authored-by: Cursor <cursoragent@cursor.com>
141 lines
4.2 KiB
C#
141 lines
4.2 KiB
C#
using System.Data;
|
|
using FluentAssertions;
|
|
using Npgsql;
|
|
using SatelliteProvider.Common.Enums;
|
|
using SatelliteProvider.DataAccess.TypeHandlers;
|
|
|
|
namespace SatelliteProvider.Tests;
|
|
|
|
public class EnumStringTypeHandlerTests
|
|
{
|
|
[Theory]
|
|
[InlineData(RegionStatus.Queued, "queued")]
|
|
[InlineData(RegionStatus.Processing, "processing")]
|
|
[InlineData(RegionStatus.Completed, "completed")]
|
|
[InlineData(RegionStatus.Failed, "failed")]
|
|
public void SetValue_RegionStatus_WritesLowercaseString_AZ370_AC1(RegionStatus value, string expected)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
var param = new NpgsqlParameter();
|
|
|
|
handler.SetValue(param, value);
|
|
|
|
param.Value.Should().Be(expected);
|
|
param.DbType.Should().Be(DbType.String);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(RoutePointType.Start, "start")]
|
|
[InlineData(RoutePointType.End, "end")]
|
|
[InlineData(RoutePointType.Action, "action")]
|
|
[InlineData(RoutePointType.Intermediate, "intermediate")]
|
|
public void SetValue_RoutePointType_WritesLowercaseString_AZ370_AC1(RoutePointType value, string expected)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RoutePointType>();
|
|
var param = new NpgsqlParameter();
|
|
|
|
handler.SetValue(param, value);
|
|
|
|
param.Value.Should().Be(expected);
|
|
param.DbType.Should().Be(DbType.String);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("queued", RegionStatus.Queued)]
|
|
[InlineData("processing", RegionStatus.Processing)]
|
|
[InlineData("completed", RegionStatus.Completed)]
|
|
[InlineData("failed", RegionStatus.Failed)]
|
|
[InlineData("Completed", RegionStatus.Completed)]
|
|
public void Parse_RegionStatus_AcceptsAnyCase_AZ370_AC2(string raw, RegionStatus expected)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
|
|
var result = handler.Parse(raw);
|
|
|
|
result.Should().Be(expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("start", RoutePointType.Start)]
|
|
[InlineData("end", RoutePointType.End)]
|
|
[InlineData("action", RoutePointType.Action)]
|
|
[InlineData("intermediate", RoutePointType.Intermediate)]
|
|
public void Parse_RoutePointType_AcceptsLowercase_AZ370_AC2(string raw, RoutePointType expected)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RoutePointType>();
|
|
|
|
var result = handler.Parse(raw);
|
|
|
|
result.Should().Be(expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(RegionStatus.Queued)]
|
|
[InlineData(RegionStatus.Processing)]
|
|
[InlineData(RegionStatus.Completed)]
|
|
[InlineData(RegionStatus.Failed)]
|
|
public void RoundTrip_RegionStatus_PreservesValue_AZ370_AC2(RegionStatus value)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
var param = new NpgsqlParameter();
|
|
handler.SetValue(param, value);
|
|
|
|
var roundTripped = handler.Parse(param.Value!);
|
|
|
|
roundTripped.Should().Be(value);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(RoutePointType.Start)]
|
|
[InlineData(RoutePointType.End)]
|
|
[InlineData(RoutePointType.Action)]
|
|
[InlineData(RoutePointType.Intermediate)]
|
|
public void RoundTrip_RoutePointType_PreservesValue_AZ370_AC2(RoutePointType value)
|
|
{
|
|
var handler = new EnumStringTypeHandler<RoutePointType>();
|
|
var param = new NpgsqlParameter();
|
|
handler.SetValue(param, value);
|
|
|
|
var roundTripped = handler.Parse(param.Value!);
|
|
|
|
roundTripped.Should().Be(value);
|
|
}
|
|
|
|
[Fact]
|
|
public void Parse_NullValue_ThrowsDataException()
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
|
|
Action act = () => handler.Parse(null!);
|
|
|
|
act.Should().Throw<DataException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void Parse_DbNullValue_ThrowsDataException()
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
|
|
Action act = () => handler.Parse(DBNull.Value);
|
|
|
|
act.Should().Throw<DataException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void Parse_UnknownString_ThrowsDataException()
|
|
{
|
|
var handler = new EnumStringTypeHandler<RegionStatus>();
|
|
|
|
Action act = () => handler.Parse("not-a-status");
|
|
|
|
act.Should().Throw<DataException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterAll_IsIdempotent()
|
|
{
|
|
DapperEnumTypeHandlers.RegisterAll();
|
|
DapperEnumTypeHandlers.RegisterAll();
|
|
}
|
|
}
|