mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-04-23 01:06:38 +00:00
route in progress, region stitching is disabled by default
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SatelliteProvider.IntegrationTests;
|
||||
|
||||
public static class RouteTests
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public static async Task RunSimpleRouteTest(HttpClient httpClient)
|
||||
{
|
||||
Console.WriteLine("Test: Create Simple Route with Two Points");
|
||||
Console.WriteLine("-----------------------------------------");
|
||||
|
||||
var routeId = Guid.NewGuid();
|
||||
var request = new CreateRouteRequest
|
||||
{
|
||||
Id = routeId,
|
||||
Name = "Simple Test Route",
|
||||
Description = "Test route with 2 points",
|
||||
RegionSizeMeters = 500.0,
|
||||
ZoomLevel = 18,
|
||||
Points = new List<RoutePointInput>
|
||||
{
|
||||
new() { Latitude = 48.276067180586544, Longitude = 37.38445758819581 },
|
||||
new() { Latitude = 48.27074009522731, Longitude = 37.374029159545906 }
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine($"Creating route with 2 points:");
|
||||
Console.WriteLine($" Start: ({request.Points[0].Latitude}, {request.Points[0].Longitude})");
|
||||
Console.WriteLine($" End: ({request.Points[1].Latitude}, {request.Points[1].Longitude})");
|
||||
Console.WriteLine($" Region Size: {request.RegionSizeMeters}m");
|
||||
Console.WriteLine($" Zoom Level: {request.ZoomLevel}");
|
||||
Console.WriteLine();
|
||||
|
||||
var response = await httpClient.PostAsJsonAsync("/api/satellite/route", request);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"API returned error status {response.StatusCode}: {errorContent}");
|
||||
}
|
||||
|
||||
var route = await response.Content.ReadFromJsonAsync<RouteResponseModel>(JsonOptions);
|
||||
|
||||
if (route == null)
|
||||
{
|
||||
throw new Exception("No route data returned from API");
|
||||
}
|
||||
|
||||
Console.WriteLine("Route Details:");
|
||||
Console.WriteLine($" ID: {route.Id}");
|
||||
Console.WriteLine($" Name: {route.Name}");
|
||||
Console.WriteLine($" Total Points: {route.TotalPoints}");
|
||||
Console.WriteLine($" Total Distance: {route.TotalDistanceMeters:F2}m");
|
||||
Console.WriteLine();
|
||||
|
||||
var startPoints = route.Points.Count(p => p.PointType == "start");
|
||||
var endPoints = route.Points.Count(p => p.PointType == "end");
|
||||
var intermediatePoints = route.Points.Count(p => p.PointType == "intermediate");
|
||||
|
||||
Console.WriteLine("Point Types:");
|
||||
Console.WriteLine($" Start points: {startPoints}");
|
||||
Console.WriteLine($" Intermediate points: {intermediatePoints}");
|
||||
Console.WriteLine($" End points: {endPoints}");
|
||||
Console.WriteLine();
|
||||
|
||||
if (startPoints != 1)
|
||||
{
|
||||
throw new Exception($"Expected 1 start point, got {startPoints}");
|
||||
}
|
||||
|
||||
if (endPoints != 1)
|
||||
{
|
||||
throw new Exception($"Expected 1 end point, got {endPoints}");
|
||||
}
|
||||
|
||||
Console.WriteLine("Point spacing validation:");
|
||||
for (int i = 1; i < route.Points.Count; i++)
|
||||
{
|
||||
var point = route.Points[i];
|
||||
if (point.DistanceFromPrevious.HasValue)
|
||||
{
|
||||
if (point.DistanceFromPrevious.Value > 200.0)
|
||||
{
|
||||
throw new Exception($"Point {i} is {point.DistanceFromPrevious.Value:F2}m from previous, exceeds 200m limit");
|
||||
}
|
||||
Console.WriteLine($" Point {i} ({point.PointType}): {point.DistanceFromPrevious.Value:F2}m from previous");
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Retrieving route by ID...");
|
||||
var getResponse = await httpClient.GetAsync($"/api/satellite/route/{routeId}");
|
||||
|
||||
if (!getResponse.IsSuccessStatusCode)
|
||||
{
|
||||
throw new Exception($"Failed to retrieve route: {getResponse.StatusCode}");
|
||||
}
|
||||
|
||||
var retrievedRoute = await getResponse.Content.ReadFromJsonAsync<RouteResponseModel>(JsonOptions);
|
||||
|
||||
if (retrievedRoute == null || retrievedRoute.Id != routeId)
|
||||
{
|
||||
throw new Exception("Retrieved route does not match created route");
|
||||
}
|
||||
|
||||
Console.WriteLine($"✓ Route retrieved successfully");
|
||||
Console.WriteLine($"✓ Retrieved {retrievedRoute.Points.Count} points");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("✓ Route created successfully");
|
||||
Console.WriteLine("✓ All point spacing validated (≤ 200m)");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Simple Route Test: PASSED");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user