refactor: Throw error if using CFs in Sonarr v3

pull/124/head
Robert Dailey 2 years ago
parent e686b300b1
commit f6e6644af5

@ -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<CustomFormatConfig> {new()}
};
var act = () => updater.Process(false, config);
await act.Should().ThrowAsync<VersionException>().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<CustomFormatConfig> {new()}
};
var act = () => updater.Process(false, config);
await act.Should().NotThrowAsync();
}
}

@ -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.");
}
}

Loading…
Cancel
Save