Skip to content

Commit 5e097ca

Browse files
committed
Fix 43 test failures: .NET 10 compat, remove dead MediaInfo tests
.NET 10 fixes: - WhereBuilder: Array.Contains no longer compiles as Enumerable.Contains in .NET 10 expression trees. Relaxed type check in SQLite and Postgres WhereBuilders. - TransmissionBase: TimeSpan.FromSeconds throws ArgumentOutOfRangeException in .NET 10 instead of OverflowException. Catch both. - HistoryRepository: Use List<int> instead of int[] to avoid array Contains expression tree issue. Removed dead tests: - Deleted all MediaInfoFormatter test fixtures (4 files) — the formatter returns empty for everything, no behavior to test. - Updated FileNameBuilder tests to verify MediaInfo tokens return empty. - Fixed sample detection test after DetectSample removal. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 91fda1a commit 5e097ca

File tree

10 files changed

+42
-187
lines changed

10 files changed

+42
-187
lines changed

src/NzbDrone.Core.Test/MediaFiles/DownloadedGamesImportServiceFixture.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void should_not_delete_folder_if_files_were_imported_and_video_files_rema
266266
}
267267

268268
[Test]
269-
public void should_delete_folder_if_files_were_imported_and_only_sample_files_remain()
269+
public void should_delete_folder_if_files_were_imported_and_no_video_files_remain()
270270
{
271271
GivenValidGame();
272272

@@ -281,7 +281,17 @@ public void should_delete_folder_if_files_were_imported_and_only_sample_files_re
281281

282282
Mocker.GetMock<IImportApprovedGame>()
283283
.Setup(s => s.Import(It.IsAny<List<ImportDecision>>(), true, null, ImportMode.Auto))
284-
.Returns(imported.Select(i => new ImportResult(i)).ToList());
284+
.Returns(imported.Select(i => new ImportResult(i)).ToList())
285+
.Callback(() =>
286+
{
287+
Mocker.GetMock<IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny<string>(), It.IsAny<bool>()))
288+
.Returns(System.Array.Empty<string>());
289+
});
290+
291+
Mocker.GetMock<IDiskProvider>()
292+
.Setup(s => s.GetFiles(It.IsAny<string>(), true))
293+
.Returns(System.Array.Empty<string>());
294+
285295
Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory));
286296

287297
Mocker.GetMock<IDiskProvider>()

src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatAudioCodecFixture.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoCodecFixture.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoDynamicRangeFixture.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/NzbDrone.Core.Test/MediaFiles/MediaInfo/MediaInfoFormatterTests/FormatVideoDynamicRangeTypeFixture.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/NzbDrone.Core.Test/OrganizerTests/FileNameBuilderTests/FileNameBuilderFixture.cs

Lines changed: 24 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void should_include_affixes_if_value_not_empty()
376376
}
377377

378378
[Test]
379-
public void should_format_mediainfo_properly()
379+
public void should_return_empty_for_mediainfo_full()
380380
{
381381
_namingConfig.StandardGameFormat = "{Game.Title}.{MEDIAINFO.FULL}";
382382

@@ -389,63 +389,11 @@ public void should_format_mediainfo_properly()
389389
};
390390

391391
Subject.BuildFileName(_game, _gameFile)
392-
.Should().Be("South.Park.H264.DTS[EN+ES].[EN+ES+IT]");
393-
}
394-
395-
[TestCase("nob", "NB")]
396-
[TestCase("swe", "SV")]
397-
[TestCase("zho", "ZH")]
398-
[TestCase("chi", "ZH")]
399-
[TestCase("fre", "FR")]
400-
[TestCase("rum", "RO")]
401-
[TestCase("per", "FA")]
402-
[TestCase("ger", "DE")]
403-
[TestCase("gsw", "DE")]
404-
[TestCase("cze", "CS")]
405-
[TestCase("ice", "IS")]
406-
[TestCase("dut", "NL")]
407-
[TestCase("nor", "NO")]
408-
[TestCase("khk", "MN")]
409-
[TestCase("mvf", "MN")]
410-
[TestCase("geo", "KA")]
411-
[TestCase("kat", "KA")]
412-
public void should_format_languagecodes_properly(string language, string code)
413-
{
414-
_namingConfig.StandardGameFormat = "{Game.Title}.{MEDIAINFO.FULL}";
415-
416-
_gameFile.MediaInfo = new MediaInfoModel()
417-
{
418-
VideoFormat = "h264",
419-
AudioFormat = "dts",
420-
AudioChannels = 6,
421-
AudioLanguages = new List<string> { "eng" },
422-
Subtitles = new List<string> { language },
423-
SchemaRevision = 3
424-
};
425-
426-
Subject.BuildFileName(_game, _gameFile)
427-
.Should().Be($"South.Park.H264.DTS.[{code}]");
428-
}
429-
430-
[Test]
431-
public void should_exclude_english_in_mediainfo_audio_language()
432-
{
433-
_namingConfig.StandardGameFormat = "{Game.Title}.{MEDIAINFO.FULL}";
434-
435-
_gameFile.MediaInfo = new MediaInfoModel()
436-
{
437-
VideoFormat = "h264",
438-
AudioFormat = "dts",
439-
AudioLanguages = new List<string> { "eng" },
440-
Subtitles = new List<string> { "eng", "spa", "ita" }
441-
};
442-
443-
Subject.BuildFileName(_game, _gameFile)
444-
.Should().Be("South.Park.H264.DTS.[EN+ES+IT]");
392+
.Should().Be("South.Park");
445393
}
446394

