|
|
|
@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using TrashLib.Config;
|
|
|
|
|
using TrashLib.Radarr.Config;
|
|
|
|
|
using TrashLib.Radarr.CustomFormat.Api;
|
|
|
|
|
using TrashLib.Radarr.CustomFormat.Models;
|
|
|
|
@ -17,68 +16,62 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors
|
|
|
|
|
[Parallelizable(ParallelScope.All)]
|
|
|
|
|
public class PersistenceProcessorTest
|
|
|
|
|
{
|
|
|
|
|
private class Context
|
|
|
|
|
{
|
|
|
|
|
public Context()
|
|
|
|
|
{
|
|
|
|
|
Steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
|
GuideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
|
DeletedCfsInCache = new Collection<TrashIdMapping>();
|
|
|
|
|
ProfileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
|
|
|
|
|
|
|
|
|
|
Processor = new PersistenceProcessor(
|
|
|
|
|
_ => Substitute.For<ICustomFormatService>(),
|
|
|
|
|
_ => Substitute.For<IQualityProfileService>(),
|
|
|
|
|
() => Steps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PersistenceProcessor Processor { get; }
|
|
|
|
|
public Dictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; }
|
|
|
|
|
public Collection<TrashIdMapping> DeletedCfsInCache { get; }
|
|
|
|
|
public ProcessedCustomFormatData[] GuideCfs { get; }
|
|
|
|
|
public IPersistenceProcessorSteps Steps { get; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Custom_formats_are_deleted_if_deletion_option_is_enabled_in_config()
|
|
|
|
|
{
|
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
|
|
|
|
|
|
var configProvider = Substitute.For<IConfigProvider<RadarrConfiguration>>();
|
|
|
|
|
configProvider.Active.Returns(new RadarrConfiguration {DeleteOldCustomFormats = true});
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
|
var deletedCfsInCache = new Collection<TrashIdMapping>();
|
|
|
|
|
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, () => steps);
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
var config = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
var ctx = new Context();
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.Received().RecordDeletions(Arg.Is(deletedCfsInCache), Arg.Any<List<JObject>>());
|
|
|
|
|
ctx.Processor.PersistCustomFormats(config, ctx.GuideCfs, ctx.DeletedCfsInCache, ctx.ProfileScores);
|
|
|
|
|
ctx.Steps.JsonTransactionStep.Received()
|
|
|
|
|
.RecordDeletions(Arg.Is(ctx.DeletedCfsInCache), Arg.Any<List<JObject>>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Custom_formats_are_not_deleted_if_deletion_option_is_disabled_in_config()
|
|
|
|
|
{
|
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
|
var config = new RadarrConfiguration {DeleteOldCustomFormats = false};
|
|
|
|
|
var ctx = new Context();
|
|
|
|
|
|
|
|
|
|
var configProvider = Substitute.For<IConfigProvider<RadarrConfiguration>>();
|
|
|
|
|
configProvider.Active.Returns(new RadarrConfiguration {DeleteOldCustomFormats = false});
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
|
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
|
|
|
|
|
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, () => steps);
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.DidNotReceive()
|
|
|
|
|
ctx.Processor.PersistCustomFormats(config, ctx.GuideCfs, ctx.DeletedCfsInCache, ctx.ProfileScores);
|
|
|
|
|
ctx.Steps.JsonTransactionStep.DidNotReceive()
|
|
|
|
|
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Different_active_configuration_is_properly_used()
|
|
|
|
|
{
|
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
|
var configProvider = Substitute.For<IConfigProvider<RadarrConfiguration>>();
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
|
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
|
|
|
|
|
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, () => steps);
|
|
|
|
|
var ctx = new Context();
|
|
|
|
|
|
|
|
|
|
configProvider.Active = new RadarrConfiguration {DeleteOldCustomFormats = false};
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
var config = new RadarrConfiguration {DeleteOldCustomFormats = false};
|
|
|
|
|
ctx.Processor.PersistCustomFormats(config, ctx.GuideCfs, ctx.DeletedCfsInCache, ctx.ProfileScores);
|
|
|
|
|
|
|
|
|
|
configProvider.Active = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
config = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
ctx.Processor.PersistCustomFormats(config, ctx.GuideCfs, ctx.DeletedCfsInCache, ctx.ProfileScores);
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.Received(1)
|
|
|
|
|
ctx.Steps.JsonTransactionStep.Received(1)
|
|
|
|
|
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|