mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 13:41:15 +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>
136 lines
4.5 KiB
C#
136 lines
4.5 KiB
C#
using FluentAssertions;
|
|
using Microsoft.Extensions.Options;
|
|
using SatelliteProvider.Common.Configs;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Common.Enums;
|
|
using SatelliteProvider.Common.Utils;
|
|
using SatelliteProvider.Services.RouteManagement;
|
|
using SatelliteProvider.Tests.Fixtures;
|
|
|
|
namespace SatelliteProvider.Tests;
|
|
|
|
public class RoutePointGraphBuilderTests
|
|
{
|
|
private static readonly ProcessingConfig DefaultProcessingConfig = new();
|
|
|
|
private static RoutePointGraphBuilder MakeBuilder() =>
|
|
new(Options.Create(new ProcessingConfig()));
|
|
|
|
private static List<RoutePoint> ToRoutePoints(IEnumerable<(double Lat, double Lon)> points) =>
|
|
points.Select(p => new RoutePoint { Latitude = p.Lat, Longitude = p.Lon }).ToList();
|
|
|
|
[Fact]
|
|
public void Build_TwoUserPoints_FirstIsStart_LastIsEnd_BetweenAreIntermediate()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route01Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
graph.Points.First().PointType.Should().Be(RoutePointType.Start);
|
|
graph.Points.Last().PointType.Should().Be(RoutePointType.End);
|
|
graph.Points.Skip(1).Take(graph.Points.Count - 2)
|
|
.Should().OnlyContain(p => p.PointType == RoutePointType.Intermediate);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ConsecutivePointsRespectMaxSpacing()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route01Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
for (int i = 1; i < graph.Points.Count; i++)
|
|
{
|
|
var prev = graph.Points[i - 1];
|
|
var cur = graph.Points[i];
|
|
var distance = GeoUtils.CalculateDistance(
|
|
new GeoPoint(prev.Latitude, prev.Longitude),
|
|
new GeoPoint(cur.Latitude, cur.Longitude));
|
|
distance.Should().BeLessThanOrEqualTo(DefaultProcessingConfig.MaxRoutePointSpacingMeters + 0.5,
|
|
$"point {i - 1}→{i} must be ≤{DefaultProcessingConfig.MaxRoutePointSpacingMeters}m");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_TenPointRoute_HasOneStartOneEndAndEightAction()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route04Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
graph.Points.Count(p => p.PointType == RoutePointType.Start).Should().Be(1);
|
|
graph.Points.Count(p => p.PointType == RoutePointType.End).Should().Be(1);
|
|
graph.Points.Count(p => p.PointType == RoutePointType.Action).Should().Be(8);
|
|
graph.Points.Should().Contain(p => p.PointType == RoutePointType.Intermediate);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_TotalDistanceEqualsSumOfHaversineSegments()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route01Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
var summed = 0.0;
|
|
for (int i = 1; i < graph.Points.Count; i++)
|
|
{
|
|
var prev = graph.Points[i - 1];
|
|
var cur = graph.Points[i];
|
|
summed += GeoUtils.CalculateDistance(
|
|
new GeoPoint(prev.Latitude, prev.Longitude),
|
|
new GeoPoint(cur.Latitude, cur.Longitude));
|
|
}
|
|
|
|
graph.TotalDistanceMeters.Should().BeApproximately(summed, 1.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_SequenceNumbersAreContiguousAndStartAtZero()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route04Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
graph.Points.Select(p => p.SequenceNumber)
|
|
.Should().Equal(Enumerable.Range(0, graph.Points.Count));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_FirstPointHasNullDistanceFromPrevious()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = ToRoutePoints(TestCoordinates.Route.Route01Points);
|
|
|
|
var graph = sut.Build(input);
|
|
|
|
graph.Points.First().DistanceFromPrevious.Should().BeNull();
|
|
graph.Points.Skip(1).Should().OnlyContain(p => p.DistanceFromPrevious.HasValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_FewerThanTwoPoints_Throws()
|
|
{
|
|
var sut = MakeBuilder();
|
|
var input = new List<RoutePoint> { new() { Latitude = 47.46, Longitude = 37.64 } };
|
|
|
|
Action act = () => sut.Build(input);
|
|
|
|
act.Should().Throw<ArgumentException>().WithMessage("*at least 2 points*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_NullInput_Throws()
|
|
{
|
|
var sut = MakeBuilder();
|
|
|
|
Action act = () => sut.Build(null!);
|
|
|
|
act.Should().Throw<ArgumentNullException>();
|
|
}
|
|
}
|