mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-22 17:11:15 +00:00
[AZ-370] Refactor C17: status / point-type enums + AC RT2 update
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>
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using SatelliteProvider.Common.Configs;
|
||||
using SatelliteProvider.Common.DTO;
|
||||
using SatelliteProvider.Common.Enums;
|
||||
using SatelliteProvider.Common.Interfaces;
|
||||
using SatelliteProvider.Common.Utils;
|
||||
using SatelliteProvider.DataAccess.Models;
|
||||
@@ -59,8 +60,8 @@ public class RouteServiceTests
|
||||
};
|
||||
var existingPoints = new List<RoutePointEntity>
|
||||
{
|
||||
new() { Id = Guid.NewGuid(), RouteId = existingId, SequenceNumber = 0, Latitude = 47.46, Longitude = 37.64, PointType = "start", SegmentIndex = 0 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = existingId, SequenceNumber = 1, Latitude = 47.47, Longitude = 37.65, PointType = "end", SegmentIndex = 0 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = existingId, SequenceNumber = 0, Latitude = 47.46, Longitude = 37.64, PointType = RoutePointType.Start, SegmentIndex = 0 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = existingId, SequenceNumber = 1, Latitude = 47.47, Longitude = 37.65, PointType = RoutePointType.End, SegmentIndex = 0 },
|
||||
};
|
||||
var routeRepo = new Mock<IRouteRepository>(MockBehavior.Strict);
|
||||
routeRepo.Setup(r => r.GetByIdAsync(existingId)).ReturnsAsync(existingEntity);
|
||||
@@ -125,9 +126,9 @@ public class RouteServiceTests
|
||||
var result = await service.CreateRouteAsync(request);
|
||||
|
||||
// Assert
|
||||
result.Points.First().PointType.Should().Be("start", "first user-supplied point");
|
||||
result.Points.Last().PointType.Should().Be("end", "last user-supplied point");
|
||||
result.Points.Skip(1).Take(result.Points.Count - 2).Should().OnlyContain(p => p.PointType == "intermediate",
|
||||
result.Points.First().PointType.Should().Be(RoutePointType.Start, "first user-supplied point");
|
||||
result.Points.Last().PointType.Should().Be(RoutePointType.End, "last user-supplied point");
|
||||
result.Points.Skip(1).Take(result.Points.Count - 2).Should().OnlyContain(p => p.PointType == RoutePointType.Intermediate,
|
||||
"every middle point in a 2-point route is interpolated");
|
||||
}
|
||||
|
||||
@@ -142,10 +143,10 @@ public class RouteServiceTests
|
||||
var result = await service.CreateRouteAsync(request);
|
||||
|
||||
// Assert
|
||||
result.Points.Count(p => p.PointType == "start").Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == "end").Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == "action").Should().Be(8, "8 middle user-supplied waypoints in a 10-point route");
|
||||
result.Points.Should().Contain(p => p.PointType == "intermediate", "long route always interpolates");
|
||||
result.Points.Count(p => p.PointType == RoutePointType.Start).Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == RoutePointType.End).Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == RoutePointType.Action).Should().Be(8, "8 middle user-supplied waypoints in a 10-point route");
|
||||
result.Points.Should().Contain(p => p.PointType == RoutePointType.Intermediate, "long route always interpolates");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -159,9 +160,9 @@ public class RouteServiceTests
|
||||
var result = await service.CreateRouteAsync(request);
|
||||
|
||||
// Assert
|
||||
result.Points.Count(p => p.PointType == "start").Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == "end").Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == "action").Should().Be(18, "18 middle user-supplied waypoints in a 20-point route");
|
||||
result.Points.Count(p => p.PointType == RoutePointType.Start).Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == RoutePointType.End).Should().Be(1);
|
||||
result.Points.Count(p => p.PointType == RoutePointType.Action).Should().Be(18, "18 middle user-supplied waypoints in a 20-point route");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -274,7 +275,7 @@ public class RouteServiceTests
|
||||
|
||||
regionService
|
||||
.Setup(r => r.RequestRegionAsync(It.IsAny<Guid>(), It.IsAny<double>(), It.IsAny<double>(), It.IsAny<double>(), It.IsAny<int>(), false))
|
||||
.ReturnsAsync(new RegionStatus { Status = "queued" });
|
||||
.ReturnsAsync(new RegionStatusResponse { Status = RegionStatus.Queued });
|
||||
|
||||
var service = BuildService(routeRepo, regionService);
|
||||
|
||||
@@ -319,8 +320,8 @@ public class RouteServiceTests
|
||||
routeRepo.Setup(r => r.GetByIdAsync(id)).ReturnsAsync(routeEntity);
|
||||
routeRepo.Setup(r => r.GetRoutePointsAsync(id)).ReturnsAsync(new List<RoutePointEntity>
|
||||
{
|
||||
new() { Id = Guid.NewGuid(), RouteId = id, SequenceNumber = 0, Latitude = 1, Longitude = 2, PointType = "start", SegmentIndex = 0 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = id, SequenceNumber = 1, Latitude = 3, Longitude = 4, PointType = "end", SegmentIndex = 1 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = id, SequenceNumber = 0, Latitude = 1, Longitude = 2, PointType = RoutePointType.Start, SegmentIndex = 0 },
|
||||
new() { Id = Guid.NewGuid(), RouteId = id, SequenceNumber = 1, Latitude = 3, Longitude = 4, PointType = RoutePointType.End, SegmentIndex = 1 },
|
||||
});
|
||||
|
||||
var service = BuildService(routeRepo, new Mock<IRegionService>());
|
||||
@@ -332,8 +333,8 @@ public class RouteServiceTests
|
||||
result.Should().NotBeNull();
|
||||
result!.Id.Should().Be(id);
|
||||
result.Points.Should().HaveCount(2);
|
||||
result.Points[0].PointType.Should().Be("start");
|
||||
result.Points[1].PointType.Should().Be("end");
|
||||
result.Points[0].PointType.Should().Be(RoutePointType.Start);
|
||||
result.Points[1].PointType.Should().Be(RoutePointType.End);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user