mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 06:51:13 +00:00
687d6bdd5b
Add per-source tile rows to support multi-provider imagery (Google Maps + future UAV). Migration 013 (transactional) introduces source/captured_at columns, backfills existing rows to (source='google_maps', captured_at=created_at), and replaces the 4-column unique index with a 5-column index that includes source. TileRepository: - ColumnList includes source + captured_at - GetByTileCoordinatesAsync returns most-recent row across sources (ORDER BY captured_at DESC, updated_at DESC, id DESC) - GetTilesByRegionAsync uses DISTINCT ON to pick the most-recent tile per cell, restoring caller-facing row order - Insert/Update upsert on the new 5-column conflict key TileSource enum lives in Common.Enums. Snake_case wire format (google_maps, uav) is enforced by a focused TileSourceTypeHandler because the generic ToLowerInvariant pattern would emit "googlemaps", violating contract v1.0.0. TileService stamps Source=GoogleMaps + CapturedAt=UtcNow on every new tile. Tile-storage contract is now frozen at v1.0.0. AC coverage 7/7. New unit + integration tests cover all ACs; existing 200 unit + 5 smoke tests preserved. Co-authored-by: Cursor <cursoragent@cursor.com>
244 lines
7.1 KiB
C#
244 lines
7.1 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();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(TileSource.GoogleMaps, "google_maps")]
|
|
[InlineData(TileSource.Uav, "uav")]
|
|
public void TileSourceHandler_SetValue_WritesContractWireValue_AZ484(TileSource value, string expected)
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
var param = new NpgsqlParameter();
|
|
|
|
// Act
|
|
handler.SetValue(param, value);
|
|
|
|
// Assert
|
|
param.Value.Should().Be(expected);
|
|
param.DbType.Should().Be(DbType.String);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("google_maps", TileSource.GoogleMaps)]
|
|
[InlineData("GOOGLE_MAPS", TileSource.GoogleMaps)]
|
|
[InlineData("uav", TileSource.Uav)]
|
|
[InlineData("UAV", TileSource.Uav)]
|
|
public void TileSourceHandler_Parse_AcceptsContractWireValue_AZ484(string raw, TileSource expected)
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
|
|
// Act
|
|
var result = handler.Parse(raw);
|
|
|
|
// Assert
|
|
result.Should().Be(expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(TileSource.GoogleMaps)]
|
|
[InlineData(TileSource.Uav)]
|
|
public void TileSourceHandler_RoundTrip_PreservesValue_AZ484(TileSource value)
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
var param = new NpgsqlParameter();
|
|
handler.SetValue(param, value);
|
|
|
|
// Act
|
|
var roundTripped = handler.Parse(param.Value!);
|
|
|
|
// Assert
|
|
roundTripped.Should().Be(value);
|
|
}
|
|
|
|
[Fact]
|
|
public void TileSourceHandler_Parse_UnknownString_ThrowsDataException_AZ484()
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
|
|
// Act
|
|
Action act = () => handler.Parse("satar");
|
|
|
|
// Assert — Inv-1: unknown sources surface, not silently coerce (coderule.mdc: never suppress errors).
|
|
act.Should().Throw<DataException>().WithMessage("*satar*");
|
|
}
|
|
|
|
[Fact]
|
|
public void TileSourceHandler_Parse_NullValue_ThrowsDataException_AZ484()
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
|
|
// Act
|
|
Action act = () => handler.Parse(null!);
|
|
|
|
// Assert
|
|
act.Should().Throw<DataException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void TileSourceHandler_Parse_DbNullValue_ThrowsDataException_AZ484()
|
|
{
|
|
// Arrange
|
|
var handler = new TileSourceTypeHandler();
|
|
|
|
// Act
|
|
Action act = () => handler.Parse(DBNull.Value);
|
|
|
|
// Assert
|
|
act.Should().Throw<DataException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void RegisterAll_RegistersTileSourceHandler_AZ484()
|
|
{
|
|
// Arrange / Act
|
|
DapperEnumTypeHandlers.RegisterAll();
|
|
|
|
// Assert — registration is idempotent and the handler emits the contract wire value.
|
|
var probe = new TileSourceTypeHandler();
|
|
var param = new NpgsqlParameter();
|
|
probe.SetValue(param, TileSource.GoogleMaps);
|
|
param.Value.Should().Be("google_maps");
|
|
}
|
|
}
|