mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 22:21:15 +00:00
f7ad7aa5ab
Extract RouteValidator (aggregating validator), RoutePointGraphBuilder (point interpolation + sequence numbering), GeofenceGridCalculator (NW/SE region centers), and RouteResponseMapper (entity -> DTO; also used by GetRouteAsync, eliminating duplicate DTO assembly). CreateRouteAsync shrinks 184 -> 52 LOC of orchestration. RouteService.cs shrinks 295 -> 138 LOC overall. Validation aggregates all failures into a single ArgumentException (AC-2); single-violation messages preserved verbatim so existing RouteServiceTests pass unchanged. 28 new unit tests for the four helpers (112/112 unit tests, smoke green). Co-authored-by: Cursor <cursoragent@cursor.com>
185 lines
5.2 KiB
C#
185 lines
5.2 KiB
C#
using FluentAssertions;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Services.RouteManagement;
|
|
using SatelliteProvider.Tests.Fixtures;
|
|
|
|
namespace SatelliteProvider.Tests;
|
|
|
|
public class RouteValidatorTests
|
|
{
|
|
private static CreateRouteRequest BuildValidRequest()
|
|
{
|
|
return new CreateRouteRequest
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Name = "valid-route",
|
|
Description = "test",
|
|
RegionSizeMeters = 500,
|
|
ZoomLevel = 18,
|
|
Points = TestCoordinates.Route.Route01Points
|
|
.Select(p => new RoutePoint { Latitude = p.Lat, Longitude = p.Lon })
|
|
.ToList(),
|
|
};
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ValidRequest_DoesNotThrow_AZ365_AC2()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().NotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_FewerThanTwoPoints_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Points = new List<RoutePoint> { new() { Latitude = 47.46, Longitude = 37.64 } };
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>().WithMessage("*at least 2 points*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_RegionSizeOutOfRange_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.RegionSizeMeters = 50;
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>()
|
|
.WithMessage("*Region size must be between 100 and 10000*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_BlankName_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Name = " ";
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>().WithMessage("*Route name is required*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_GeofencePolygonZeroZero_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Geofences = new Geofences
|
|
{
|
|
Polygons = new List<GeofencePolygon>
|
|
{
|
|
new() { NorthWest = new GeoPoint(0, 0), SouthEast = new GeoPoint(0, 0) },
|
|
},
|
|
};
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>()
|
|
.WithMessage("*coordinates cannot be (0,0)*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_GeofenceInvertedLatitudes_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Geofences = new Geofences
|
|
{
|
|
Polygons = new List<GeofencePolygon>
|
|
{
|
|
new()
|
|
{
|
|
NorthWest = new GeoPoint(48.250, 37.370),
|
|
SouthEast = new GeoPoint(48.280, 37.395),
|
|
},
|
|
},
|
|
};
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>().WithMessage("*northWest latitude*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_NullPolygonCorner_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Geofences = new Geofences
|
|
{
|
|
Polygons = new List<GeofencePolygon>
|
|
{
|
|
new() { NorthWest = null, SouthEast = new GeoPoint(48.260, 37.390) },
|
|
},
|
|
};
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>()
|
|
.WithMessage("*polygon coordinates are required*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_OutOfRangeLatitude_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Geofences = new Geofences
|
|
{
|
|
Polygons = new List<GeofencePolygon>
|
|
{
|
|
new()
|
|
{
|
|
NorthWest = new GeoPoint(95, 37.370),
|
|
SouthEast = new GeoPoint(48.265, 37.395),
|
|
},
|
|
},
|
|
};
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>()
|
|
.WithMessage("*coordinates must be valid*");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_MultipleErrors_AggregatesIntoSingleException_AZ365_AC2()
|
|
{
|
|
var sut = new RouteValidator();
|
|
var request = BuildValidRequest();
|
|
request.Name = "";
|
|
request.RegionSizeMeters = 50;
|
|
request.Points = new List<RoutePoint>();
|
|
|
|
Action act = () => sut.Validate(request);
|
|
|
|
act.Should().Throw<ArgumentException>()
|
|
.Where(ex =>
|
|
ex.Message.Contains("at least 2 points")
|
|
&& ex.Message.Contains("Region size must be between 100 and 10000")
|
|
&& ex.Message.Contains("Route name is required"),
|
|
"AZ-365 AC-2: validator aggregates all failures into a single ArgumentException");
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_NullRequest_Throws()
|
|
{
|
|
var sut = new RouteValidator();
|
|
|
|
Action act = () => sut.Validate(null!);
|
|
|
|
act.Should().Throw<ArgumentNullException>();
|
|
}
|
|
}
|