[AZ-286] [AZ-287] [AZ-288] Service-level unit tests (mocked deps)

Batch 2: 27 new tests, 31/31 total passing.

AZ-286 TileService (9 tests):
- BT-01 download stores tiles via repository
- BT-02 cache reuse passes existing tiles to downloader
- BT-02b stale-version cached tiles are NOT treated as still-valid
- BT-N02 GoogleMapsDownloaderV2 rejects zoom levels not in {15..19}
- GetTileAsync known/unknown id

AZ-287 RegionService (6 tests):
- AC-1 RequestRegionAsync inserts entity and queues request
- AC-2/AC-3 ProcessRegionAsync transitions queued→processing→completed
  and writes CSV + summary files
- AC-4 stitch path is set when stitchTiles=true
- ProcessRegionAsync handles RateLimitException by writing failed
  summary with the error message preserved
- GetRegionStatusAsync mapping
- Missing region id is logged and short-circuits without DB writes

AZ-288 RouteService (12 tests):
- AC-1 every consecutive pair is ≤200m apart on 2-point route
- AC-2 first/last user points keep their roles; middles are interpolated
- BT-10 10pt route → 1 start, 1 end, 8 action, plus intermediates
- BT-12 20pt route → 1 start, 1 end, 18 action
- AC-3 TotalDistanceMeters == Σ Haversine(point[i-1], point[i])
- BT-N03 < 2 points throws ArgumentException
- regionSize <100 / >10000 throws ArgumentException
- BT-N04 (0,0) corner throws
- BT-N05 inverted NW.lat <= SE.lat throws
- BT-11 valid geofence creates region requests + links them with
  isGeofence=true
- BT-07 GetRouteAsync returns route + points
- GetRouteAsync unknown id returns null

Code review: PASS_WITH_WARNINGS — 3 Low Spec-Gap findings:
  1. BT-N01 (invalid coords) deferred to AZ-289 integration tests
     (TileService doesn't validate coordinates — API-layer concern)
  2. Point-type label drift between blackbox-tests.md ("original")
     and code ("start"/"action"/"end")
  3. Region status drift: spec "pending" vs code "queued" — initial
     state on insert

Verification: docker dotnet test — 31/31 pass in 0.83s.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-10 05:02:00 +03:00
parent 3d112c0f47
commit dea0b8b4c0
9 changed files with 965 additions and 2 deletions
@@ -0,0 +1,30 @@
# Unit Tests: TileService
**Task**: AZ-286_tile_service_tests
**Name**: Unit tests: TileService (download, cache, dedup)
**Complexity**: 3 points
**Dependencies**: AZ-285
**Component**: Blackbox Tests
**Tracker**: AZ-286
**Epic**: AZ-284
## Scenarios
- BT-01: Tile download — mock ISatelliteDownloader.DownloadSingleTileAsync returns tile info; verify TileService stores it via ITileRepository.InsertAsync
- BT-02: Cache reuse — mock ITileRepository.GetTilesByRegionAsync returns existing tile; verify ISatelliteDownloader receives existing tiles to skip
- BT-N01: Invalid coordinates — verify appropriate error handling for out-of-range lat/lon
- BT-N02: Invalid zoom level — verify GoogleMapsDownloaderV2 rejects zoom levels outside allowed range
## Test Data
Coordinates from `input_data/test_coordinates.md`: lat=47.461747, lon=37.647063, zoom=18
## Expected Results
Per `input_data/expected_results/results_report.md`: tile with zoomLevel=18, tileSizePixels=256, imageType="jpg", non-empty filePath
## Acceptance Criteria
AC-1: All 4 scenarios have passing tests
AC-2: ISatelliteDownloader is mocked (no real Google Maps calls)
AC-3: Tests verify both happy path and error paths
@@ -0,0 +1,30 @@
# Unit Tests: RegionService
**Task**: AZ-287_region_service_tests
**Name**: Unit tests: RegionService (request, process, stitch)
**Complexity**: 3 points
**Dependencies**: AZ-285
**Component**: Blackbox Tests
**Tracker**: AZ-287
**Epic**: AZ-284
## Scenarios
- BT-03: Region 200m zoom 18 — verify request queuing and status="completed" after processing
- BT-04: Region 400m zoom 17 — same flow, different parameters
- BT-05: Region 500m zoom 18 with stitching — verify stitched image path is set
## Test Data
Coordinates: lat=47.461747, lon=37.647063. Sizes: 200m, 400m, 500m.
## Expected Results
Per results_report.md: status="completed", csvFilePath non-empty, summaryFilePath non-empty
## Acceptance Criteria
AC-1: RegionService.RequestRegionAsync creates entity and queues request
AC-2: RegionService.ProcessRegionAsync transitions status pending→processing→completed
AC-3: CSV and summary files are generated
AC-4: Stitch path is set when stitchTiles=true
@@ -0,0 +1,30 @@
# Unit Tests: RouteService
**Task**: AZ-288_route_service_tests
**Name**: Unit tests: RouteService (interpolation, geofence, distance)
**Complexity**: 3 points
**Dependencies**: AZ-285
**Component**: Blackbox Tests
**Tracker**: AZ-288
**Epic**: AZ-284
## Scenarios
- BT-06: Simple 2-point route — verify intermediate points at ≤200m spacing, point types correct
- BT-07: Route retrieval — verify GET returns same route with all points
- BT-10: Complex 10-point route — verify point distribution (1 first-original, 1 last-original, 8 intermediate)
- BT-11: Geofenced route — verify geofence region creation
- BT-12: Extended 20-point route — verify point distribution (1 first-original, 1 last-original, 18 intermediate)
- BT-N03: Route with <2 points — verify validation error
- BT-N04/N05: Invalid geofences — verify validation errors
## Test Data
Route points from test_coordinates.md (ROUTE-01 through ROUTE-06)
## Acceptance Criteria
AC-1: Point interpolation produces spacing ≤200m between all consecutive points
AC-2: Point type assignment is correct (original/intermediate)
AC-3: Total distance is calculated via Haversine
AC-4: Negative cases return appropriate errors