Files
satellite-provider/SatelliteProvider.Tests/GoogleMapsDownloaderTests.cs
T
Oleksandr Bezdieniezhnykh a7a645c7ab make structure
add tests
2025-10-26 09:15:06 +02:00

58 lines
1.9 KiB
C#

using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using SatelliteProvider.Common.Configs;
using SatelliteProvider.Common.DTO;
using SatelliteProvider.Services;
using Xunit;
namespace SatelliteProvider.Tests;
public class GoogleMapsDownloaderTests
{
[Fact]
public async Task IntegrationTest_DownloadRealTiles_ShouldDownloadBytes()
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var mapConfig = new MapConfig();
configuration.GetSection("MapConfig").Bind(mapConfig);
var services = new ServiceCollection();
services.AddHttpClient();
services.AddLogging(builder => builder.AddConsole());
var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService<ILogger<GoogleMapsDownloader>>();
var options = Options.Create(mapConfig);
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var downloader = new GoogleMapsDownloader(logger, options, httpClientFactory);
var centerPoint = new GeoPoint(37.7749, -122.4194);
var radius = 200.0;
var zoomLevel = 15;
await downloader.GetTiles(centerPoint, radius, zoomLevel);
var mapsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "maps");
Directory.Exists(mapsDirectory).Should().BeTrue();
var files = Directory.GetFiles(mapsDirectory, "*.jpg");
files.Should().NotBeEmpty();
var totalBytes = files.Sum(file => new FileInfo(file).Length);
totalBytes.Should().BeGreaterThan(0);
foreach (var file in files)
{
File.Delete(file);
}
}
}