447395
[Test]
448-
public void should_format_mediainfo_3d_properly()
396+
public void should_return_empty_for_mediainfo_3d_and_simple()
449397
{
450398
_namingConfig.StandardGameFormat = "{Game.Title}.{MEDIAINFO.3D}.{MediaInfo.Simple}";
451399

@@ -459,7 +407,7 @@ public void should_format_mediainfo_3d_properly()
459407
};
460408

461409
Subject.BuildFileName(_game, _gameFile)
462-
.Should().Be("South.Park.3D.h264.DTS");
410+
.Should().Be("South.Park");
463411
}
464412

465413
[Test]
@@ -593,10 +541,10 @@ public void should_replace_all_tokens_for_different_cultures(string culture)
593541
_game.Year = 2020;
594542
GivenMediaInfoModel();
595543

596-
_namingConfig.StandardGameFormat = "{Game CleanTitle} ({Release Year}) [{Quality Title}] [igdb-{IgdbId}] [{MediaInfo AudioCodec}]";
544+
_namingConfig.StandardGameFormat = "{Game CleanTitle} ({Release Year}) [{Quality Title}] [igdb-{IgdbId}]";
597545

598546
Subject.BuildFileName(_game, _gameFile)
599-
.Should().Be("South Park (2020) [Uplay] [igdb-124578] [DTS]");
547+
.Should().Be("South Park (2020) [Uplay] [igdb-124578]");
600548
}
601549

602550
[Test]
@@ -646,67 +594,57 @@ public void should_use_existing_casing_for_release_group(string releaseGroup)
646594
.Should().Be(releaseGroup);
647595
}
648596

649-
[TestCase("eng", "")]
650-
[TestCase("eng/deu", "[EN+DE]")]
651-
public void should_format_audio_languages(string audioLanguages, string expected)
597+
[Test]
598+
public void should_return_empty_for_audio_languages()
652599
{
653600
_gameFile.ReleaseGroup = null;
654601

655-
GivenMediaInfoModel(audioLanguages: audioLanguages);
602+
GivenMediaInfoModel(audioLanguages: "eng/deu");
656603

657604
_namingConfig.StandardGameFormat = "{MediaInfo AudioLanguages}";
658605

659606
Subject.BuildFileName(_game, _gameFile)
660-
.Should().Be(expected);
607+
.Should().BeEmpty();
661608
}
662609

663-
[TestCase("eng", "[EN]")]
664-
[TestCase("eng/deu", "[EN+DE]")]
665-
public void should_format_audio_languages_all(string audioLanguages, string expected)
610+
[Test]
611+
public void should_return_empty_for_audio_languages_all()
666612
{
667613
_gameFile.ReleaseGroup = null;
668614

669-
GivenMediaInfoModel(audioLanguages: audioLanguages);
615+
GivenMediaInfoModel(audioLanguages: "eng/deu");
670616

671617
_namingConfig.StandardGameFormat = "{MediaInfo AudioLanguagesAll}";
672618

673619
Subject.BuildFileName(_game, _gameFile)
674-
.Should().Be(expected);
620+
.Should().BeEmpty();
675621
}
676622

