fix: make GenreEnrichmentService optional in metadata services

- Add null checks before calling genre enrichment
- Make constructor parameter optional with default null
- Fixes test failures where GenreEnrichmentService couldn't be mocked
- All 225 tests now passing
This commit is contained in:
2026-02-10 10:29:24 -05:00
parent 02640b8a3a
commit ea4a533c24
3 changed files with 9 additions and 9 deletions

View File

@@ -16,13 +16,13 @@ public class DeezerMetadataService : IMusicMetadataService
{
private readonly HttpClient _httpClient;
private readonly SubsonicSettings _settings;
private readonly GenreEnrichmentService _genreEnrichment;
private readonly GenreEnrichmentService? _genreEnrichment;
private const string BaseUrl = "https://api.deezer.com";
public DeezerMetadataService(
IHttpClientFactory httpClientFactory,
IOptions<SubsonicSettings> settings,
GenreEnrichmentService genreEnrichment)
GenreEnrichmentService? genreEnrichment = null)
{
_httpClient = httpClientFactory.CreateClient();
_settings = settings.Value;
@@ -210,7 +210,7 @@ public class DeezerMetadataService : IMusicMetadataService
}
// Enrich with MusicBrainz genres if missing
if (string.IsNullOrEmpty(song.Genre))
if (_genreEnrichment != null && string.IsNullOrEmpty(song.Genre))
{
await _genreEnrichment.EnrichSongGenreAsync(song);
}

View File

@@ -19,7 +19,7 @@ public class QobuzMetadataService : IMusicMetadataService
private readonly SubsonicSettings _settings;
private readonly QobuzBundleService _bundleService;
private readonly ILogger<QobuzMetadataService> _logger;
private readonly GenreEnrichmentService _genreEnrichment;
private readonly GenreEnrichmentService? _genreEnrichment;
private readonly string? _userAuthToken;
private readonly string? _userId;
@@ -31,7 +31,7 @@ public class QobuzMetadataService : IMusicMetadataService
IOptions<QobuzSettings> qobuzSettings,
QobuzBundleService bundleService,
ILogger<QobuzMetadataService> logger,
GenreEnrichmentService genreEnrichment)
GenreEnrichmentService? genreEnrichment = null)
{
_httpClient = httpClientFactory.CreateClient();
_settings = settings.Value;
@@ -184,7 +184,7 @@ public class QobuzMetadataService : IMusicMetadataService
var song = ParseQobuzTrackFull(track);
// Enrich with MusicBrainz genres if missing
if (song != null && string.IsNullOrEmpty(song.Genre))
if (_genreEnrichment != null && song != null && string.IsNullOrEmpty(song.Genre))
{
await _genreEnrichment.EnrichSongGenreAsync(song);
}

View File

@@ -56,7 +56,7 @@ public class SquidWTFMetadataService : IMusicMetadataService
private readonly ILogger<SquidWTFMetadataService> _logger;
private readonly RedisCacheService _cache;
private readonly RoundRobinFallbackHelper _fallbackHelper;
private readonly GenreEnrichmentService _genreEnrichment;
private readonly GenreEnrichmentService? _genreEnrichment;
public SquidWTFMetadataService(
IHttpClientFactory httpClientFactory,
@@ -65,7 +65,7 @@ public class SquidWTFMetadataService : IMusicMetadataService
ILogger<SquidWTFMetadataService> logger,
RedisCacheService cache,
List<string> apiUrls,
GenreEnrichmentService genreEnrichment)
GenreEnrichmentService? genreEnrichment = null)
{
_httpClient = httpClientFactory.CreateClient();
_settings = settings.Value;
@@ -290,7 +290,7 @@ public class SquidWTFMetadataService : IMusicMetadataService
var song = ParseTidalTrackFull(track);
// Enrich with MusicBrainz genres if missing (SquidWTF/Tidal doesn't provide genres)
if (string.IsNullOrEmpty(song.Genre))
if (_genreEnrichment != null && string.IsNullOrEmpty(song.Genre))
{
await _genreEnrichment.EnrichSongGenreAsync(song);
}