diff --git a/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs b/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs index 568106de..302118db 100644 --- a/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs +++ b/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs @@ -9,6 +9,7 @@ using NSubstitute; using NUnit.Framework; using TestLibrary.AutoFixture; using TrashLib.ExceptionTypes; +using TrashLib.Services.Radarr.Config; using TrashLib.Services.Sonarr; using TrashLib.Services.Sonarr.Api; using TrashLib.Services.Sonarr.Api.Objects; @@ -152,4 +153,40 @@ public class SonarrCompatibilityTest await act.Should().NotThrowAsync(); } + + [Test, AutoMockData] + public async Task Failure_when_custom_formats_used_with_sonarr_v3( + [Frozen] ISonarrApi api, + [Frozen(Matching.ImplementedInterfaces)] SonarrCompatibility compatibility, + ReleaseProfileUpdater updater) + { + api.GetVersion().Returns(new Version(3, 9)); + + var config = new SonarrConfiguration + { + CustomFormats = new List {new()} + }; + + var act = () => updater.Process(false, config); + + await act.Should().ThrowAsync().WithMessage("Sonarr v3*custom format*use*v4*"); + } + + [Test, AutoMockData] + public async Task No_failure_when_custom_formats_used_with_sonarr_v4( + [Frozen] ISonarrApi api, + [Frozen(Matching.ImplementedInterfaces)] SonarrCompatibility compatibility, + ReleaseProfileUpdater updater) + { + api.GetVersion().Returns(new Version(4, 0)); + + var config = new SonarrConfiguration + { + CustomFormats = new List {new()} + }; + + var act = () => updater.Process(false, config); + + await act.Should().NotThrowAsync(); + } } diff --git a/src/TrashLib/Services/Sonarr/ReleaseProfile/ReleaseProfileUpdater.cs b/src/TrashLib/Services/Sonarr/ReleaseProfile/ReleaseProfileUpdater.cs index 4099974d..12299376 100644 --- a/src/TrashLib/Services/Sonarr/ReleaseProfile/ReleaseProfileUpdater.cs +++ b/src/TrashLib/Services/Sonarr/ReleaseProfile/ReleaseProfileUpdater.cs @@ -206,9 +206,13 @@ public class ReleaseProfileUpdater : IReleaseProfileUpdater $"required version of {_compatibility.MinimumVersion} to use this program"); } - if (capabilities.SupportsCustomFormats && config.ReleaseProfiles.Any()) + switch (capabilities.SupportsCustomFormats) { - throw new VersionException("Sonarr v4 does not support Release Profiles. Please use Sonarr v3 instead."); + case true when config.ReleaseProfiles.Any(): + throw new VersionException("Sonarr v4 does not support Release Profiles. Please use Sonarr v3 instead."); + + case false when config.CustomFormats.Any(): + throw new VersionException("Sonarr v3 does not support Custom Formats. Please use Sonarr v4 instead."); } }