677-
[TestCase("eng/deu", "", "[EN+DE]")]
678-
[TestCase("eng/nld/deu", "", "[EN+NL+DE]")]
679-
[TestCase("eng/deu", ":DE", "[DE]")]
680-
[TestCase("eng/nld/deu", ":EN+NL", "[EN+NL]")]
681-
[TestCase("eng/nld/deu", ":NL+EN", "[NL+EN]")]
682-
[TestCase("eng/nld/deu", ":-NL", "[EN+DE]")]
683-
[TestCase("eng/nld/deu", ":DE+", "[DE+-]")]
684-
[TestCase("eng/nld/deu", ":DE+NO.", "[DE].")]
685-
[TestCase("eng/nld/deu", ":-EN-", "[NL+DE]-")]
686-
public void should_format_subtitle_languages_all(string subtitleLanguages, string format, string expected)
623+
[Test]
624+
public void should_return_empty_for_subtitle_languages()
687625
{
688626
_gameFile.ReleaseGroup = null;
689627

690-
GivenMediaInfoModel(subtitles: subtitleLanguages);
628+
GivenMediaInfoModel(subtitles: "eng/deu");
691629

692-
_namingConfig.StandardGameFormat = "{MediaInfo SubtitleLanguages" + format + "}End";
630+
_namingConfig.StandardGameFormat = "{MediaInfo SubtitleLanguages}End";
693631

694632
Subject.BuildFileName(_game, _gameFile)
695-
.Should().Be(expected + "End");
633+
.Should().Be("End");
696634
}
697635

698-
[TestCase(HdrFormat.None, "South.Park")]
699-
[TestCase(HdrFormat.Hlg10, "South.Park.HDR")]
700-
[TestCase(HdrFormat.Hdr10, "South.Park.HDR")]
701-
public void should_include_hdr_for_mediainfo_videodynamicrange_with_valid_properties(HdrFormat hdrFormat, string expectedName)
636+
[TestCase(HdrFormat.None)]
637+
[TestCase(HdrFormat.Hlg10)]
638+
[TestCase(HdrFormat.Hdr10)]
639+
public void should_return_empty_for_mediainfo_videodynamicrange(HdrFormat hdrFormat)
702640
{
703641
_namingConfig.StandardGameFormat =
704642
"{Game.Title}.{MediaInfo VideoDynamicRange}";
705643

706644
GivenMediaInfoModel(hdrFormat: hdrFormat);
707645

708646
Subject.BuildFileName(_game, _gameFile)
709-
.Should().Be(expectedName);
647+
.Should().Be("South.Park");
710648
}
711649

712650
private void GivenMediaInfoModel(string videoCodec = "h264",

src/NzbDrone.Core/Datastore/WhereBuilderPostgres.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ private void ParseEnumerableContains(MethodCallExpression body)
297297
else
298298
{
299299
// Static method
300-
// Must be Enumerable.Contains(source, item)
301-
if (body.Method.DeclaringType != typeof(Enumerable) || body.Arguments.Count != 2)
300+
// Must be Enumerable.Contains(source, item) or Array static Contains
301+
if (body.Arguments.Count != 2)
302302
{
303303
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
304304
}

src/NzbDrone.Core/Datastore/WhereBuilderSqlite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ private void ParseEnumerableContains(MethodCallExpression body)
297297
else
298298
{
299299
// Static method
300-
// Must be Enumerable.Contains(source, item)
301-
if (body.Method.DeclaringType != typeof(Enumerable) || body.Arguments.Count != 2)
300+
// Must be Enumerable.Contains(source, item) or Array static Contains
301+
if (body.Arguments.Count != 2)
302302
{
303303
throw new NotSupportedException("Unexpected form of Enumerable.Contains");
304304
}

src/NzbDrone.Core/Download/Clients/Transmission/TransmissionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public override IEnumerable<DownloadClientItem> GetItems()
9494
{
9595
item.RemainingTime = TimeSpan.FromSeconds(torrent.Eta);
9696
}
97-
catch (OverflowException)
97+
catch (Exception ex) when (ex is OverflowException or ArgumentOutOfRangeException)
9898
{
9999
item.RemainingTime = TimeSpan.FromMilliseconds(torrent.Eta);
100100
}

src/NzbDrone.Core/History/HistoryRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public List<GameHistory> FindByDownloadId(string downloadId)
4848

4949
public List<GameHistory> FindDownloadHistory(int gameId, QualityModel quality)
5050
{
51-
var allowed = new[] { (int)GameHistoryEventType.Grabbed, (int)GameHistoryEventType.DownloadFailed, (int)GameHistoryEventType.DownloadFolderImported };
51+
var allowed = new List<int> { (int)GameHistoryEventType.Grabbed, (int)GameHistoryEventType.DownloadFailed, (int)GameHistoryEventType.DownloadFolderImported };
5252

5353
return Query(h => h.GameId == gameId &&
5454
h.Quality == quality &&

0 commit comments

Comments
 (0)