|
|
@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NSubstitute;
|
|
|
|
using NSubstitute;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using Trash.Config;
|
|
|
|
using Trash.Radarr;
|
|
|
|
using Trash.Radarr;
|
|
|
|
using Trash.Radarr.CustomFormat.Api;
|
|
|
|
using Trash.Radarr.CustomFormat.Api;
|
|
|
|
using Trash.Radarr.CustomFormat.Models;
|
|
|
|
using Trash.Radarr.CustomFormat.Models;
|
|
|
@ -22,13 +23,15 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
var config = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
|
|
|
|
|
|
|
var configProvider = Substitute.For<IConfigurationProvider>();
|
|
|
|
|
|
|
|
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
var deletedCfsInCache = new Collection<TrashIdMapping>();
|
|
|
|
var deletedCfsInCache = new Collection<TrashIdMapping>();
|
|
|
|
var profileScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>();
|
|
|
|
var profileScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>();
|
|
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, config, () => steps);
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.Received().RecordDeletions(Arg.Is(deletedCfsInCache), Arg.Any<List<JObject>>());
|
|
|
|
steps.JsonTransactionStep.Received().RecordDeletions(Arg.Is(deletedCfsInCache), Arg.Any<List<JObject>>());
|
|
|
@ -40,17 +43,43 @@ namespace Trash.Tests.Radarr.CustomFormat.Processors
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
var steps = Substitute.For<IPersistenceProcessorSteps>();
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
var cfApi = Substitute.For<ICustomFormatService>();
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
var qpApi = Substitute.For<IQualityProfileService>();
|
|
|
|
var config = new RadarrConfiguration(); // DeleteOldCustomFormats should default to false
|
|
|
|
|
|
|
|
|
|
|
|
var configProvider = Substitute.For<IConfigurationProvider>();
|
|
|
|
|
|
|
|
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = false};
|
|
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
|
|
|
|
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
|
|
|
|
var profileScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>();
|
|
|
|
var profileScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>();
|
|
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, config, () => steps);
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.DidNotReceive()
|
|
|
|
steps.JsonTransactionStep.DidNotReceive()
|
|
|
|
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
|
|
|
|
.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<IConfigurationProvider>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var guideCfs = Array.Empty<ProcessedCustomFormatData>();
|
|
|
|
|
|
|
|
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
|
|
|
|
|
|
|
|
var profileScores = new Dictionary<string, List<QualityProfileCustomFormatScoreEntry>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var processor = new PersistenceProcessor(cfApi, qpApi, configProvider, () => steps);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = false};
|
|
|
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configProvider.ActiveConfiguration = new RadarrConfiguration {DeleteOldCustomFormats = true};
|
|
|
|
|
|
|
|
processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
steps.JsonTransactionStep.Received(1)
|
|
|
|
|
|
|
|
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|